Crazy about Arduino - Level 3 - Building a Complete Web-based IoT Data-logger | Idan Gabrieli | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Crazy about Arduino - Level 3 - Building a Complete Web-based IoT Data-logger

teacher avatar Idan Gabrieli, Pre-sales Manager | Cloud and AI Expert

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

50 Lessons (4h 1m)
    • 1. Course Introduction

    • 2. Before we start...

    • 3. Step 1 - Setting the Sensors

    • 4. What is a Sensor ?

    • 5. Sensors are Everywhere

    • 6. Measuring Temperature and Humidity

    • 7. Ultrasonic Sensor

    • 8. Wiring All Sensors to the Arduino

    • 9. Hardware Setup - Sensors

    • 10. Project Demo

    • 11. Code Review

    • 12. Step 2 - Ethernet Shield

    • 13. IP Address

    • 14. MAC Address

    • 15. Client Server Communication

    • 16. TCP and UDP Ports

    • 17. Network Socket

    • 18. TCP Session

    • 19. HTTP and HTML

    • 20. Ethernet Shield

    • 21. Ethernet Library

    • 22. Hardware Setup - Ethernet Shield W5100

    • 23. Project Demo

    • 24. Code Review

    • 25. Step 3 - WampServer

    • 26. Apache, PHP and MySQL

    • 27. Download and Install

    • 28. Getting started with Wamp

    • 29. Basic Server Configuration

    • 30. Step 4 - MySQL Database

    • 31. What is a Database ?

    • 32. MySQL Tools

    • 33. Using phpMyAdmin Console fix

    • 34. SQL Statements

    • 35. Testing our Project Database

    • 36. Step 5 - PHP - Running Scripts at the Server

    • 37. What is PHP ?

    • 38. Basic PHP Syntax

    • 39. PHP Extension to MySQL

    • 40. mysqli - Establish Database Connection

    • 41. Insert New Data

    • 42. Insert Data PHP Scripts Testing

    • 43. Query Data

    • 44. Query Data PHP Scripts Testing

    • 45. MySQL Error Handling

    • 46. MySQL Error Handling Testing

    • 47. Step 6 - Final Project - Web-based Datalogger

    • 48. Connecting the Arduino to the Web Server

    • 49. Final Project Checklist and Demo

    • 50. Course Summary

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


The Crazy about Arduino Training Program - LEVEL 3

  • Do you like building “things” by yourself?
  • Are you looking for ways to easily combine software code and some hardware components?
  • Did you ever wonder how electronic devices are really working?
  • Do you have some creative ideas and you just looking for ways to easily prototype them?

If the answer is “YES” for some of the questions above then you just landed in the right place!. Arduino is an amazing development and prototyping platform with endless possibilities for Do-It-Yourself Makers looking for ways to express their creative mind and technical capabilities. 

Are you Ready to start being “Crazy” about Arduino....?  ;-)

Meet Your Teacher

Teacher Profile Image

Idan Gabrieli

Pre-sales Manager | Cloud and AI Expert


Class Ratings

Expectations Met?
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Course Introduction: hi and welcome to the crazy about are doing a training program. Level three. Now let's see. What are we going to learn? We will start by connecting albarino to several sensors for measuring temperature, humidity, light change in distance while using the DHD 11 Ultrasonic and LD R Sensor. Next will be to connect. They're doing, you know, to the Internet, using the Internet extension chilled, getting dynamic I p. And creating HDP connection to a remote server. So basically, we will transform the albarino into an Internet off things device. Then we will end to install and set up a will own Web and database server using Apache and my sequel and creating the PHP several side script. And the last step will be to connect. They are going, oh, I ot device toe the Web server using a Web A p I, and stole ongoing sensor data. In addition to the fun part off creating such project by yourself, it may also three get all kind off. Innovative ideas in your mind is always We're going to combine a little bit theory, but each section and more emphasize on the practical side with the step by step short learning Cycle, dividing a complex project to several steps. We're going to use several free software tools to help us design circuit upload software to the Torino and set up a personal weapon that obey server on a standard PC. Each section includes a short quiz to test your knowledge. Still, my best advice is to build the project by yourself. It is really fun process. And, of course, don't forget that you can't share your thought and ongoing question. My name is he dangled. Really? A. Like many teachers have a full time regular job. I'm actually walking in the software industry for many years with a strong linkage to the business side. I have a comprehensive knowledge in electron ICS networking I t Web technology and all kinds of other stuff that are useful for creating this overhauled training program. Generation I like to teach if you already started your journey with Level one and level two , then you already joined the makers evolution, sharing your passion to create new things by yourself, combining all kind off technology while having some fun. This level, Level three is really a jump step in the crazy about or doing a training program. So at the end, it is really up to you. Are you ready to start being crazy about? 2. Before we start...: Before we start, I have some few simple commendation. It start by adjusting the video place to fool edgy. If it's not your default setting this course supporting full HD, it tried to follow the suggests section order one by one is the project we're building is really based on this order. Now, in some chapter, there are some files that you should download, including albarino programs. Circuit design PHP script into one. I really encourage you to build the project by yourself. The cost of hardware component were planning to use is very reasonable and affordable, and we can easily get it over the Internet. Probably you have most off them. If you have done level one level two and the last thing, please use the UTV site to add question or maybe start some discussion with other student before starting building the project. Let's review the needed the software tools and the hardware items first on the software side there, the application that are needed. The first software is, of course, they're doing. I d being used to create code and upload that without we know we use that a lot until now, in level one and level two. If you don't have it yet, you can download that from the official Albarino site. It is completely free. Second program is called Free Ting. It is used to easily design schematic the sick it. It is also a free software that you can download form. The fighting official site is mentioned. In some chapters. You will be able to find sketch and secret design files a dedicated for the project so you can review us question change. And maybe you use that in your future. Their project and the last software that is needed is called Wamp Server. You don't need to download a softer right now because we have a dedicated section related toe that software installation and configuration. Now, what about Howard? Will. I'm always aiming that the hardware cost will be minimal and we can off course. We use the component from previous level Level one, Level two. The following image shows the simple endpoint I ot device. We are going toe build using out. We know, you know, basically were planning to use three different sense. All it three simple leads and exist oh, the Internet extension shield for Do we know, you know and, of course, some wires to connect the component to the do you know, using the bread board. Now let's see the following Excel file that summarize all needed competent. The following list summarized they needed the component. You can always also download this Excel file from this chapter. But basically most of the items that you see over real items that we already so in level one in a level to like they're doing no starter kit that we know, you know a board is some led simple lay leads fixed Resistol A that we're using together with the leads ultrasonic stencil that we saw in level two A moving below. This is a new high temps that state on a chilled for Do we know you have some link right over there. You can see also the price off that model and another needed component is DHT 11 for temperature and the humidity sense. So, again, this is you can see the link in the price off that component LDL that we also used in a level to some wires and of course, the bread board itself. Okay, that's all. I think we are ready to start building our project 3. Step 1 - Setting the Sensors: Step one. Setting the sensor. We are building it that a local system that is similar to an Internet of things solution and one off the main component in this set up is off course. The collection endpoint or the thing? A. That should measure something, collect and transmit. The relevant data over the Internet were Web seven, and then this Web server will be accessed using a Web browser to visual the data being collected by the end point device or devices. So this is the first step in our journey where we would like to connect few sensor toe. The Reno by setting the needed heart, was set up. Do some testing with software program and start measure something. But before jumping to the practical side in the section, let's quickly review the concept off sensor. 4. What is a Sensor ?: looking on the basic, simple definition. The sensor is an object that is used to detect events or change in its environment and then provide a corresponding output. Okay, this is like the wiki definition. Basically, it is the first component in the chain when we would like Toa Bridge between the Hill physical environment and the digital virtualized Internet or some computing system so it is used toe, acquire some physical pala metal and convert it into a signal for additional processing. In one side, we have some measured input getting into the sense, so that has the capability to untranslated toe an output signal. The output can be on a low voltage level, specific resistance or maybe a digital output and more. Today, with the constant doping coast of hardware and software, we have sense. So just everywhere they're embedded in our smartphone cause moving more home appliance airplanes, those industrial planets in countless other applications send so a critical component in many system today 5. Sensors are Everywhere: now what kind of things can be detected by sensible? Well, there are many types off sensor that can detect different physical properties. Okay, like voltage or current level electrical magnetic field temperature, acoustic wave, some mechanical position, accelerations, especial gust, concentration and much more if you will search ive A just for a sense of related to what we know, you will be able to find many types off Senso. Usually it's coming with breakout boat, meaning small models that can be used for endless application. We said the Internet and found some nice, sensible to measure distance. It is cheap, easy to while, and probably not so hard to control a using that we know stay if we will examine a sense of much more carefully there, some common set off for pity's that better describe that specific sense. So let's see some of them. For example, resolution is the ability off a sense of to see small difference in having okay in our case , Can we measure resolution off one meter, one centimeters, one millimeters a range is the maximum and minimum value range over which is sent, so we provide us the aiding eso in our my case again. What is the age of distance? The sensor can still measure Stability is related to the degree which is Senso. A characteristic remain constant over time. Okay, due to all kind of things like a component aging, decreasing sensitivity off specific component and etcetera the supposed time, How long it takes between an object passing the Senso until the sense of actually detected and send signals in real time application. This is a critical parliament temperature range. Well, all sense So okay, are walking in specific temperature range. That must be a line with environment which we would like toa place the sensor radiant sighs What is the size off the sensor? That's critical element when a sense social be implemented in some larger system accuracy. How will the sensor measure the environment? In an absolute sense, it is expected that there will be some ever winch. So we need to do to understand their wage in our sense of power consumption. How much energy descent so is required toe be operate setting time The time for the sensor to reach a stable output once it is thing own. Some economic factors. Okay, like coast. Okay, Lifetime and availability in the market. Okay, and much more it. So for sure, there are many factors to be considered while choosing a sensor. And of course, we need to take it into account in any project we are planning to build. I'm sure that you already know that many types off Senso that can be connected to our doing aboard and start measures some physical properties, probably. You got some off them in Samel. Do we know a kit that you bought over the Internet? Basically sensible can be on a local digital. It can be simple sense, so that require additional component. Or it can be a model or a breakout boda. Tell Adi integrate some sense or another needed component around it. In our that a local project, I choose very affordable. Sensor it to measure temperature, humidity, life change and this does and they will be used to provide us almost real time information . Using the website will develop in your future project. You can choose other kind off sensor based on different application and adopt a little bit the program we are going to develop. Now let's review the sense. So we are planning to use some of them. You already so in previous levels, under the crazy about or do we know training program, meaning level one and level two? 6. Measuring Temperature and Humidity: the first sensible a we would like to use is called DHT 11 old HD 2 to 4 measuring temperature and humidity. Now, such Senso appears in many application, like building engines or kind of former clients, computers and many others that require it to monitor such properties, temperatures and humidity. Now the DHD 22 is a little bit more accurate and better over larger range, but we will use the HD 11. That is good enough in our case. Now, please know that we're using the DHD a breakout boat. Okay, this what you see here on the right side for making our life easier Now, some off the main A properties off this sense ALS are, for example, it can measure between 22 80 degree humidity. Okay, reading with 5% accuracy. OK, remember, this is like general properties off a sensor A. In addition, if it's related to temperature so it can only read temperature between zero toe 50 degree Intel's use and the eating itself has some l, for example, I mean some accuracy Evo between minus and plus to a degree. In addition, the sampling rate that we are reading information from this sense or should not be more than one hurts meaning once every second. Okay, of course, in our in our case in our project were planning to read the sense of every few minutes. So we don't have any problem in that case. Ah, the size of a pretty small as you see And they some a hole that we can easily use that for doing installation. And the last thing is that I'm going to use a library if we're making our life more easier when we are operating the sensible 7. Ultrasonic Sensor: measuring distance. So the last sensor we will use is called ultrasonic sensor again. Will it be used that in level two, the ultrasonic sensor is using sonar waves to detect distance to an object. The range descent so can detect is between two sentimental toe around four metres, and the resolution will be around 0.3. Sentimental now most probably or so that because this sense of breakout board is very popular in many albarino project, due to the fact that it's low cost and very easy to use. And we also are going to use that in our project now like the LDS and so we don't need any special library toe operate this throat or so inaccessible. It is quite easy when you understand how the sensor is walking. If we will visual that for a minute, then we have the sense of meeting ultrasonic waves. When these waves come because an object, some of them get reflected back, something that is called echolocation. Now. This reflected waves get picked up by this Enso, and it's calculate how much time it took for the wave to return. We're looking on the model. We can see that the sensor has to opening on its front one opening. Transmit the ultrasonic wave like a tiny speaker and the other one received them. Okay, like a tiny microphone. Now we have the time to Asian. It took the wave to go forward in backward form the object. So we will use simple physics. Met Okay, x equal toe. We multiply by t in our case seeks is the distance we would like to measure. And it will be equal to the speed off sound multiplied by the time duration the time duration between when an ultrasonic wave it was is transmitted. And when it received we divide this number by two because the sun wave has to travel toe the object and back. The last thing I would like to say about the trust on Extensible is the way we operate it in our polka. If we will take a careful look on the model, then we have two data terminal called Trig In Echo. The sensor takes measurement only when requested to do so. So in order to generate an ultrasonic in Aleppo gone, we need to set the Trig terminal on High ST for 10 microsecond. That will send out eight cycle Sonic Best, which will travel at the speed off sound, hit something and well received by the senses. Then the echo pin will be set by the central model as high state toe indicate the do a shinin microsecond. The sound waves travel. I will take this time and translated toe distance as we saw before. 8. Wiring All Sensors to the Arduino: wiring all the same. Soto That though, you know. Okay, starting with the DHT 11 Breakout models. It has three terminals. Vcc okay for the five volt s is the data appeal and ground. The sensor is using a single while Porto cold used for transferring the data to the Arduino . So we just need to allocate a single dig ital pain in the You know, we're going to use a specific library for operating descent so and the idea will be It's so simple. The sensor measurement, every time Interval moving next toe. The ultrasonic sensible that has four terminals vase isi connected to the five volt power Big and eco connected to selected dig ital pins end ground now, no additional components are needed and we can use it without any special library. The triggp in okay meaning trigger will be used to send the signal and the echo pin will be used to listen for returning echo. In addition for testing, we will display the distance and the temperature and humidity in the serial monitoring port . As we saw in level two, the LDS sent so require additional pull down Resistol Toby used in a simple voltage divider circuit. Now in Elektronik, voltage divider is actually a very simple, passive linear circuit that produce an output voltage, meaning the V out terminal. That is a fraction off its input. Voltage. Okay, the V in terminal now here the avian voltage is distributed on two Resistol. Our one in our to that are connected in serious and re out is actually the voltage dope on our to we will use this set up toe connect the LD a sensor starting with the Wien as the five volt and ground as a reference from the Arduino. Next, the LDL is like a valuable Resistol. So we will place it is ah, one and below a 10-K or fixed Resistol as to and then we connect an analog input terminal. Okay, a zero to measure V out in specific point. Okay. In the where the V out is located, this will be connected to the Arduino. Now, how this circuit is walking when the LDL it is exposed to light. Okay, bright light it Resistance the Chris. So we have more voltage. Drop on the static, resist on alto and we get in higher voltage reading in V out on the other side when the light is blocked. Okay, it's darker. The resistance off the elder increase eso the voltage reading will be low well on our 20 k and the voltage dopa. Now to now just as a remark if you're planning Teoh have the sense of in a very bright area it is better to use a lower pull down with this store like one kilo home Resistol instead of the 10 kilo pulled down. Resist. Oh, a lasting to know is that the LD R is actually a non polarized component so that the action , while connecting this component is not important. Now let's see a the circuit in the freezing tool. The next step is to use the nice freaking tools toe, see the sick it okay and to end. We saw and we used fretting in level one and level two very easy to use tools. And you can also download this a sick. It is a file A from the download section under this chapter. So please go forward. If you would like to use that also, basically, we're looking on the Arduino Uno board over Hill and the Bread Board below with all the needed component in our project in for that specific section right now. So let's review the component one by one. So, festival we're taking the five world and ground reference form that we know connected to their bread board and then distribute that to the other side off the bread board. Okay, so this that's the two connection over here. So that's the first thing we're going to do. The next thing is to place the 11 component, So starting with the DHT 11 cents. So that's the sense over here the DHD sends so is connected with three. A terminal. The 1st 1 is going in today. Five world and on the other side, the ground. Okay. And we need one terminal connected to the door, you know. Okay, this is Ah, the more the sensor without breakout boat. So here you see four. Terry. Now one of them is not being used in the actual hardware. Said that that we'll see in later. We have only three terminal, and this is how a model is coming. So basically, we're taking the single wild connection called s into the How would we know and we're going to connect it to a digital being. Number two Moving next is the LDL Senso. So there's LDS. And so we're using some simple voltage divider circuit where we have the LDL and another fixed Resistol and basically on one side off the voters divided. We're connecting five world and on the other side, ground and in the middle between the two Resistol, we're connecting the place. We would like to measure the voltage. Okay, that's will be connected toe under. Look, being a zero in that we know and the fixes this storm using is 10 kilo or good. That's the LDL sensor. Now the ultrasonic sends. So this this is the model that you see over here and get their four terminals. One off them is going into the five or the other side is going into the ground and in the middle, we have to that terminal. Let me zoom for a second on that. So we have the trigger terminal and the echo That's the two. So the trigger in their core going into the do we know over here to a connection number nine and eight as a digital being in the outdoor we know. Okay? We can't use aim The guitar being 10 toe am 13. And we understand that later. Okay, this more related to the next section. He now will course. And looking below, I added three more l e d. That will provide us important indication the 1st 1 is called event. Okay, the blue polo. It would provide us indication, in case they some event, like a special being caused in the ultrasonic. Oh, there is a life changing. The idea the next lead is called HDP at the end would like to connect this set up toe the the Web server. So in case there is some communication between the Arduino into the web, seven will get some indication using the slip. Okay, it will be used in later stage. And the last one is a l. Okay. In case there is some aero in the spoken stopped because of that elbow will get visual indication using that led now, each lead okay, is connected at the end to the Arduino. Okay, you can see the terminal over the rail and the one over it going into being a 54 and three . Okay, they get a painting that we know. So we'll be able to control them. Turn them on and office if needed in our program. Just more remark. Please don't connect. Led directly to the Arduino without a Resistol at the middle. Okay. Can damage the terminal and the paint. I mean, island, do you know? And of course, they lead itself. So So just put a small resistor like a 220 or Moses toe in serious. But each one off the led when it's being completed, connected toe the ground toe, complete the circuit. Okay, that's all. Okay. Basically, this is the second that we're going to use. Not so complicated, but it's important as a fair step before moving on into the next section. 9. Hardware Setup - Sensors: let's review the set of the hardware set up we are using in this section. So right over here, that's the albarino, you know, board and reality. So the capability off that board, it's more than enough for our project. Basically, we have the connection over there going into the our computer. The years be connection that also be used to distribute power and for uploading our sketch , the program into the boat. And then we have several digital terminal over there and several analog Tell me now just below. And also a ground in power connection that we can distributed toe our bread bodies. That's the bread board below. So we are connecting to the world board the power, the government power, and also distribute that to the other side off the bread board. Okay. Just using the those two wires, OK, moving on toe. The a component that we have in this circuit, it's so over here we have the DHT 11 that the temperature sent. So with free terminal right over a Okay, this is a break boat. Okay, so we just need to connect vcc one that ah am channel and and ground right over here we have the three led, as we saw in the freighting tool, connected in serious with resist of a fixed Resistol to limit the current passing toe. The led over here is the LDL, since all connected in serious with another 10-K fixed resist. Also, we have what is called voltage divider circuit in in the middle. We're connecting that to the doing, you know, into the analog. A terminal a zero and the L led itself are connected to several digital pains over so we can control them on enough. And on the left side. This is the ultrasonic Senso. Okay, Hcs al 04 with four terminals. I'm connecting that over here on the back side. And of course, we need to connect vis ISI ground into a data channel. One is the trigger, and the other one is the echo going into the terminal AP, number 89 in the outweighing. Okay, Digital connection. Okay, basically, that's the set up we need for this section. And now let's review the project in action and the relevant court used to operate all those components 10. Project Demo: okay. We connected all the components using the bird board. It's now connected to my computer. So we have power. I uploaded the 11 sketched to really we really viewing in the next chapter. It's time to see how the project is behaving. Okay, Some small project demonstration. So for that, I will open the serial monitoring windows. And of course, as soon as I'm doing that, the system is initializing and you can see the tree lead that light up. OK, this is like 12th testing period. Okay, now I'm getting the message. That system is ready. Okay? It is also used not just to test the leads in the system. It's also being used to let some sensible some set up time like the DHD sensor, and that usually needs, like around 62nd Justo initialized. Now I'm getting the first reading. Okay? Temperature and humidity. There is an interval to check that the temperature and humidity. Okay, I'm getting the next and eating. Okay. It's will be repeated. No, we have two more cents. So the LDL in the ultrasonic sensor, both of them are triggered. Okay? Meaning the system is always checking and hating the status off those Senso. But I will get an event if something is happening. And if I will cover the l D off with second. Okay, then I will get the deal. The arson so changed too bright. Okay, there is a less light on their there. If I will remove my hand, then I'm getting the LDS and so very bright. Maybe I will also close the light in this room. Okay, I'm getting in. You really I have some steel light from outside. Let's open the light again. Okay. Very bright. It is expected. I am. And this is a an event that we supposed to, um, transmit over the internet to some web server in case something is happening. And of course, I'm getting the temperature every every time. It Now let's check the distance. So in the program, I am decided to put 15 centimeters is a threshold. So well again, I will put my hand Okay. I'm getting some threshold reading. Okay? I'm my hand again. Okay. Different value. Okay. If I will place my hand and I will not move it, Okay. I'm expecting the program to understand the system. Don't send that they should only cost once, okay? And nothing happened from that point. Okay, I will remove my hand, okay. And then put it back again. Okay. Again, I'm getting the special distance. That was post again. This is an event that we will send to the Web server and that the treasured would cost. And what was the value that was crossed Doing the time interval? Okay, that's the ah project. The menstruation from the Calgary No side. And, of course, the next Step two is toe to be able to take this afternoon into actually connected to the internet. This what we'll do in the next section? But before, let's review the sketch, the program that I used to operate all those sensors small thing that I almost forgot to mention is the blue led. Okay, this lead over right over area. Okay. A This lead will light up for very short time. Zero point for a second if something else happened. Okay. Like a special distance that was closed or an LDL change. Okay, this provide us visual indication that something happened. Okay, That's all. Also will be useful in later stage, because on one side were expecting to see that, you know, using our Web server. We'll add that later. But on the other side, if you're looking on on a system that is sitting somewhere, it is nice to have some visual indication that something is happening. So let's cover the there for a second just to see okay, that they light the the bullet is light up. And also for the the stunts. Okay, The same thing very. For for very short time. Okay. The rest of the lead, meaning the red and the yellow will be used in later stage in our project. 11. Code Review: Okay. The last thing that we would like to doing this section is, of course, to review the sketch. The code that I used to operate a project so far. So let's do that together. Using that going i d. Again, The name of the file is Step one sense so you can download this file form this from that specific chapter that we are right now. So please go ahead. If you would like to make a play with the program and upload that to your project, Okay. Starting with them. Of course. Some comment really related to that file. Okay, we're talking about this level. Level number two A. And the description is step one setting the sensor. We're using a library that is called DHT That h just too quickly to see the library itself . Okay, so we know which library is needed. Okay, I will. A look on, see? All installed A libraries in my side. DHT and search for the h d. Okay, Does the law away that I'm using? Date's sense. So library. And that's the name off the developers in the name of the version. Okay. And you see that is being used to operate the central DHT 11 DHT 22. It's close it okay back to the program itself. So the first thing that we're doing is including this specific library, and then we are doing all kinds of valuable declaration. And you see, it's divided to the topic by Senso. So the 1st 1 is going toe to the LDL send. So we need. Okay, Del there is connected to a specific being number. There's an analog that's the first analog meaning that we know and is too string that that we're using to operate the D L. And we'll see that later led our last NLD, our current. That's the last status off the LD R and this is the current starters off the Elia we use it and later, under the DHD sense off course, there is the bean itself where the DHT is connected and then we are initializing okay. Using the library class, the HD a new instance that is called DHT, using the parliamentary where they did she's connected it do you cheapen in the type we're using? DHT 11 is the way to create a new instance to manage. Day says so now the next one is the time interval to between aiding the sense. Oh, okay. That's right. Now said 2 32nd meaning every 32nd we are reading the value of the DHT sense of reading the temperature and humidity. There are two additional global valuable related to the time and we'll see how we use it later. And the next sense of his ultrasonic sense So again, there to dig ital bean a tow, connect the sense So the trigger be number and there could be number. Now there is some flug a 1,000,000,000 flag if that will provide us indication. If that if there is some new traditional event Okay, don't worry. We'll see that later. M and some palm. It'll that defined the special distance. Okay. Only if the distance, coast this value then this is a new event and they are doing a will will indicate there is some special that was crossed. Okay, so that's a global value that we can easily change. Okay, there are $7 3 indicate oh led is Remember. The 1st 1 is event. If there is a new event like distance was course toe or daily are LDL value was changed. And the next lead is not used in this face. In this section, it will be used in the next section. One will connect the Arduino to the Internet and the next one is able. Okay, if there is some problem in some marrow, it is a good indication to provide us without opening the ceremony to import. Okay, Looking on the set up function again, we are setting the serial communication and then each digital a pain. Okay, some of them are all Put some off. The marine put is needed and we are performing short led test. Okay, That's also useful to see that all leads are operating. Starting the ditch the DHD Senso using dysfunction digestive begin delay for 12th. And to let the dhe sense off some starting time. And also to say, the old led indicator Really the it way turned them on. And then we turned them off right after that. And the next thing to do is to say they'll there last valuable with the current since so a light something that will it will be used later to indicate there is a new event and bring the system is ready moving to the loop function. Okay. What I have done is to keep the look function simple. It's possible. Okay, because we have several a sensor that we need to operate. So each function is actually responsible toe difference. And so the 1st 1 is checking the LDL. The 2nd 1 is checking the DHD, and the 3rd 1 is checking the distance. And there is a delay that we can easily control off a 44 400 millisecond between sense awaiting okay. And right after that, I'm also 10 off and event. The event led. If it was, stand on by some off the function. Now let's review the function one by one. Okay, Check El Dia or kill. It's looking on that function Check killed. Er we don't return anything. S. So the first thing that we're doing is reading the current LDL sensor and put that in jail . They are current. He felt their current is different. Formal. They are last meaning. That is, they were comparing from the last leading if it's not the same meaning we have something new. We have held the essence or change and this is two lines for the bugging for presenting their the our sense of change in the value and off course update the new the reading. Okay, so? Well, the last is getting there, the current, and we raise the event led. Okay, food. That is high way we saw here that we're using some internal function to get this and so light. Let's quickly see that over here. So this a function is returning this thing. Okay, What we are doing is that we are reading using the analog, read the LD R Value. And then we're comparing the value to difference setting. Okay, to understand if the light level is dark, deem light and bright, okay? Or maybe even very bright. And return that as string. That's all going back to the main look function. The next sub function would like to say is the check tht So let's cool school down and find that shakes DHD. I'm not returning in anything. So what we're doing is first awful reading the car in time using the dysfunction, Millis. As soon as you go down on their do, we know that you know will start a counting in merely second at the time, OK? And then we can use to do some simple calculation if the car in time my nose the previous time is more than the time interval. Okay? Meaning we cost the time interval and then we will hear the new value. Okay, so we are updating the previous time to the car in time, then using to function toe with the temperature in re temperature and humidity. Put that into viable and that's all. We are printing that on this year and monitoring screen temperature and humidity. That's what the last function in our will program is. The chick distance and let's school below two t find it. Okay, This is part of the ultrasonic sense off function. Check the stunts. A. We saw that in level two. Okay, The way to read the distance is using some mechanism. So where First? Awful. We are leading the the current distance from the older son Extensive. And put that in a day in the inviolable called distance and using this function, the food review and and then check if the distance course, the fresh 11 Ok, the distance that we just got is less or equal from the special distance. Invaluable. Look, It is a global valuable and you remember we said to 15 sentiment Er's and it's a neutral racial talker were using some bullion flag to indicate it's a new treasure old. Then we will print to the screen. Special distance was crossed and the value oh can set this Boolean flag toe false to understand the it's not the nutritional anymore and then raise the event led to hide it and on meaning that there is a there is a new event and if the distance was changed back and now it's bigger than the special distance, then I'm setting that The nutritional is true, meaning I can check again for new and looking for Newt special that are being crossed. Now this check distance exact is using some funky sub. Functional is called Get Senso distance. Let's see that over here. This is a function we saw before a meeting level to S o the way to get the distance using the ultrasonic Senso is using this mechanism. We are setting the trigger being too low for too microsecond and then set the trigger being high toe 10 microsecond It will send some being some some a best and and then wait for an echo toe, come back to their camp in. And then we're using some function to indicate situation off, sending the burst and get in echo using their coping and that situation and together distance. We're doing some simple A calculation, Okay. Divided by two and divided by the speed of sound wave. Okay, basically, that that's the program that we're using. Okay, of course. This is a building block for a later stage in our final project. Okay, if something is not clear for you and you would like additional explanation, please send me a question using the You did me a sight. I'm here to help you with your project. 12. Step 2 - Ethernet Shield: aeterna chilled. Let's get connected. We are in Step three after wiring and testing the old needed sent. So the next important step is to connect, are doing all toe the nettle and make it a connected device. Now, as soon as we will do it, the application options we can build without we know are becoming much more interesting. And it is another step off making our are doing a project and Internet off things device. So in this section we will start with some basic short introduction to networking. And then we will focus on how to use the Internet shield model Obote as an easy to use extension models to the Arduino, starting by setting the needed hardware and then develop a program for testing simple client server communication. We are living in the age off Internet everywhere, and networking is a critical element for enabling this worldwide connected things. We would like to connect our Arduino project, toe the network and before jumping to the practical side and how to connect news that on a chilled model, I would like to set up a common ground around networking as this is important for making sure that everyone understand what they are doing? If you feel this is not enough for you, please go ahead and add the question in the U Demi side. I'm here to help you. 13. IP Address: starting with the famous I p. Others. We all know this is the logical network address. Okay? Used by the I people to call toe, identify a connected entities like a computer servers. Some I ot device and so want when we type some web, you are rail address in a web browser. It is at the end, translated toe an I P address, and then I will computer. We know what destination address took place inside that straight. Okay, To reach the destination, I p address is a numerical label. Okay, That is usually written in some human readable notation. Okay, with four blocks off number, and we doth between them. Okay, this Is that what we called I perversions for? Actually, there are two version off the Internet protocol. I'd be version for with 32 bits number and I perversion six, which dramatically extend the amount off available, other s, and you can see them on the size of that. It's 128 bits. Okay, Most probably you are familiar with the structure or fight division for, and that's good enough for our project. There are two main types off I P address, local and global local I P address is only unique in specific local network. Okay, Like our home network or some office network on the other, in global I p is an I p that is unique around the world. Okay, with a dedicated organization called the Internet Assigned Numbers Authority that is actually managed the i p other space allocation if we take a look on some home waters, the connection to the ice B is based on a public facing global i p others that is visible to the rest of the off the Internet And on the other side, many local addresses for all kinds of devices connected using Uihlein wireless toe the router. Okay, this is the local I. P. Actually, your Internet service provider is using a pool off global, others is and most probably it will allocate a global I p address when your router is first connected to the network. Or, you know, starting up this global I p other. This allocation is completely transparent from your site. So we usually don't care about the global life now how a device connected toe the to the power router is getting and I be Atlas an I. P r. This can be allocated menu Lee or dynamically, when we define an I p manually, then it is called ecstatic i p and that's the case. We need to make sure, for example, that we don't define toe connected network entities with the same i p others. That's a little bit more complex to handle in a large, dynamic network. So another more common option is to allocate an I p. Address using something that is called the HCP service. The recipes stand for dynamic host configuration, political and all outers today are supporting such capability. When we connect something toe the network at the http request is initiated by the device toe the local outer and then the auto dynamically assigned the new device and available local I p others. This off course makes the network set up much easier and faster. One thing that is important to remember in that case is that every time we start up our computer okay or reconnect our smartphone toe the local network, there is a high chance to get a different I p address as it is allocated dynamically. Okay, in the context off our doing a project the widow is going to initiate network communication with the Web server. Sitting in our local home network is what we are planning to the well going Taubate, a web server in our local A network so that we don't need to know the web. Seven i, the others. Now, assuming the Web seven application were planning to use will be located in our computer is And as I am demonstrating in this course, then we have some small task to remember. The Arduino sketch must be updated with the current are located I, p. Address off the Web server. If will not do it, then that we know will not be able to communicate with our website. Okay, if you're planning to assign a static i p address to the computer where the Web seven application will be located, then you need to do it only one time. Okay, because the I p address off the Web server will not be change all the time. 14. MAC Address: the next type off. Uh, address is called Mark. Okay, stand for media access. Control of this. This is the physical interface. Hard will address. Okay. It is usedto uniquely identify every single device connected to some local network. Now, you can ask if we have Okay, we've used an I p address. Why do we need a market this? Well, they are used for different purposes. Okay. The I P addresses a logical others related to the network level and mark addresses related toe the link layer both off them are needed most often. The Mark address is assigned by the manufacture off the network interface controller. OK, in short, Nick, and usually this addresses configured and burned inside the device memory. For example, if you will check your home water for a second, the most probably will find below the mark address that will be printed on some stick ill attached to it. Because you see, over here on the right side now, such mark, others should be unique all around the world. So every device manufacturer is allowed to use a specific range. Okay? It is quite large. Okay, because the address spaces using 12 x a decimal number. For instance, when we buy a computer, okay, there is a WiFi mortal inside, and it's using a unique mark. Others and the wire line Internet adopter in our computer is also using a unique mark. Others we don't need to configure anything now, in the context off our doing a project, most probably the Internet model we are planning to use is usually coming without a mark. Others so we need to set it up in our program is not a big deal issue, but we still need to do it. I p nettle communication is based on stay mawf pockets. Okay, that I'm holding the data, Toby Trance be transmitted its payload. Every pocket being created is coming with source and destination address in the link. Lil, as you seemed in the green meaning with two mark address One of the missiles and the other one is destination. And also in the I p layer, there is a source and destination. I p address the set up off the mark and I p source addresses only done one time. So when they are doing a project, we start up in the set up function. We need to make sure to set up the mark and I p others. So when the Arduino project will start up, the set up function in the poor gun will need to make sure the mark and I p are allocated now related toe the mark in I p destination market destination is handled automatically using a protocol that is called help. However, I P destination is dilated to make a specific connection. When one device would like to communicate with another device, then i p destination address is also needed. Let's do some simple a demonstration related to wipe in a mark address. So under Windows seven, there is a command that is called I p config. Okay, well, some May barometer that is called all. Basically, I'm presenting all in interface configuration in my computer. And right now my computer is only connected using a wire line connection using summit on it adopter toe the toe, my home router. So over here I can see some little's. For example, the physical others. That's the mark address. Okay, it is 1/12 exit decimal number which expires. I know there is a date. Sippy, that is in a services is enabled meaning this interface got the i. P using the DTP service in my home in my home router. That's the address that I got. In addition, that I date office also is a configured with the different gateway. Okay, this is the route address when you would like Toa go out and connect to something in the Internet. Now that's a mark address. I can't change. It's coming. It's part off my Internet adopter, okay? And the i p address. I have some control. On top of that, I can confirm configure. That is a static I p. All still let the outer toe config that a automatically using the DCP service. Now let's see the connection toe mark. Others okay? We know that my computer need also a the mark. Others the destination mark others to be able to a cent communication to some other elements. There is a command to present the mark address that you enter Facility lend. Okay, it's called out book. The political is called up and it's also a command that you can use em if I will use some Impala mater's I can now display for each i p others the physical make address. Okay, So for example, that's lying below. This is my logical i p Others off my out. And now I know the market address off the router. And in addition, I have some other device in my network that is ending with the number two, and that's their mark. Others off that network element. Okay, there is a There is a command also toe delete a mark other century. Okay, so let's do that for a second, okay? We'll choose some others okay? And deleted from the entry. And let's display the list again. OK, now, there is no such line, okay? With the number two meaning only if these will be some application that is trying to reach this I p address, then they are protocol with, We will be used to be able to get dynamically the mark address off this specific I p destination. Let's do that. If I will pink for a second, okay. Peeing is sending some eco command to some destination. Okay, that's very simple testing. I'm thinking to this address, okay? And I'm getting reply off course, but the interesting thing thing I would like to show you if I will go back to the ill placed. Now I can see on the disciple address the the Mark address again. Okay, so basically, this is completely transparent from user side. Okay, Everything is is managed by the operation system, but in the context off all day. You know, we need to know that we need to configure this physical address, that's all. 15. Client Server Communication: a large part off network communication today is based on client several communication model . Okay, most of the Internet traffic is actually based on that. Well, we ever sell ver that is designed Toby a centralized system that self many clients, so a services used to provide resource and service too many client by waiting for incoming requests. The provided information could be a webpage, some that a base information, some file and many other things. A client is a device that request data and obtained the response from the server. For example, when we access some website, our browser is acting as a client in the remote Web. Seven is the silver, accepting the connection from our browser. Now again, in the context off our albarino project, we really use the same clients, every communication where the bueno will be the client and our computer. Well. We act is a Web server and also be used as a Web client helping us toe access the information being collected from the Arduino and stowed in the website that obey server. Now, how do we create such session between the client and a server 16. TCP and UDP Ports: a single computer can run many Internet application on the same time. Now, when a data is arriving to the computer while line one less interface how the operation system knows which application should process the data. In addition, when connecting to some remote server Okay, we need to specify what kind ofs Elvis we're looking for. Is it a website? Maybe? Would like to download some file, etcetera. Well, now we are moving a little bit up on the communication layer. Tow the transport a layer. So we have the link layer with the Internet is an example. And then we learned that we need to make others. We have their Internet, Leo and for example, by using the well known I people to call. And then over there you need an I P address. Now we are adding the transport layer where we have to type off. Well, very well known. A proto Courtis ipi new dippy. And over there you need to specify something that is called port. Okay. Ports number. I used to separate data stream toe the relevant application. Now there is a long list off public poets number. Okay, that identify which service is needed. For example, FDP's using port number 20 and 21 secure Shell is using 22 the html page. We get form. The Internet is based on the http particle that is usually using the different port 80 80. Now why This is important. Well, when our do we know will access some Web server, we will lead to indicate the Elefant needed service by using a port number. A combination off I P address and port number are leading us toe the next subject called Network Soak it. 17. Network Socket: network socket is basically some endpoint off a logical connection, and this is completely managed dynamically by the operation system. Every time you open a new windows in your browser and look toe a website or maybe download some files or watch a movie, it will be handled by a dedicated network. Soak it, soak it address. Okay, is the combination off I. P address and Port number now transport protocol we saw that is usually using TCP or UDP. Now in network socket is the combination off soak it address and specific transport protocol. It now is an Arduino poor grammar. We need to know how to create, use and handle such network socket. Okay, it's not rocket science. It's very easy. So to summarize, when we would like to create a network, soak it in our program, really to provide the I P address as destination port number is, they needed service from the remote several and to true specific transport political and in our case, it will be the Tous IPI transport protocol. Now, when I don't think to say about network soak, it is that normally server runs own specific computer and has several soak it that are bound to specific port number. Okay. The sever. Just wait endlessly and listen to the socket for reclined toe. Make a connection request. So here we have a server. Okay. Waiting for three different services. A touch to three different socket. Okay. FTP edged appeal. Telnet on the client side declines should know the host name off I p off the relevant server and the port number on which the server is listening Toe. Okay, so if I need an FTP, I will send a request using the port number off FTP. So this is the first step before making a connection. 18. TCP Session: to make a connection request. Okay, we saw the decline. Try toe open a session with the sale ville. Okay. Using the server i p address in the relevant port number and they needed a transport protocol. Okay, if everything goes well, the server except the connection request and will create a new dynamic silver side, soak it bound to the same local port and also has its remote endpoint. Okay, the client endpoint. I m close the session and twin, so this is basically something that is called Soak it to soak it virtual connection. Okay, Socket on the server side and soak it on. The client side declined, and the server can now communicate with each other. Okay? Writing and reading form their 11 socket. Now, every DISIP e connection can be uniquely identified by it's to soak it in point. Okay. The clients I took it and the service I took it. Now let's see example off such disip ization in my computer with to soak it as endpoints using again the same the command line. Okay with another a commander, it is called net start. Okay, with some pollinator, I can see all established tous ipi connection on my computer, and that's an example. Off network socket. So on one side, we have the port of call that the situs IPI Okay, each line represent the socket. So that's the I B address. Okay, on the local side. And this is the port number, will, on the other side again, we have an I P address in a port number. Okay, And it's the state off decision. This is established. There's a walking established communication between the client and the server. Let's see another line. Let's take this line as an example. Okay, this is outside my network. So this is an I p off my computer. Some important number. Local port number and a destination AI pr this and a port number. And now, actually, 44 tree is a port number indicating a very well known protocol that is called HDP s. Okay, it's a secure connection to a sites. And of course, when this server is sending information back to my computer, Okay, the operation system knows which application should get that using this combination. OK, there. Port number that enabled the system to know this is the specific poses application that should get that information. Okay. That's the way to get the least off established a connection. Now, there is another Parmenter that you can use to see which port your computer is listening. Okay. Like a silver, for example, my computer is listening to the I. P. Address. 80 because I am. I have the web silver installed on my computer. This what we're going to do in the later stage? And I set that the port number this Web server will listen is 80. Okay. And this is why you see that this is in listening state. OK, that's basically the way to see all the listening port in your A computer or any other server that you're managing. 19. HTTP and HTML: the next important thinks about wept. Networking. Is there widely used http Protocol and html A language now. Http is hyper text transfer, political and perhaps the most popular application protocols used it in the Internet. HDP is basically function is a request. Responds Porta called in the client server computing model that we saw a few slides ago. As you can see on the right side http seating as an application layer on top of the recipient transport layer html Oh, hypertext markup language is the language of the web. It is a markup language for creating webpage and web application. And the HDP protocol is used to transfer will html information. When a whip client sent an http request OK, message to image. To be sever the server will return was something that is called response message. Okay, now a web browser, for example. Maybe the client and an application running on a computer. Okay. Hosting a website, maybe the server. When we type A, you are ill. Okay. For my browser toe, get the web resource using HDP. The browser actually tends the u R L into a request message and send it to the HDP server okay. The sever, which provide all kind of resource like energy mill fires another constantly, like video files, files to download or maybe also perform other function on behalf of the client will return and a spoons message to the client. Now, the response message, of course, contained off Carl kind of things like completion status information about the request and may also contain the requested content in its message body STP as a protocol defined several method to indicate the desired action that would like to perform on the server side . Now, one of the most common method is called the get method, and it is basically used to retrieve information from the Web server. We will use Okay, the get method to facilitate the information exchange between the Arduino and the Web server. For example, the following you are well, okay, link okay to google dot com is a an example of get requests. Okay. After the link address, we can see there is a question mark in the u r l that provide a way to send viable okay in the u are relative in this case, the valuable A g f e under school out of these being said toe, see up and the valuable F G said to one. Okay, data is sent as valuable purse separated with an UN percent. And this is the trick we will use to submit data. Now, When the page okay in the service side received this your rail and the valuable inside help toe identify what exactly is needed to be done. Like performing a specific search and off course returned the result as there is a page now . So in the context off our bueno, we will send the sensible data is valuable inside the u R l off the get request to be able to do it all. Do we know we need to create an http request message like your browser is creating? Looking on the structure off financially P request message. It consists off a message. Edl Okay. And an optional message body separated by a blank line. The first line off an http request messages called the request line and it is based on cree filled the method filled like get the u R I feel that specified the resource requested and at the end and HDP version field And where today there are two versions that are currently news HDP a 10 image to P 11 now the request header are in the form off multiple head of field. Okay, names and value separated by comma. This is the way off the browser to provide more detailed information on decline side. So the several will be able to provide the right content. No, this is an example. Off a get request. Ah, we see the get meddled. Ah, my side and indexed indexes. The u R I okayed requested resource. We're using version HDP 11 And when we can see several header field names with the relevant y value like the host name, for example the language that should be used in So one now Don't worry, We will see all of that in the ball game court. It is not so complicated at the end, that's all. For now, we're getting some big home theory about networking and Web communication. I think it's time to move on to the practical side and start using all the things that we learned so far. 20. Ethernet Shield: so we covered. Few basic things are networking and specifically were bare networking. Now I would like to present the hardware model used to connect the Arduino to the network. If you remember Level one, meaning the first course under the crazy about Arduino, a training program we discussed about the options to extend the features off the doing No, no board. For example, it can be a breakout, separated model that that we can connect to the, you know, using wires. Oh, it can be a special type of board called chilled, meaning it is seating and connecting to the Arduino board without any wires. This is the type off Internet model we will use in our project. It is called a turn itude w 5100 This shield the neighbors I was smaller. Do we know Toby connected to the Internet and by doing so, opens up and less amount off possibility by allowing us to connect our project to the Internet. This model is including single Internet LG 45 connector with the maximum speed off 100 megabyte and up to four simpleton use socket connection. The board also include Micro as the card slot to stow date eyes files but will not use it as our data will be transmitted on in time to the central database. Now this mortal relies on their doing no Internet library, which comes bundled with the development environment that doing i d. This dedicated library is usedto easily set up the interface and initiate communication off client and server one off. The useful things with Arduino Shield is that no external wiring is needed. We just flag the shield on top that doing aboard, as you can see here on the left side. Now this keeps the peen layout intact okay on the top side and allows another shell Toby stucked on top so we can keep adding more and more shield is needed. Now the connection with the Arduino is based on SP. I bus through the eye CSP heather, you feel remember form course level one SP I buses used as a communication channel between external devices and that win now something very important to remember is that this SP I connection is utilizing digital pains 10 11 12 en 13 on, you know, as they are reserved for interfacing with the Internet model and This is what you can see on the right side. So, you know, we're all do we know, You know, we will not be able to use those pins. Okay? Meaning 10 11 12 entertaining. And you will see the project that we're not going to use those beans. The power for this board will be supplied. Okay. To the two board using the USB cable that is connected to the Underline are doing No, no board. The only things, of course we need to connect is now the Internet cable two our own, Walter. Okay. The connection between that and a dental face toe the outer in our home. Okay, Like any Internet interface. Okay, the board includes several led. Okay, Is indication this what you see here on the on the right side, for example, the link indicates the presence off a network link and will quickly turn on and off when the should transmit. Always save data. The next one full day indicates that the network connection is full duplex and 100 m indicates the connection is up to the speed off 100 megabyte per second network connection , Alex antiques will turn on and off when the shield receives and sent the data and the last one c o l l meaning collision. It will provide us indication when network collision are detected on the link layer. 21. Ethernet Library: as we led. So in course, Level one and Level two that we know eco system provide the very large open source could grouped as libraries. Some of them are melody part off. They're doing No, I D. And and some of them can be installed manually if needed. Now for data on a chilled ER is a dedicate library that is used to set up the mark and I P address. Initiate connection is grind to a remote server and also accept connection as a saver form remote client it. Let's review the main classes this library provide. As you can see, the Internet library provided several useful classes. Now which class to use is really based on? What are we trying to achieve in our program? Under each class, there are several functional method that can be used. We will always use the first class called Internet here on their left side Internet class, and also this next one. The I P address classes are related to the Internet should basic set up meaning setting the mark address and static or dynamic i p. Others the next one. The several class should be used if we would like to set our world we know as a server and accept connection from client. Now imagine, for example, that you have few cents so connected to an Arduino board and you would like to visual the sense of leading off a webpage. In that case, you can set up their doing know is the Web server and connect to it using a Web browser using HDP political. Now still there do you know at the end is a very small footprint, a computing device with a limited resource like memory and CPU power. So using that as a server is probably not the best method in more complicated application. So the next class, called Client is used when we would like a world we know toe connect were remote, several, like a remote web server. We moved out of this. We can create one or more clients, okay, that can connect to serve and send and receive data in our project. This is the main class we will use as we would like. I was doing, you know, to read Senso and push value to ah, we're Web in that the base server 22. Hardware Setup - Ethernet Shield W5100: Let's quickly review The house was set up so until now, a We connected, you know where they circuit the bread board with old needed component. OK, all the same. So and we're not touching the world board anymore. What I added is the Internet chilled right over it, sitting on top of the do you know, nobody for will move that a little bit so we can see how that is connected. I am in a nice way to they're doing aboard now. The only thing that we need to do is to just take their Why is that we connected to the, you know, border and now connect toe the same pains just on the Internet. A shield, that's all. This is the only thing that we need to do and, of course, connect a do we know right now, using an Internet cable to ah will a home router. So we'll be able to get an Internet connection now looking on the board itself. Okay, so, of course, all the available analog and digital pains that we have in a all do we know, you know, available over real. Remember that we discussed that digital P number 10 until 13 are reserved as a communication between the two boats, so we cannot use them. And in addition, there is an SD card slot right over here if you would like to save a files. But again, we're not using that in this project, and the group off leads right over. There are indication, or four kinds of things like the power off aboard Link. Meaning there isn't. There is a link to the to the card. Full days, the full duplex connection a collision takes and Alex provide indication of the and board is transmitted to receive data. In addition, there is the visit button that is just located over here, and basically that's all thats they needed. The help will set up. And from that point of time, we can run our boredom and use that eternity boat, you know? Well, it project 23. Project Demo: Okay, let's see the project. Okay. In action. We connected the Internet model right over here. Now it's connected with the cable toe. My home router. And I can say some indication off the power to the boat. The red led and another the next one. Provide me indication that is a There is a link. OK, before we disconnect that for a second will see that, um, the link is disappearing. Let's connect the buck again. It will take them sometimes. Hey, now what? We will do you okay? We're not using the sensors yet. We just want to test. Ah, this model. So what? We'll do we? We'll a first a full set up the market address and then we will ask for a dynamic I p using the D. Http protocol for my home router that will allocate an i p others to their doing, you know? And then we will initiate http request to the Google site and hopefully will get HDP response and will display that using the serial monitoring port. Okay, let's open the serial monitoring port. Okay, that restart the green aboard. Now we're waiting to get the I P address from the DCP service from from the voter device. Okay, Okay, great. I got the I P address. The system is where Israeli. I put some 12th delay before initiating http request form the Google site. Great. We send a Now we can see that we send an http request to the web server. And this is the lines that I used using the get method and some a problem. It, er is a search, a permitted toe, the Google site. And after that, sending that the connection is its clothes. And just after one second, I got em. This is the HDP response, okay? Always, you're getting some number as an indication and then all kind off a other field, okay? And some empty line and the content itself focus the body off the M HDP response from the Web server is right over here. This is the place that the your Web browser will use to display something on the screen. And, of course, I'm printing that there is a There is a disconnect from the server after getting that information. And that's what this is basically simple testing to get an I P address and then a check that we can actually send an http request to a Web server and get an HDP response. That's all. This is what we need in this section. Now let's see the code I used to operate the project so far. 24. Code Review: like always. Let's see the court okayed sketch the program that I used to operate that Turn it card. Okay, that's the name of the file. Step to it on a chilled you can download that specific filed form, the chapter that we are right now. So please go ahead. If you would like to use it if we're looking below festival were including the neither that innit library. And then we're setting some needed barometers. The 1st 1 is in a way off the mark address with six pairs. Or fix that. That's immoral number. Probably You can use the numbers that I'm putting right over the chance that you will, by mistake, use the same AM characters Is another device in your local network is almost zero is Don't be afraid to use that. And then I'm using actually the Web seven. You are l w w google dot com in our project. Okay. In later facing our project will use an I P address. Okay. And then below the first thing that we're doing is initial initializing the Internet client library. OK, that this is the way to initialize that in creating new instance called client. We will utilize to led and that we used in section in the previous section meaning the the Evo lead. And in this phase, also, the HDP led the pain. I am looking below on the set up function. So we're setting the serial port the pill mode off the two led putting someone second delay to let the Internet car tow boot up. And then we are asking for an i p dynamic I p Okay, using the day http a protocol and this is the way to get it. You are using this class Internet and then a calling to a function that is called begin providing the make address. Okay. And if it's ah equal to zero meaning it was felt so I will print fell to configure it and it using this API will raise the daily the there were led and put some endless loop to stop doing something. If it's success, OK, so we're going forward and then we are printing the I P address. Okay, My I P address and then I can use some function to get the local I p that I that I allocate . Okay, Printing system is ready 12th delay and then putting some 12th delay and then sending only one time. And htp requests toe the a Google website now looking. Let's see the http request for a second. This is them. I am function right over. Well, first of all, we are connecting there. Do you know it's declined toe the Web server and this is the command to do that. You were using the instance Klein that we created and then calling a function that is called connect and providing too a pal emitters. It could be a Web server. You are ill or Web seven like be. And the port number. Okay. You remember that when we would like to open a tous IPI session, we need to open a okay, soak it to soak it connection. And for that, we need to provide the destination and the relevant port number. That's a if it success. Okay. And then I'm turning on the HDP led indicator, okay? Meaning? I'm starting HDP communication. Okay. All those lines for the bugging. I'm using the serial monitoring poto present that I'm connected and I'm sending some htp requests. And this is the stringer that I'm sending and and if I will go below, this is the actual way to send the HDP request. I'm using again. The instance Client and I'm printing OK, using a function that is called print Ln Okay, they request OK, using the get a method and some parliament er's as the need is what I would like to get and HDP ah relevant God. And also some edl value like the s name and that I would like to connect the connection right after that printing an empty line. Okay. To indicate this is the end off the http request message. If there is some, Evel and Avellino cannot connect to the server and I'm printing some message connecting failed and then 10 on the ever lead and put the program in an endless endless sale. Okay, that's the htp requests. We only running that once right over in the set of function and then in the loop function. What we're doing is we are reading the HDP response coming from the silver. Okay, using a function that is gold. Okay, first of all, that we are checking the is available a characters using this function. If it's relevant, then we can read it using this function and just present that function on the serial port. So this is a way, a simple way to present HDP response now is if there is a this connection with the server, we will them off the HDP led. And then we will a stop a the declined and then do nothing forever in the main Borglum loop , that's all. As you remember from the project demo, we actually asked for the i P address and then send one time HDP response and display that in the screen. Okay, this is will be the building block moving forward in our project. 25. Step 3 - WampServer: Step six wants ever setting a local Web server. Until now, we learned almost everything that is needed there, doing no sight, OK, including wiring the hardware, creating the software court used to read the sensor, set up a date and it mortal. And we learned how to initiate simple http request It were Web seven and we used Google as a remote Web seven for simple communication testing. We didn't yet sent the outgoing sense awaiting toe a Web server okay, and store it in a database. So now it is time to learn how to set up our personal Web server using application called Wamp Server. This is the point where we start playing with the power off Web technologies and making a world we know a real cool I ot sister. Okay, so what is wants of 17 is a free web development environment for Windows, Okay, that enable us to set up and run a Web server on our A computer and most website that we can develop. It is basically a package of tree main building blocks Apache two PHP in my SQL. If you're looking on the world Wamp, it stands for up a as Apache two in my skill and pee PHP where the first letter W indicates that this is a package for Windows operation system. Basically, this is an easy to use web development environment for Windows. We can download that from the following link, as you can see while choosing the relevant version. Okay, there. Toe version 30. Tour in 64 bits now is Wamp. Server is limited to windows. You can choose toe, consider using other amp software stocks like a mom sump. And there is another one who had called big nummi for additional operation system with some different company. Okay, if that possible, try to use the Wamp server is this is the software picket that I'm going to use Okay for the demonstration. Now let's start to review the big nick blocks off the one server. 26. Apache, PHP and MySQL: The first component is the actual http Web server that is called Apache. Now, this is one of the most used Web server software worldwide. Okay, Is today 2000 and 17. It estimated to serve around 46% off all active website. Okay. Can you imagine that? Almost half off the website Active website and around 43% off the top 1,000,000 website. Okay, this is also a huge amount. Now there are many other Web server application. However, it is still the most popular. Apache is developed and maintained by an open community off developer, a spot off the Apache Software Foundation. Now they support the development off a number off open source software project, including their Apache Web seven. If you will open the site off the Apache Software Foundation, then you will be able to see that they are also maintaining many other project like the famous A dupe solution for big data s. So, basically, this is the http Web server component. The second main component in the wants of a package is PHP. It is basically a plugging for the Apache Toby ableto one PHP script PHP stand for a PHP hypertext people says so, and at the basic level, it is a several side scripting language for Web site now. Silversides scripting language, including PHP, are usually designed to provide the dynamic content. In Web site, A PHP is again a community project, and it is recognized by a the blue nice elephant that we see on the right side. We we learned to use PHP code toe, perform action on the Web, several, like reading and writing sensible data to the database. Now I'm not planning to teach PHP and went okay. We will end the basic things that will enable us to create the needed script. The next and last important building blocks off will use under the swamp. A package is my school. My scale is an open source relational database management system, he showed. It's called Al de BMs, supporting multiple Always say platform. My school is now owned by Oracle Corporation, and it is still one of the most popular open source that the based application in the Internet, almost any website today has capability to store and retrieve information for me, that the best in our project we need that capability. So using my school we will be able tow easily, create and manage that The base inside the sense of reading coming from the Arduino is records toe the irrelevant that obey, stable and query historical data in specific time interval to be able to present that a on a weapon. 27. Download and Install: The next step is off course to download the one server the once ever file. So to be able to do that, we're going into the one server link 17 dot com, and that's the skin that will get as a reminder. The one server is a package off the Apache is the website of the HDP Web server. PHP is a plugging Toby ableto one silver side skipped that are based on PHP, and the last building block is my school is a national database, so we will be able to stall kind of data now as a reminder. The Wamp server is a Windows based development environment, and now the next thing is, of course, clicking on. Start using one server and you will get an option toe decided 11 version, the 64 bits and 32 bits. If you're not sure about the version, your computer, you can go into the control panels and click on system, and you will get the old under system type. You will get the 11 version okay. For example, I have 64 bits Operation system, meaning I can use the 64 bits a right over it and I'm getting an option to download this file. I can click off right over it and download that file. Now you can download the fine. That's OK. But before learning the Wamp several installation, you need to make sure that you have something that is gold visual Studio C Plus plus 2012 runtime libraries. And you can download that from this link. Okay, If you're not sure if this is L. A. D installed in your computer, you can go again into the control panel, click on poor gums and features and below. You will be able to see if you have all those needed on time libraries, and that's a long list. Now, if you don't have it, then plays do going to the link that we saw right over here. And that's the windows that you will get. Form a Microsoft site and you can download the most updated package from here. Eso again. You need to make sure this visual C plus plus package is installed before trying toe one. The one several installation for that's all. Okay, so we don't loaded the one server installation file in some location, and now we are ready to do that installation. So let's do that together. Choosing the one language. Okay, and then there is some long license agreement. If you have some free time to read all of that, I'm accepting the agreement clicking next, and I'm getting some important remark. So the 1st 1 is to make sure that we have an up to date visual C plus place on time libraries with those package VC 9 10 11 and 2 10 and 14. And of course, this is can be changed in the future, and the next one is to make sure that we don't try to doing installation off the warm several over an existing version. Okay, there is some a process off how to do that. Another thing is that used the suggest default for the spot off the installation. Don't try to do something else because they sound limitation with space and other characters that cannot be used on the program pet, and we need to make sure that Skype is closed or it least force the publication not to use the same port off the 17 minute boat 80. And, of course, we disable any other available Web application that are using the same airport clicking next. Okay, keeping the default folder again, clicking next and then doing that insulation. This is a long process and can take up to 5 to 10 minutes is so I will skip it and go to the end off that installation and will continue from that point. Okay. The whistle also will ask you to set the default browser for the one server, so you can choose whatever. Well, so that is a that you would like to use. And at the end, you will get some remark about the PHP. My had mental is that we will end how to use. And the remark is about the user name and possible the user will be would. And there is no passport. Okay, You just keep it empty. Unless you would like to change that. A clicking next. Okay, I'm completing the one server installation now. If everything went well, okay. You can go and run the wants of application clicking on that. Okay. Would start to run right over here in the background. Okay. You can see that the cola was changed from a red to win. If we click on that I'm getting some menu and from the system may play, and we learned how to use all of those options. But the important thing is to verify that you're getting again light, meaning the 17 is running a on your computer and ready to be used. Now if you don't get a the gin coehlo, meaning there is some problem to run the 17 application. And it's probably related if you have a Skype or not. The application that is utilizing using the same a port number 80. And if you will change that, you will see that the warm server is walking. Okay, that's all regarding the installation process. Now let's start to learn how to use their warm server. 28. Getting started with Wamp: assuming that you succeeded with the 17 installation. So it's now am running on your computer. Eso in my computer. I can see that is an icon right over here. It's an again Kahlo. Meaning the server is actually ready. Toe, answer an http request. If you click left on your mouth, you will get all kind off options in the menu. Eso the basic one is toe startle services or stop all services. If I will click on Stop all services, what will happen that the Coehlo change to read? Meaning the seven is not actually ready to accept a web request. Okay, there is no services that will be ableto am. Answer those requests if I would click again and bring it back. Startle services now is changed to green. Now clicking again on the left side. We have all kind off options. The 1st 1 is to get the local host menu. Okay, where I can see the several configuration. That patchy version, the PHP version, a on all kind off extension being loaded inside the my Skrill vision and all kind off tools . Okay. We'll mainly use the PHP my ad mean to manage the my skill and we didn't create it. Any project yet. Okay. You say your project No project located yet s So that's going to be the next step. While we are going to configure the server a going back to the menu s. So that was the local lost. We have a quick am linked to the PHP. My admission that we can also access from this link and we can access the www director. I mean, that's the day actor we where you are going toe create the project. OK, your site project and we're going to create a folder and inside those this folder, we will put the needed escaped and HTML if five is our whips of OK, we'll do that later. Going back to the menu. So under the menu, we have a remained option related to the Apache configuration. The PHP and the my school will touch that later. If instead, off clicking left will click right? Then we'll get different options. The 1st 1 is to see you know about the server version. Okay, we can see the building block off the one server at the Apache version, the pH being the my SQL a going back and clicking right, I can refresh the server. If there is some problem, I can change the language off that menu. The additional options to change the warm sever, the one server sating We're not going to touch that yet. And they're in an option toe exit And to close the once ever and all kind off tools that we can do a simple testing related toe. The one server, Let's see some of them. The first important option here is something that is called Test Port 80. Okay, we can test if the Apache Web server is really listening. Towboat 80. Okay, is getting htp requests. We have also the options to change that to another port number if you would like and test the boats. So I will test right now. Rotated that is configured as a default. Clicking on that and you can see the forces number. And that is listening to the port 80 and everything is OK. This is correct. A Just for your information, we saw that before using the nets that okay, the nets that command if we'll run it with some parameters, we can see the process number and the name. They're each one. If it will go up, I can see that. That's the HDP D work. It is a Web server and it listening to board number 80. Okay, it just for checking. Let's, for example, go to the Web server and ask to stop or services. Okay, I'm getting the red cooler and let's run this command again. And, of course, if I will go up, it's not listening to the port 80 anymore, okay? And if I will bring it back, of course it will start listening to the port again. So that's a simple testing that we can do. Okay, let's close it. The next useful testing is two steps. The my Skrill. A port number. So again, I'm going into test port. Okay, there is a different number. We don't need to change that. And then I'm running. I'm running that and I'm getting the test results for that report number. I can see the posters number being used by the my SQL Process. And okay, I'm getting this. The service from the warm several. It is correct. Everything is okay now. They are additional testing that we can do in the tools menu. Like checking the state off the service. Okay, I'm getting that. The services started on Everything is ok. Ok, well, services are started. This is OK as additional indication. And I think that's enough from the tools that we every we can also empty looks file if you would like we learn how to use the log file later. Is so from that point we are We would like to go into the next step and start to configure a the one server. 29. Basic Server Configuration: after the installation and the simple testing we have done on the one silver. There are few simple configuration steps that are needed to complete the server set up. And the 1st 1 is to create a project folder where we're going to a place our fights. So I'm going right over here clicking on the W W W directory. Okay. And clicking right. Creating a new folder is going to be the name off our project it. Now, please use this name my that Lo Gil. Okay, because this is the location of for the location that I will I'll do, we know at the end will use to be able to access the needed script. Now, let's do a simple testing. I created some simple HTML file. Let's place that in this folder we can also edit and see what I have created is like basic html a document. Ah, with some title my website and some park off inside. This is going to be my daughter Local website. Okay, we're just testing eso. That's the my index html file. Let's close it and let's rightto access that html file. So I'm using HDP local host and my that? No, girl. Okay, that's the folder location off my project. And now I'm trying to access specific file my index html clicking on that and I get a result. My website. Okay, this is an example off running something on the web server. Let's close that and I'm back to the home page off the web server. Now you can see on the project OK. Your project there is a new one that is called my data Logger. Let's continue to the next configuration is more related toe security Setting patchy is an issue. P seven is configured by placing something that's called directives in a plain text configuration file. We see an example. Now, those directives are actually a set off fools which define how the several should run. Now, one off the default security setting is that the Apache Web server is only accessed by the local host. Okay, meaning it will deny any incoming http request connection form anyone except the local host . Now, you remember at the end we want to connect our bueno toe this web server. So to be able to do that, we need to do some simple, very simple security configurations setting, and let's see how exactly we're doing that. Now let's change those setting those security scenting I'm going into the menu Apache and then clicking over a HDP d virtual lost. Not con going into this specific line, okay and change that it to required all a granted and that's all. Save that file. And now a doing a will be able to access the Web. Seven. The last thing that you need to do toe to make those setting effective, you need to, um, he start all services. So I'm just clicking on that and wait few seconds until I get the green light and that's all. I finish the configuration off the Web server. We created the needed Project folder. Hey, we didn't yet created the files, and that will do that in in later face. But we adjusted the setting on the Web server and we can move forward 30. Step 4 - MySQL Database: in Step one, we connected Senso toe that we know in Step two. We took that doing, you know, and connected it to date and it using that on a model. A Step three was dedicated to set up a simple Web server on our personal computer using the once several free package. Now, a central component in our project is the ability to store the collected sense of information even without a base silver. So step for is all about the my sequel database. We will review some basic definition related to that of base and tables. And then we will create a new that a base instance and new tables, according Toa, our specific project requirement. If you already familiar with my sequel database, then it is going to be a piece of cake for you. And if you're unless for media, don't worry, it is quite easy topic and as always, we will do everything in step by step. So let's start with the quick introduction to database 31. What is a Database ?: our section start with some simple definition, and the 1st 1 is database that the base is basically a logical container for storing data in a very structured way. Now this logical container is a collection off one or more tables that are made up off columns and rows. Each column is one single filled where we can start specific type of data. Okay, like sense. So name, since so type, since a value etcetera. And those are collection off columns where each row is also called the record holding, for example, a specific sense. So reading in specific time interval it is almost the same two dimensional table structure that we are using toe build simple tables in except a single database can contains one or mo tables, so data is stored in tables and tables are stored in that a base. In addition, it database management system, like the my sequel server, can contains one or more databases. Let's see that in a simple visual way, the database system in our case will be the my sequel server. Now, inside the my sequel, a management system, we can create several logical that the base instance and specific that a base instance can hold one or mo tables, which store information in rows and columns. In our project, we will create one single database instance, and then we will create several tables for holding the different sensors data. Now how can we access the data stored in specific table? For that? We're using a special columns called Keys. My sequel is a relational database management system, something that is called RD BMS. It is called relational database because all the data stored into different tables and keys are used to create relation between them and to be able to access the date. The first type off key is called a primary key, and it is one filled or maybe combination off several fields that are uniquely identifies each record in the table now, in some cases, one single field is not sufficient to define one ho, so a component key can be used where the key is actually a combination off multiple columns , and another type off key is used to link between tables. That's the elation that we can create between tables. The tables in my sequel database are accessed using a language called SQL, which sent for structured query language. SQL is used to communicate with the data basing in any Neza wake, and it is the standard language for all relational database management system. It is very easy to learn and use in our project. We will use some very simple SQL a commander statement Toby able to store and access the needed data. If you will visual the process in our project, then we have the Arduino is our small i ot device measuring the outside environment using sensor and collecting the relevant data all maybe a Web client that would like toa access the data being stored in the database server. So that's the main cases we would like to handle in our project. Now, using a simple web AP, I dad, we know or the Whip client will be able to communicate with the Web several using HDP and trigger a relevant script in the server side. The Web seven process Such http request Will van the relevant script Okay, for example, quitting the data or maybe storing data in the database and return html page as the economic content to the work client. Now there are a few steps that are needed before we can achieve that goal, we need to create a new that the base instance a new tables to store the data and decide which SQL statement we would like to one on the database side. 32. MySQL Tools: As you remember, we would like to use the my sequel component that is coming. It's part off the warm silver now to be able to manage and access the data. There are two main options. The 1st 1 is using my sequel, Simple Command Line Windows that provide away toe Enter SQL Command. There's a little bit more complex for beginner, and I always prefer the fast and easy way, so we'll go for the second option. We can use the PHP. My ad mean Web client graphical tools that allow us to do everything an easy way like, for example, creating in your database or delete an existing that the base skates, additional tables, columns, the lead contents, the lit specific, those visual, the data and more if you want. The PHP Mad Men is called that way because it is written in PHP. It's functioning as an administration tools for managing the my sequel server. Now let's open the PHP my had mean tools and start to learn how to use it and create the needed A that the basic tables 33. Using phpMyAdmin Console fix: Okay, so we would like to learn how to use the PHP, my admin tool. So I'm going here to the right side, clicking and opening the icon related to the silver. Ok. You remember this icon should be in a green color indicating the server is on, clicking on that and getting fewer options. One of them, the top link is called PHP my admin, clicking on that will open the PHP my admin console. And the first thing that we need to do is to enter a username and password. Now the default username is root and the password is empty. So you can just click on Go and you will enter into the main administrator, a portal. Okay, so the first thing that we are getting is the main PHP, my admin page, where we can see the database, the information about the database server. Okay. This is a local database and this is the loopback IP of my computer or any computer. And of course we, this is a server type of My SQL and the version. And also information about the web server that is running Apache and PHP extension to the MySQL and so on. And now over here on the left side there is a nice navigation that you can choose. Any database instance that is available in your system right now this is the default database that are related to the installation of MySQL, silver and overview all kind of menu options. One of them is to look on all database available database. That's the list of database in if I will go to the SQL, that's a query windows where I can write a query. Okay, select and write something. Okay. Looking on the status of the web server, handling user account, where you can see that the available users exporting the data. Let say that you have data in, in a collected and stored the database. You would like to stop to export that to all kinds of file format like csv, pdf, or maybe input information into the database. Some setting options that you can play with adjusting the MySQL server. Now let's focus on the things that we need to do for our specific project. Okay, so the first step that we need to do is to create a database instance to our project. So I am going here to the database option. Okay? And I'm going to create a new database. Let's type. A database name. So please follow the exact names that I'm using because this is the name that we are going to use in the script. So it will be easier for you to choose the same name. So the name of the database instance I'm using is just Arduino. Arduino and create the new database. Okay? And now you can see that Arduino is available over the hill, will go again and click on that. We see that there is no tables right now found in the database. And of course we need to create tables. Now before doing that. Now before doing that, it's important to set up some user permission privilege. So for that we'll go into the privilege options. Click on edX user account. Okay, would like to add a new user that we'll be able to access the database, the Arduino database. So on clicking the username and I'm going to use my user and the password will be my password. And I need to type that again, my password. Make sure that this is the checkbox that is being enabled Gandalf privilege on database Arduino. And click on go right over. A new user was created. Now you can see that at the end, the, the PHP, my admin tool, translate the action that you are doing on the web, a client to a specific command, a related to database, okay, like creating a user, my user and all the, all the relevant parameters. Okay, going back to the data base, we have an instance is called Arduino. We created a new user that we'll be able to access data database. Now, the next thing is to create several tables to store the sensor data. The first table that we will create is called DHT A11. Underscore logs, ok for stalling the DHT reading sensor reading and the number of columns that are needed. Three. And click Go. Now I'm getting a screen that I need to set each column, each field in the new table. And this is what we are going to do. The first column that is needed is to store the timestamp of that specific reading. Okay, they say at the end we are reading a temperature and humidity in specific time. So we would like to save that as, as a field in a row. So I will call that column time stamp. And the next one will be. A temperature. And the last one with the big surprise will be called humidity. Now, that's the name of the field and we need to set up the type of those fields. So timestamp, we have a special options that is called timestamp. And we would like to set that, that also. And we would like to set that this column also be used as the primary key of that table. Okay, temperature will be an integer. Okay, that's okay. Integer type codes, that's going to be a number. And humidity is going to be also an integer. So that's okay. The only thing that I would like to change is that a timestamp will be automatically filled, okay. With a default value of the current timestamp. So when a record will be created, okay, using some script that Arduino trigger, it will provide the temperature and the humidity reading. But the MySQL server will save automatically the current time reading. We don't need to supply that specific field. Now when we finish to do all that setting, we can click Save. Okay, great. And now we can see some summary of that, of the structure of the table. Okay, again, we are in the under Arduino. Does the table DHT 11 underscore logs, and now we're looking on the structure. So the first column is called timestamp. The second is temperature when humidity, the timestep is a primary key and there is a default value taking from the database several time. Okay, let's move on into the next one. So I can click Overview, Amanda, the Arduino instance, and I can click new type, the table name. So right now I want a table to store the LDL sensory information, so we'll call it LDR. Others call logs, and I only need two column. The first one will be the timestamp. As always, we would like to store the time. Okay, so I'm choosing the type timestamp and I would like to get the default value, and that's going to be a primary key. And the second one will be the light level. And that's basically a text. Okay, some, some texts. And that's all we can save that I can see a new table called LDR underscore logs. And the structure of that is to field timestamp enlight level. And the first one is the type of a timestamp and that's a primary key. And the second one is just the text. Now the last table is for stalling the ultrasonic sensor waiting. So we'll call it woulda. So 10K. Ok, let's say that I don't have any mistake or sonic underscore logs. And again, I need only two fill. The first one will be time stamp, stalling the time, and it will be a type of timestamp and the default is the current timestamp value. And that's going to be a primary key. And the second field is to hold the distance reading form the ultrasonic sensor, and it is in centimeters. So let's indicate that this distance underscore centimeters, cm, and it will be integer value. And that's all we can save that. And a new table was created, ultrasonic underscore logs to fill time step and the second one, distance, distance centimeters. Okay, so let's summarize what we have until now. So we started with creating a database instance called arduino. And under this database we created three different tables. Dh, T11 underscore logs, LDR underscore logs, and ultrasonic logs. Now those tables are empty, okay, they are still empty. And if you will click on one of them, you will see some query. Okay, we didn't explained yet. They're available a command in SQL. This is what we are going to do in the next chapter. But basically I'm getting that there is no result. The database is empty of course. And now we will learn some basic commands related to SQL and then go back to the PHP, my admin to play little bit with the database in the table. 34. SQL Statements: it is a little bit surprised, but most off the action that we can perform on a database can be done within a very few SQL statement. The 1st 1 is the create command used to create a new database instance, or maybe a new table. We are not going to use it as we led. Used the PHP, my Adminis tool to perform such task for our project. The next command select is probably the most widely used command as it is used to retrieve records, form a table or maybe a combination of table. We will use the select command as part off the website, enabling the Web clients to access the data stored in the database. Insert is usedto add new records to the table, so it will be also used for the several side script we're going to build in our next section related toe PHP. The delete statement is used to delete records in a table update is usedto updates recording a table altar is used to modify existing table structure, and the last commonly used command is dope for deleting a table, or that the base all of those command, I mean the delay tablet altered envelope can be easily replaced by the PHP my had mental. So in our project, we will focus on only the two SQL Command. Select an insert. All the other one will be done using the PHP my head mentor at the end. The whole point off storing information in other base is off course tobe able to retrieve it so the select command can be used to produce a table showing the value off some or all of the records in a table. The following first example using the select command is to simply display the complete content off the table called my table. So we have desk your keywords, elect A. The gastric character is used to get all columns from the my table table and, of course, indicating in the name of the table form the database. And because there is no additional filtering condition, we will get all their coats from the my table table. The next example is when we would like to get only specific field pH record. So the way to do that is just after the select key would we will light down the list off required column. So we here we have cologne one and column too. Again, the form keyword is to indicate the relevant a table. Now the next example is when we would like toa filter some subgroup off the coats from all the records that are available in the table. So for that, we can use the well key would and perform one or maybe few condition using operator, for example. It can be a condition that feel that all records where the temperature measurement okay we're dealing with Senso is between 10 degree to 20. This is quite simple and very useful. And they're all kind off operator that we can use equal, not equal greater than less than greater than week will between some range or using. They like to search for specific pattern in the last one is in to specify multiple possible value for McCollum. The last example I would like to present about the select statement is using the older by key would on enabling us to choose a column or maybe few columns and organize the order off . The result we're getting form the select statement. So we are adding the older by key would and then the relevant cool long. And then at the end we decide the order to be ascending or descending. Okay, that's all about the select statement. Don't worry. We see some example later. Now let's move to the next important statement that we need the insert statement. We need the insert statement to be ableto insert data to the table in our project that we know is going toe run a service side script that will be used to store the sense of reading into the database. Now looking on the sea tax off the insert So it's starting with the SQL Key would inset into following by the destination table name and then at least off the table columns named Destination Okay, would like to put the daytime toe now right after that will use the values SQL Key World following by the least off value, Toby added, based on the order off the columns names. So basically, in our example, value one will go into court along one value to will go into columns to it said Okay, that's the old we need to know about the insert statement. Pretty simple and straightforward, and we are going to use that later 35. Testing our Project Database: In the last two chapter, we created a database called Lord We Know, and we created three tables that were planning to use in a project. And in the last chapter, we actually learned a few SQL statement that now we can use. So for that we are again going to go to the they PHP way. I mean logged into the to and quickly review the table. So that's the name of the database that obeisance, Tan said. We know, and this is the tree tables teach to 11 under school Loves used to stow the DHD sense of reading. And so you have the table for the R and for the ultrasonic. It's sensible now, before we go into SQL. And let's start by using a simple incident, a statement insert into Do we know is that a base in the table tht 11 under school logs? And then I need to mention the destination columns them true and community using the keyword values and some a value that I would like to insert inside. Let's use 20 to 30 tree close that click Go and Nuovo was added. If I will go into the DHT 11 under school look stable now automatically. When I'm clicking on that, it's actually running a select statement to see the whole goes in that specific table. And now I can see a new ho just was headed with the temperature value 22 in humidity. 30 tree. So these the first options to insert data? The next option is to go into the inset option where I can see the columns, time, stem temperature, humidity and I can enter that right over here. That's 6 66 and 77. Please go. And it's translate that into an insert, a statement. And now just a reminder. The timestamp is something that we don't need to insert a manually. We are using some options toe Generate that from the current time stamp. Every time we're reading in you ho, it will get the current time stamp from the server. And if I will go again into the tht 11 tables now, I can see a new just was headed right over here. Let's do the same for the other tables. They'll they are logs off clicking over here, going to insert, and I'm going to insert some text. You can go. Okay, it's automatically translate that into an insight into LD R logs a time stamp in light level. And that's the value current time step in the text that I just entered. The if I click on Dell, the our logs, I can see that is a new ho right over here. Now, let's do the same to the ultrasonic logs I am going to insert over here. I need to type some distance. 32 clicking gold trust only gloves. And I can see that is a new column. Okay, so basically, this is a simple testing just to see that you can enter data into the tables. And now, because this is a day me data, what I suggest to do is go into the Do we know that a base? And this is the list of tables. So just right over there, we can empty each one off them, clicking on empty. Actually, I can do that for the whole free by clicking over there. But that's okay. Now the whole three tables are empty, okay? And we can move on into the next faith 36. Step 5 - PHP - Running Scripts at the Server: in our last step meaning step, for we learned how to configure the my sequel database server, using the PHP My had Minto and we led created the albarino that the base instance and few tables for stowing the sense of data. I also presented the two main SQL commands that we need to use, select and insert. Now. Maybe you asked yourself doing section for which component in our project is actually going to run Those SQL statement on top off the database is at the end. We would like that the whole process will be fully automated. Well, this is the point where we need PHP toe provide us a way to run skipped at the several site in this section. Step five, we will lead the last needed peace on our puzzle. We will end what is PHP, how it is working with the other component in our project and also covering some PHP syntax . Now we're not planning Toby, a PHP expert, but still we need the basic syntax enabling us to write simple script for our project. So don't worry so much. If you don't have any PHP background, we will cover what is needed for the project. So let's start with some basic background about PHP 37. What is PHP ?: we'll all be so that one of the main component in the Wamp server package is PHP, and it is basically a plugging for the Apache serval and I billing toe one PHP script Pitch B stand for PHP. Hypertext people says. So I think it's a little bit strange that to use PHP inside the description off, what is the meaning off the PHP world? But anyway, at the basic level, it is a several side scripting language for Web site enabling to provide a dynamic webpage . The important thing to remember is that the PHP could maybe embedded into HTML code, and this is the way we're going to use it now. The first took it may seems a little bit strange. Okay, meaning to combine HTML and PHP. But this is the way PHP silver side script are walking to generate dynamic webpage. Looking on this simple process flow we so before, on the right side a Web browser or maybe an Iot device like they are doing, you know, okay, that were bleeding. That came. Issue in htp requests toe a web server. Now inside, this HDP request will be embedded. The final aim off the specific PHP script Toby run On the server side, the Web server would process the HDP request. And because it is a PHP enable server, it can also process a peach because we need to remember that PHP is a server side language , which means that the actual script in PHP are located on the server hosting the weapons. Now, if we complete the process, the Web several create the dynamic edge to be HTML page, and then send that that as HTML responds to the Web client now what kind of things can be done on their silver side while running a PHP script? Well, many things, but we are interested in the options to connect to a database server. So let's take the website okay, with all the component that we saw until now and connected to a database using that the base seven. Okay. In our case, it will be the my sequel that the base ever. Now, please note that it doesn't matter if all servants side component are ready, and sitting on the same computer is in our case, we're using their Wamp server package. So again, the Web Several poor says http request run the 11 script. Any federal return HTML page is content the PHP script of being used. Toe issue SQL statement to the database application, enabling us to connect, read and write data to the database. You know where the next chapter we would start learned the basic PHP see text used to develop the needed script in our project. 38. Basic PHP Syntax: Toby. Able to use PHP, we need to begin with basic syntax and functionality. A PHP file normally contains HTML tags. And of course, some PHP skipped Include where the default file extension for PHP files is ending with dot PHP. As you see right now, my script dot PHP, for example, the following block off court is a standard HTML document with PHP code embedded inside. The first thing we can see is that the PHP script start with special opening a PHP tag and ending with the closing PHP Tuck this what we've seen, rip any code in a PHP script that is not enclosed by those special PHP tags is assumed Toby html. Now, something very important to remember is that the PHP block off court can be placed anywhere in html document. Okay, we can educate several block off PHP code placed in multiple place in the HTML document. Now each PHP statement and we semicolon that like like the C plus plus language we use in our do. We know we can also write comments in the same way as we are doing in our doing a court, meaning it can be a single line comment or multi details. Multi lines comment block. Like any programming language valuables are containing for storing data. Valuable declaration. PHP. Start with the dollar sign, followed by the name of the Valuable. Now I like the way we declare valuable in Arduino in PHP. There is no need to specify the specific valuable type. Okay, Like straying into jer and so on. PHP will automatically convert the valuable toe the correct data type, depending on the valuable placing inside available name must start with a letter or underscore character and cannot start with a number impeach be all keywords. Okay, like while if else settle that we learn later function, building function or maybe user defined functions are not case sensitive. However, all valuable names are case sensitive. The next topic is about walking with string valuable, something that is very important in our PHP script. We are planning to develop. It went, assigning a text value to a string viable. We need to put quotes or conduct double quotes around the text value, and the next thing is concatenation off street. Valuable is very useful, and the easy way to do it is by using the string or potato period, for example, If I will try to concoct donate The crazy world is a text we text One is valuable in another Texted the end level three Okay, you see, the all all the free elements are combined with appeared operator Okay, something that is very useful in PHP. Valuables can be declared anywhere inside the script. The scope off the valuable is the part of the script. Well, the valuable can be used now. PHP has three different valuable scope local, global and static. In addition, several pre defined valuable in PHP something that is called super global, which means that they are always accessible. He got list off the scope, OK, it can be in outside the function inside the function and so one. Now, this is the least off the PHP super global valuable. But we are interested in only one off them. And this is the underscore. Get super global valuable. PH B and other school get super global valuable can be used to collect form data after submitting an HTML form with the method, get all data that is sent inside the U. N. It is the way that we were planning to use that What you see right now in green cooler is super important. This is the way toe access a perimeter past in a You are a link inside the PHP code. So I will do, you know, is going to submit and extra p request using the get method and inside the your bill that it will submit will be the sense of leading the PHP script. Willie lead that value using this built invaluable. Okay, they underscored, Get super global valuable and pass it to the database. As you remember, the PHP could is used for several side script running on the silver okay, and HTML is used to display content in the Web client side to be able to generate dynamic HTML code using PHP, we need a way to output data, and for that purpose, we can use the echo statement enabling toe output, text numbers and viable that can also contain HTML markup. In addition, we can combine several viable using the string Oprah Vato period that we saw before usedto concur tonight's thing. So in this example, this that's an echo statement and the first is some text and combined with valuable called query adding some HTML tags used for way vacating a new line and also combined wits with an information that is being returned form some function. These are very common statement that we were planning to use in our A PHP script. It's part off our project scripts that were planning to develop. We will see later. It is needed to read a table from the database using some SQL query and then go, oh, by low until the end of the table. So in that case, why loop is the perfect method to loop through each own off data in some queer result and performing the 11 task pair each. Oh, and of course, the testing condition will be if there are still those to scan Oh, we reach the end off the result function very useful. Also, any PHP and PHP has more than 1000 built in function. Okay, that can be very useful and can save us valuable time will develop a complex script. So I always commend to search the a little bit the Internet looking for the PHP building function before trying to develop a function by yourself a, for example, the echo statement. We saw before is actually a built in function. It's part of the extensive list off PHP, a function dealing with string in our project. We need to interface with database and for that their specific my sequel function that we will learn how to use. In addition to the built in function, we can create user defined function. In our case, there is a block off court that we're using again and again in all script. So it's better to build a function for that repeated court. And in the future, when we would like to change something, it will be much easier to handle now to declare a function. We used the key word function function names are not case sensitive. That's something to remember. We are going to use the same customized function in several script files. So for that we will use statement. That is gold. Include, Okay, we'll see that, of course later. The last thing I would like to mention in this chapter is related to launching a PHP skipped former u l. So starting with http a request and then a website of I p o host name in our case, it will always be local host, followed by the Project folder name we created. If you remember my daughter Logan, and at the end escaped filing. We would like toa Now, if the PHP script is getting Parliament is using the get method, then the U Early's including that data inside. So here we have p one equal to value one and P two equal to value too. Okay. And this is the way we are going to bus send. So, data that's all related to the basic PHP syntax. Now we're going to learn the built in functions related to the communication with my A square. 39. PHP Extension to MySQL: so far, we covered some basic page piece in tax. And now I would like to focus on the connection to the My Skrill that the base the good news is that we don't need to develop any complex function for that connection. We're going to use the new PHP extension to my Skrill called PHP My scary ally. That stands for PHP. My SQL improved. Please note that there was in all the version off PHP extension toe my school and the improved world Okay, they improved is used to distinguish between them. And of course, I would like to use the newest one the my SQL I extension Allow us to access the functionality provided by my SQL server version 4.1 and above. We can easily access the my skill that obey syllable while using a cream main PHP function . My SQL connect is used to establish a connection toe specific that the base Okay, we're using some may parameters. The next one is my skill. I query for sending an SQL query for storing or retrieving later. And the last one my school I closed four closing the connection with specific database. Now you can also review the official PHP the communication for additional information. And let's do that for a second. But we will cover the main things that are needed in the following chapters. As I said, you can also use the PHP official site using this link. OK, it's not the must. We're going to cover the needed A information in the following chapter, but anyway, inside the documentation top the all kind off information. For example, some nice overview off the software available related to my school from the PHP using this link, and that's what you are going to get. Same. Some nice overview off the A p I between the beach being the my SQL What is the extension and what are the options for pH. B A p I to the my scale? Actually, there are three main AP I options. The 1st 1 is to use the older version, my school extension and the second option that we're going to use the my skill. I improved extension. Okay, that's the newest one and the last one that provide the same functionality that we're not going to uses. PHP that object and you can see some small remark right. Overly. If you're using my school vision 4.14 point three or later it is strongly recommend that you use the nearest one. The my school I extension instant off the older one. Now, if you will go back to the main screen under the commendation for the introduction to the my skills, I then right over here we can click or and the my school extension function summary. And this what? We're going to get a nice summary off the function that we can use. Okay, that's a long list. And if we take cares, an example em one of the function that we're going to use my school connect okay, that is used open in your connection to the MySQL server. If we will, we will open that again. We'll get additional explanation. But if the description off this function and an example how we can use that in a PHP a cord and some contribution knows formal, kind off users. So there's something that we can do to other function. As an example. This is a my SQL under school, where he function that is used to perform a query on the database, something that we're going to use also and what are the parameters that are being used and at the end, some example how to use that? OK, that's basically something that can be used if you would like to get more information and now let's start toe, learn how to use those function in the PHP script that we need to develop in our project. 40. mysqli - Establish Database Connection: before any PHP script can perform in action on the my skill database, it must first hold something that is gold connection to that database. So starting with the mice que el I connect function that is used to establish a connection to specific database instance that exists in the my school server. Now there are few para meters that are needed for creating a connection. Okay, the 1st 1 is a my SQL server location. That can be an I p r. This so you are really as host name in our case, it's going to be a You are a local host because the my skill servant is running on the same host as the whips of a pact under the Wamp server. Next one is that the base user name and password. Okay, for the user we created doing the Mice sequel configuration. And, of course, that the base name in our case is going to be the yard. We know that the base instance now the result off calling the function okay, they my skill, I underscore connect function is a reference to the database connection and we place it in a viable called a D billing that now can be used to interact with that. The base meaning runnings. SQL statement. Just if we were entering them manually in the PHP, my had mean a tool. So this is the first PHP escaped. We will use. Okay, Please go ahead and download the file. Form this specific chapter. It is gold db connect a dot PHP. Every PHP code is starting with those open and close a tugs inside, we have a function called connection with four valuable holding the power mentors that are needed to establish the connection. Meaning the several name, user name password in the database. Instance Name next toe, actually, k. The connection we are using the my SQL I underscore connect function with the four perimeters and the return value will be a reference for the relevant that the base instance . Now let's ignore at the moment what will happen if something went long. As I have dedicated chapter for something that's called over handling, it will be discussed later. Eso the last line is to actually retain. They knew that the base ling So this function okay, connection will be called by other script before making a query to the database 41. Insert New Data: The next function we would like to use is the my school. I underscore Query that is used to send SQL Query toe the database ever now before running dysfunction, it is recommended to create a string viable that will hold the full SQL statement were planning toe one. It will make our court much more organized is ask your statement. I just sometimes very long looking on the following esque Will query insert into is the key word in SQL toe. Insert new records. Okay, we saw that before, followed by the destination table. In this case, the HD 11 under school Looks OK. As you remember this a table that we created in my skill and two columns We would like toa insert data. Okay. Meaning temperature and humidity. Now, right after that, the values key would is followed by the values we would like toa insert into the relevant columns. Okay, temperature and humidity. What you see in red Kahlo's? Okay. Meaning the dollar under school gets and sense of one. It is a little bit strange, but this is coming from the global A very valuable called dollar under school get And this global ray actually holds the parameters passed by the HDP get request, and this is the way to deliver the values formed out, doing no using the get request via their PHP script into the relevant table in the breast. The last step, of course, is to want the my skill. I underscore query with the two needed Calumet er's meaning that the base connection reference that was already established before and the really want needed SQL query using the query string we created. Now let's see the three PHP files that will help us toe fully automate the process off, adding new data from the Arduino. Please go ahead and download this PHP script file from this chapter. It is called Ed underscored, aged 11 dot PHP. As a reminder, all the PHP files that you're going to download should be located inside the mind that a Logan folder we created in the Web server Okay, that's important again every pH because it's starting with those open and close Doug's. The first thing we're doing is to include the DB connect dot PHP files that we just saw before, so we'll be ableto call the Function connection and place the database connection result in the D billing viable Next, Will it be sold the query viable with the long esque? Your statement is drink, and right after that there is a short block off court to handle l. It would discuss later, and the last line is for closing the database connection. My school I under school clothes function it, since we are really interested in executing a single insert query now the same as we created a PHP escape toe. Add a new record for the DHT 11 cents. So we're going to do the same for every sensor, every sensible type. And the next one is the LDL sense. So it another based connection is the same. So the 1st 2 lines are identical toe the previous script. The query is the only things we need to adjust here. The destination table will be LD are under school logs, and the corns will be, in this case, light living. And that's all. Okay, please don't forget to download this file also and and also the next one and place it in the Web server. I will last PHP script usedto incident data for the ultrasonic sensible here. The destination table will be ultrasonic underscore logs and the column will be the stuns under school. It see him to keep everything simple. The PHP file name will be called Ed underscored trust sonic dot PHP as we done before, if in the future you will want to a new sense of types than just create additional script, as we have done right here, let's perform testing for those script. 42. Insert Data PHP Scripts Testing: Okay, so we created a three a script that are being used toe insert data to the database ball. Each sensible type. As you remember, We have the end underscored DHT 11 ed underscore on underscore L D E r. And the last one ed underscored ultrasonic. And also a some script that is being used to connect to the other based something that we call DB connect. Okay, all of them are PHP files. Now, the first thing that we need to make sure is to place all those four files on the might. Data low, give full deal. Okay. In our will, one server. Okay, Because we would like to be able to access those script. Let's quickly open those gripped they be connect it them ed DHT 11 Add LDL and ultrasonic. Okay, so we have the full script as fires. The 1st 1 db connect being used to connect to the Taliban that the base with the parliament er's is the server name. Now again because I were Web server and the my skills server actually running on the same computer on our computer so we can use the server name is local, lost a user name and password is we created in the MySQL database and that the base instance I'll do we know we created before and of course, skating the connection and returned that to the skip that was calling dysfunction the function connection. So as an example, it's open the ed L. D h 2 11 So here I'm including the previous skip the DP connect PHP. And then I can call this function connection and get the difference today that the base a built their needed query toe insert the data. Okay, The reminder the value are actually getting from the global very valuable. That is called AM under school. Get. And this is the way to transfer him. Http request using the get request to the PHP escaped and then into the database. And the next thing line off court is toe a query to send that a query to the database and check if the new record was successfully added and if not display some Evo and, of course, closed a database. And this is true for all the other Skip Just a different A query based on the destination. A relevant table. Now let's do the actual testing toe test those script one by one. Toby ableto test the script. Okay, on the server itself, we need to make sure that the one server is running in the background. Okay, you can see the game light. So, Disick indication the 17 is running and I can use it. So what will open is some bozo, okay? And then type. It's to be local lost and the destination my daughter Logan. And then I'm choosing specific script file age at the DHD 11 dot PHP, and then I'm gonna I'm using them. Way to send a get request, using a question mark and following by few valuables, like since So one is equal to 100. And since so two is equal toe 200. And then the only thing I need to do is just click on that. So this is a way to menu early test the script, and I'm getting some AM resort connected successfully to the database. New record created successfully. Okay, so I would like to verify that, of course. So I'm going back to the swamps of menu clicking on the PHP. My had mean we didn't enter any passports. I'm just clicking Go going into their doing. No instance. I have the relevant tables and I'm going to open the DHD a live in logs. And now I can see a new line. A temperature 102 100. Okay, is away. Let's do another test. Okay? With another value. Okay, let's change Change the value for a second. Okay? On that again, go back and quitting that again. Okay, I can see another line just entered into this to the table. OK, that's a simple testing to see that the skip that you created is actually walking. And this is true for there's something that we need to do for all the other A script. Okay, for the LDL escaped and the ultrasonic and script. So let's do that quickly. Go back and change the destination script. I would like the LDL. Okay. And over their descent, the the actual value it this is just a single value. Some text, let's and white. Okay. For example, click. I'm getting connected successfully to the database. New record was a created successfully again jumping into the and which we might mean go to the relevant table. LD R log. Okay, just inside right now. Right? Okay. And let's do another one, Dame and, uh, and the fresh. OK, but if it's working perfectly, let's do the same for the ultrasonic. So, Nick and over there, I need to provide these stones. So let's say 33 and great. I'm not getting any aero. Ultrasonic look. Territory perfect. Okay, so the insert script walking and I can see the data being in being a edit into the database . So when we will actually run those grip form the odd we know for gum, we know that we done. It's the needed debugging for making sure the script actually walking. 43. Query Data: until now we saw the script being used toe insert data to the other base. Now, what about reading the data? Using the select Command is part off some. It's your statement for that purpose. We can use a function called my school. I underscore query to submit the needed SQL as we so before using the insert a statement. Now, in this case, this trail statement is not usedto insert one off data it is used to read Won ho Oh, manuals Just after the query is executed. Okay, Using this function, we can get a result table and place it inside some valuable Okay, for example, called result. The next step will be to fetch each row at a time from this temporaries old table. And for that, we can use another function that is gold. My SQL I underscore fetch association function. Now each off data will be stored in a new is a valuable name. Whoa! Each time will run dysfunction. We'll get single and will store it in this valuable. Now let's see the actual script. This PHP script file is gold review. Under school data underscored the HD 11 dot PHP. You can download off course this file from the chapter that we are right now and place it in the Web server as we saw before for other script. Now the first line are straightforward dealing with getting database connection and then defined the SQL statement. Of course, he would like to equate the DHD 11 a log stable and order the result by the event entry time. Next will be to run the query and check for any arrows. From this point, me, we move from PHP toe basic HTML. As you remember, this is the power off pH. Pete can be embedded inside html code and the 1st 2 lines are just displaying some text title for the result table that we're going to present moving to the next a code really 11 toe this PHP file. So we keep continue read html court, for example, Defining a table structure with subtitle. BEVERAGE column Okay, like the time start staying temperature and humidity. This is basic html coding and then something a little bit strange jumping back into additional PHP code. This block off court is used to read all those and generate something that is called dynamic HTML code. The first step is to retrieve all those toe the resort viable and then use a while loop for looping through all their coats. In this result, able and then Fitch, it won ho at a time from the result table. Okay, using this dysfunction and then generate html code with the content off the Colin toes again, this is the magic off combining page managed em. El html again is just a simple markup language that our browser is getting a simple text and then once lay that on the fly toe the weapons that we can see PHP here enables to read their quotes from the database and dynamically generate HTML lines within baited the codes data with each iteration in the loop function. The next off information from the query result is being fetched. If today valuable, that is called Oh, okay. This process will continue until the no morals that are found in the result. And of course, the last step will be to close the database connection 44. Query Data PHP Scripts Testing: Okay, so we would like to review a the skipped elected to quitting the data. So the final name is a view under school. Date down the school DHT 11. Okay, it's not the finals script file. Just another step. Eso will be able to develop a final escape to be able to see all the sensor. But right now, I'm concentrating on Onley once and so the DHT level. Let's double click on that and see the skipped itself. So again, starting with including the A d B connection and calling the connection function and then building the relevant script. Okay, using select checking, quitting the data and checking if everything is OK. Now if we go below, I'm starting the to see the court related twitch, Tamil. Okay, because we discussed that HTML and PHP can be in better together. So the first line is to print a doing, you know, sensible daytime that the temperature and humidity reading and using some talks to create tables A in HTML and that's the dye tells time stamps, temperature and humidity. And if it will go below, that's the actual block off court that is being used. Toe a fetch each row at the time and to see the another low in the table. OK? And I mean generating a dynamic html tobe able to see each row in the table, and it's walking pretty simple. That is a function toe to see the number off walls. If it's more than zero come, it's not an empty result. And then I'm looking using the while loop getting single low. Using the my school, I fetch a sauce and then printing. Okay, that's the lines that are actually generating the dynamic HTML content. Creating those tags, inserting inside a actual data from the specific Oh, the time right now. And when it's ending, I'm closing the other base, and that's all. Now, let's see this actual script over the website. To be able to run the script, we need to make sure again that the one server is running. We can see that is an icon over here in the green light, and then I can go into the browser and DYP. Http. Look, I lost my daughter logo and then I used that name. If you data a d h d 11 that's the name of the Escape. No power metals off course are needed. Clicking on that and you're getting some debugging lines that we can remove later. The connection was successfully to that a base week. We I mean, we could read all the codes from the stable, and that's the two titles are doing essential data. And this is the subtitle. Temperature and humidity reading. And we only have two lines in that a base. And this is why I can see the two lines right over here. Okay, so that's a a way to, of course, to check that those that script is a walking and of course, we'll take it and develop that a little bit more Toby ableto present all other sensible data from the two additional tables. 45. MySQL Error Handling: The last thing I would like to mention is about Evros en dealing while walking with my sequel. Evals are almost unavoidable, as in some point of time you will encounter a situation that your script is not really walking and will require some level off debugging toe. Understand? The problem would cause now there are few Koeman elbows that that we may encounters, like failure to connect with at the base in the My Skrill server or failure to run a query . Or maybe no results are being returned by a query, meaning it is empty when the table in the data base is not really him. Oh, maybe an Evel, while trying to insert daytime to a table and maybe more. The 1st 2 cases are probably the places we should put our focal, so let's understand what can be done here. We have seen that before, probably the best method for handling the my sequel. Ellos is toe print the els immediately doing the run time off the script. Basically, it is the same simple method that we are using, you know, doing a programs where we are heading debugging lines that are pointing messages to the sale monitoring windows. So the first case is failure to connect to the database and it's part off the PHP my sequel function. We can use the dedicate set off function dealing with bows, and one of them is called my SQL. I underscore Connect under school. L know Dysfunction will return a text description off the Evel that my sequel server returned doing a connection attempt. In addition, we will use it The dye function okay to terminates a PHP script if something went wrong, Okay. For example, that obey server can be reached. Or maybe we provided long user name or password, etcetera. In that case, that die function will stop the rest of the PHP script form running and show the aero message provided here, combined with the string description coming from the my SQL I underscore connect on the school l function. The second very common aero is a fail toe. One a specific SQL query on the database server. Now, when we learn the my SQL, I underscore query. This function will retain force if there was an l. Okay, so we can put that in an if condition and then we can print an elbow message. Okay with the query details. Okay. In the description off the l using them my SQL I underscore l function. And if there was a success off running the disk, wary off course, using this condition will get the message. New record created successfully. And that's great. Now, still, if there is some problem, there is additional things that we can do and it is basically test the query manually. We will explain the concept, assuming that the valuable query present now the complete SQL Command including the values off the PHP valuable coming from the get request. So if you will bring it, it will leave ill tow us the actual current SQL statement being run by the script. So the next step will be toe take the printed query and execute that manually using the PHP my had mental and see the result. Now let's perform a simple Eros demonstration or simulation to see the two main cases 46. MySQL Error Handling Testing: The last thing I would like to cover is, of course, to simulate some ill that may encounter and while developing and crying in testing those a PHP script. So let's simulate something to see how the system behave in such scenario. So the first thing that we will do is to simulate, and they're all related to connecting to the database. And for that will open the db connect PHP file, looking on the parameters. And let's as an example, type a long user name. Okay, so? Well, Ed and they let the one at the end of the user name save it. And now we're going today. Well, was it it should be local lost. And let's run that specific script. Okay? Of course I'm getting Evo. We can see the road that I generate. Any my coat connection failed. Access denied for user. My user one into the local lost. Okay, that's an example. Off permission problem for trying to access the database. And if I will fix that, okay. And try again. Okay. Everything is walking. Let's simulate another problem related toe the disconnection. So again, I'm going to go to the a db connect PHP script and let's change their silver name. Okay, Put something wrong. Okay? Save that. Let's see the result. Now, off course again. I'm getting connection failed, but I'm getting a different type off ever. Okay. You remember that We use some function to display they all that we're getting from the my school database. So here I have PHP network get address Problem. A. No such host is No. If we fix that again, clicking on that everything is OK. The next very common aero related to Wendling that the base is a problem with the SQL statement itself. So, as an example, it's open one off the script related toque wearing the data, the review and the school data underscored aged 11 the Bilkey conduct. And let's change their query. Okay, this line And put something something wrong. Okay, I will put in the table that is not exist. Who can save that? Let's see the result while trying toe that script. Okay, so I'm getting a good message that the connection was successful. Toe that the base, but just ICT After that, I'm getting in a row message. And that's the select statement that the PHP script tried toe run on the database, and that's the table. I'm tryingto access. Do we know is the database instance? Don't DHD 11 underscore Logs want to Dre doesn't exist. Okay, so that's a great way to quickly find a kind of problems when you're printing details. And the last thing I would like to show you is related to a problem while trying toe. Insert a new recording toe some table. So let's simulate something related. For example, toe descript aid underscored aged 11. Again, I'm opening the browser and let's find some previous example that they used. And now let's change one of the parliament ALS. Okay, I will enter some string. OK, that's put some text, and I'm trying to run that for that specific beach. Be script. Now again, Does it get method that we are trying toe send so again a connected successfully database. But I'm getting a narrow and I'm displaying they I am SQL statement the dynamic. Ask your statement that was used. So insert into the HD 11 on the school logs, temperature, humidity and the values. Now the values that I'm seeing over here are actually coming is a perimeter from the get request. Okay, You see the deem and that it won 22 for the 2nd 1 Okay. And I'm getting some additional information. Incorrect integer value deem for the column temperature that no one. Now, this is pretty clear. The poor blame. I'm trying to insert the wrong type of data, but if you're not true about their roles and you would like to simulate that so we'll go to the beach, be my hand me tools right over here. Okay. And then to the SQL option and type some obscure. So the day schools that would like to type is the message that we got over there. We copy that, and he said that here now because, um, we are in the PHP, my Skrill. We need to mention which that the base we would like to query. So mating of, Do we know okay before that and dance the table inside out. We know, and that's all I can clear. Go and off course, I'm expecting to get a narrow so incorrect into jail value deem for colon tempeh. Trato one. Now, that's an area that we saw over here. Okay? But I'm saying if you're not sure why It's not walking and maybe did go there or something that is not declared. Try to copy that and incident in a here and maybe start to play with the data, trying all kinds of things to see what is actually walking. Okay, now it's works, and we can continue. Okay, So basically, this is the main cases that you will encounter. And, of course, if you have any other ho Phil, Frito, ask me question in the UDP site. Okay, We are ready to move on into the next section when we are going to combine all the things together as one Internet off things system. 47. Step 6 - Final Project - Web-based Datalogger: Hi and welcome toe. Final step. Step six It was a long journey and I hope that you enjoyed in the full of the steps s so far. We learned the building blocks off our project creating the endpoint Internet off things device without, we know, connected to some sensor using that and add models toe connected to our local network. And later we installed the wants of a package. When I will computer configured the mice equal that the base in created few service side script which PHP In addition, we tested that each piece is walking as expected, but it is still separated. It is not a complete solution. So Step six is our final step. You. Now we're ready toe. Combine everything into one system, creating a will end to end Web based data, Logan. And that's what we are trying to do next. 48. Connecting the Arduino to the Web Server: if you remember in section three, meaning step to you know, project. We got to the point where the Adonal is connected to the Internet using the aeterna chilled , and we have done some simple HDP testing with external Web server like the Google website. Now we have our will own Web seven up and running configured, and it is time to connect the dono to our own Web server, as the do we know is acting as a Web client that is responsible for starting the communication with with the Web server, the only things that we need to do is to perform adjustment to the Arduino sketch. So let's review the final sketch could, including everything related to the Queen or reading Senso, making network connection and sending data by running the relevant serval side script. Okay, so we are looking right now on the final sketch that I'm using to run this project. The final aim is called Step six Web, that Logan and is the file that you can download from this chapter. So go ahead and let's start toe a review. The code that I'm using here, starting with including the relevant libraries So we're using the DHD that H libraries also date on it and then gave all kinds of valuable declaration related toe the LDS. And so the DHT sensor with the ultrasonic sensor each one off them with some valuable that we need to operate descent. So and then we have three indicator led that I'm using to visual what is happening on the brain. Oh, itself okay. And the 1st 1 is the event led that is being used to indicate if there is some sensor event like distance that was crossed or maybe some light change. The next one is HDP led to indicate that there is now in HDP communication between the Arduino and the web. Several and the last one ever led that is being used toe indicate that a some system l okay , and then you can troubleshoot it will understand more maybe using, say, Armani, towing windows to see what exactly is the problem moving Next? We have some valuable related to the Internet. An I p communication. The 1st 1 is the 1st 1 Is the mark address? Probably you can use this value but the valuable that you need to adjust Is this one the Web server. I p Okay, at the end, Although we know needs to know the destination. I p off the web server now, assuming that you installed the one server on your computer is I'm doing right now. Okay, The one package is in my computer. I need to check my current i p address and write it just over you. And then there is a line to initiate that. Turn it client using this ley line, and then we're going into the set up function. That first line is to initialize the serial a communication setting a digital beans mode. I mean, in puto output, perform some short led tests. Okay, We are turning all the tree led for some a 12th and and also letting the DHD sometimes to initialize That's the delay and a 10 off the led Get the current LDL sensor reading, so we will have some baseline toe compare if there is a change. That's the LDL last. And then we are starting the internet. Come in connection with the A c p i p. Location. Meaning dynamic. I be And this is the way to get dynamic. I p using this function and assuming that everything is OK, we're getting an I P and then we are treating the allocated. I'd be right over here moving to their look function. So the look function I like to look function, Toby Simple as possible. So what I have done is grated. They remain a function and the 1st 1 is to check the LD R status. The next one is to check the DHC sensor starters, and the last one is to check the ultrasonic sensor and then doing some delay. Okay, between those really something that you could also adjust and then 10 off the event led if if it was held on by some off the function right over here. Now getting into the LDL sensor function there to fund function, the 1st 1 is to check LDL. That's the main function that is actually using an additional function that is called gets and so light. Okay, we saw all those. All that 11 could I am. But what is special here? I mean, what is new is that this this block off court, What we are doing is that sending an event look to the Web server Toby stored in the database and the way we are doing that is creating in some string that is called central data, since the one combined that with the NDR Colin reading they also for debugging and creating that into the screen. But this is the interesting function HDP request. Now it's getting is a Parliament dio and you are in now the U. N. That you see right now is get method with the destination a script that I would like to one . As you remember, we located the script in the server side in a fuller is called My Daughter logo and that's the script toe. Add the new record related to Will the r ed under school. They are that PHP and this is the way to send that as a Parliament hill using the gets method And the last thing that we need to indicates is usually get request is the vegetable HDP version eso We are reading that at the end off the request Now we are doing almost the same for all other Cecil. I mean, this is the address on extensive function. If I will go, we have the check ultrasonic And if there is some, if there is a distance that was crossed inside on building the central data string first. Okay, getting the distance and then sending that is htp requests, but I'm using different script. It understood ultrasonic and sending the relevant parliament. Let's go to the DHD, so the DHD is a little bit more complicated because we have to valuables. So the sensor data is a combination off sensor one equal toe and the temperature has a string and using an upper sent to combine another value sensor two with the value of the humidity. And then we are sending that over real and using a different skipped ed underscored the HD live in that PHP if we take a look on the HDP request function, I mean, this is where we're calling that function, and that's the function itself. HTP requests it's getting as string they request. Okay, the u L. And over here we saw the way that we're connecting to the Web server using both 80 and they'll on the HDP lead indicating that we are just opening a communication with the Web server and all those lines are related for debunking. You can remove them later but this is the actual important call. OK, well, here we are printing that to the client Dr Will get request and also for debugging. I have another function that can display the HDP response from the server and at the end, if it's if the connection is ended, we are stopping their client and off the HDP I am let the HDP indicator lead, and below we have them function that is college dippy, expose toe display, the response from the seventies more used for debugging. And that's the sketch and it went now, before seeing the project in action, there few steps that we need to do and, let's say review them quickly. 49. Final Project Checklist and Demo: there are a few simple steps or checklists that are needed to be able to bring up the system, starting with verifying that all needed PHP script that I provided are placed in their Web server, then learning the Wamp sever in the background, checking that we get game call of meaningful. Several services are walking and waiting for new http request. Next will be to connect. They do, you know, with Internet cable to your land meaning to your home router They're connected are doing or using USB cable to provide power off course and to be ableto upload the sketch. The next remark is a little bit tricky, and you can miss that easily. You need to check the current I p others off the host computer. Well, the Wamp server application is located as probably it is changing all the time. When you wister the computer, OK, in my case, the one server is located in my computer. And when I'm doing a restart, a probably getting a new I P address for my louder. So I need to check the current. I'd be address. Next will be toe upload the final sketch program okay called Step six web that are Low girl , as we saw in the previous chapter. Then take the others that you just checked the i P address off your computer and update their doing a code with this i p So you are. So you know, we know what is the destination off the Web server? An ideal, of course. Upload the sketch. Let's verify the checklist together. So the fisting I'm going into the swamps ever here. I can see that the warm server is running. Okay, consider green Light. Next we click on that and go into the W W w direct away. OK, that's the main Web. Sever the director way. And over there there should be a directory. That is good. My daughter Logan. Before we click on that, I need to verify that I have the four relevant script ed underscored DHT 11 at underscoring the AL head underscore ultrasonic and the DB connect. That's the full skipped. I need to verify anything that placed right now in my data Logger. Next, I will go and check my kind I p address. I can use use I p config. Okay, I can see this is my I be on this, and I need to verify that this is updated in the Arduino sketch. I'm opening the sketch. Step six, Web data logger. That's our final sketch. And below I'm looking for this line. A Web seven. I'd be. And I'm making sure that this is the I P. Address that I'm seeing right now in my computer. Okay, so that's OK. And we can move on into the Arduino side and upload this sketch. Okay? The first thing that will do is to verify that the sketches. Okay, I think you can verify. And we're getting that sketches. Okay? And now we are ready to upload a sketch clicking on upload. Great. Okay, so we're getting the three led for that. Second is testing, and then after 12th the system will be ready and start taking measurement. Okay, Let's see how the project beer we have the LDL Senso in the distance. And so if I will start with the distance and so Okay, I will hold my hand. Okay. Now I can see an event that was tree girl. A way to see an event as a minder is using the blue polo right after that immediately we can see the yellow Coehlo indicating and the event is being sent into their Web server. Let's do that again and again. So that's is like a tree vent. Yeah, we are getting now. There is a Web communication because the temperature new munity are being checked every 62nd everyone minutes. Now let's do something similar with the idea we close the light in the room for a second. Let's bring your door. Okay, this is another event. So it actually that's two event. Maybe we'll do that again to get some additional event. Great. Now this is the thing that we saw before a. But right now it's connected to the Web server and the Web service connected to the outer base. I'm expecting to see new lines in the that, obviously, and let's see that together. Okay, so now we're going into the database to the PHP might mean tool logging. And then let's give you the table so far on the Arduino. So let's start from the ER logs is an example, and I can see several and oh, being a created because we have done, we turned on and off the light So you see that they, like, change from bite very bright and then toe dark, very bite bright and dark and again again. And if I will go into the ultrasonic loves, then I have three measurement because we have done that three times. And if it will go into the DHT logs, okay, they are doing, you know, is measuring record every 60 seconds. So it's keep keep coming and to the database. Now, it will be nice to see that almost in real time. So, as an example, I will go into the ultrasonic logs and I can see three lines. Now let's create an event will bring my hand. Okay, there is a new event. Okay, finish the communication and let's refresh new lines Just created. Okay, you can see that's almost in a real time. Let's do that again. Let's do the same for the L. D. R logs. Maybe I would put my hand from Dale Jr. Sense off for a second. Okay, I'm getting an event late and let's check the logs. Is the refresh great? Okay, they home them. I got a new line and the current light levels in my home alone off. It's very bright. So it's changed, right? And then when I changed my hand it's another event. So just don't change again. Very bright. And, of course, the DHD 11 logs. It's keep adding all the time it's keeping its keep going all the time. Okay, so new. A temperature and humidity. I keep reading all the type if some off the reading are incorrect because you need to let the DHT 11 sense so it's something like a few minutes toe stabilize before we can use the reading. But anyway, this is how we are a kating in event in the Arduino using the sensor and sending that using the HDP get meddled into the Web server, the Web server were running over there. Their script the silver sight script that are actually saving this as new lows in the database. Now the last thing I would like to present is in case there is some Evel. So as an example, let's am then off the one server. Okay, stop all services. There's a red light and let's create an event. Okay, I'm getting the indication that there is an event however you know cannot a save them hand , get request. So in some off point of time, I'm expecting to get I am Red Cola. Rizzo. Okay. Got it. Indicating there is some problem now, you know, I mean, if you remember, the only way to get out from this situation is to list out the way, you know. Okay, let's do another test and off some Aero will bring back the one server startle services and also the star that we know. Okay, wait for the system to come to come back. Great. The one seventies up. Okay, system is walking now as an example, let's disconnect the internet cable. So I will do that from the outer side. You can look on the led right over here when I will disconnect. Okay. Just disconnected it on cable. Now, let's create some event right immediately. I can see the red colores indicator. Okay? I think this is a gateway to a quickly troubleshoot and find problems in your project and these as a product. I mean, the product itself provides some feedback to the user that that there is some problem and the last thing I would like to share with you he's away toe, analyze a data. Okay, we saw some script toe to see one table, and I kicked in the PHP file that we can see all tables and that the name is called Review A Review under school date on the school. You can download this file from the chapter that we are right now, and basically it is connecting into the database and hitting the echoes from the LDL from the ultrasonic and former DHT and display that in a nice way right over here because the temperature nobody's coming all the time. I limited that toe 10 records. Let's see the court for a second. So that's the fine man named Review on the school data underscore all that PHP. We are always including the DB connect PHP and then connecting to the database and then three different query for each table and checking the result three times to see if we have some elbow while trying to read something from the table and then jumping into HTML and pointing the tight er's Farage stable. Start itching and playing a little bit with the Coehlo off the table and then fetching the one by one. And this is repeating force off for the distance and also for the temperature and humidity . Okay, that's all that's there. And the file. You are more than welcome to take that and start to play with that. And it just that according to a future requirement 50. Course Summary: we almost at the finish line. Thanks for watching so far. This course was designed to provide you and knowledge a related to Web technology and how to combine it with albarino vacating a nice Internet off thing system. And now, let's see in high level the flow off topics that we covered and also a what I would like to recommend as the next step moving forward on your personal learning, Kev. So what did we covered so far? We started by connecting albarino to several cents. So for measuring temperature, humidity like change in distance. And for that we use the DHD 11 a don't trust own accent. So and the LDS and so we also connected are doing no to the Internet, using the alternate extension shield, getting dynamic AP and creating HDP connection to a remote server. So basically, the Lono transformed into an Internet off things device. Then we installed the once sever package setting. I will own Web in that the base silver using Apache and my sequel and creating the BHP several side script and in the last step we connected are doing you know, I ot device to the web. Several using a Web API I, and stood ongoing sensible data into the database. Doing this course, we practice how to build a complete coyote system ineffective way, starting with breaking the project into steps in each steps, we focus on one component at a time. A what are the features and capability we can get and how to connect it to the Arduino? We used freezing as a software tools to visual the circuit and building that on a simple bread boat using that Louis No I. D. E. While utilising different libraries in our program to easily operate some models. And we also learned to use the PHP my had mental for setting the my sequel databases. So at the end, we got a nice and 20 Internet off Things system, including an i O T endpoint, using the Reno and Web server in database for storing and analyzing a central data