Again., The ESP8266 Is a great product.. It adds internet connectivity to a quite fast processor and with the newer boards like the ESP 12. We also have plenty of memory and pins available. And with the Arduino IDE, we have a well known programming, environment and lots of libraries.. But what is lacking for a true internet of things platform? We need a software framework with the following characteristics: Simple connections to Web services. Iot devices have to be connected to the world, Simple interface to smartphone. Iot devices have to be simple and often without keyboard or display.. This is why they have to be able to get the information for Wi, Fi credentials and other parameters directly from the smartphone.. They need a sleep mode to extend battery life.. We all know that ESP8266 need lots of Energy and cannot work long time with batteries.. New software has to be loaded remotely over the air.. If such devices are deployed, they physically cannot be reached anymore because they are built in or have no programming connectors.. Future users would never want to deal with FTDI or other programming devices.. I start now the building of such a software platform and will show you my progress Today. I start with the first point And I hope I will be able to reach the last point in the next weeks To prove the concept I decided to build a device which connects to an official web service in Switzerland, which announced is all departures of public transportation.
We have to find the web service, which provides us with the needed information.. This is typically done by a Google search or by going to the site, httpswww.programmableweb.com Let’s assume you found an API which delivers the information you need., Then it is good to read its description to understand the syntax of the call and If you know the syntax, the Best next step is to try it out manually.. To do this, I installed an app from the Google Chrome web store.. You find the link below in the comments. The syntax of the Swiss Transportation. Api is on this slide.. It consists of three parts, an address. The two cities where the journey starts and ends and optional a statement to restrict the number of fields which are returned from the web service.. This part is very important because it reduces the effort to find the right information on our small IOT device. Let’s test. This service., As already said, I need the GET message.. I write the call in the respective line and hit send.. I get now three parts of information.. First, I get a status message and second, I get the header information.. The third part is the information. I am interested in.. It displays the next departure from Basel to Zurich.. This message has only 67 bytes.. If I switch to raw, I see the string which I have to decode later in my program on my ESP8266., But let’s play a little with the api.
. If I remove the optional field restriction, the message is much bigger., It has now 1764 bytes and it would be nearly impossible to handle it on a small IOT device.. Here we learn an important lesson., Keep the big work in the internet and not on your small device. The return message is exactly, as you see it, here. The first line will be the date line and the last line will be the connections line.. Our program just has to check if the status of the message is okay., It is status 200 and then read through all lines to find the sub string quotdeparturequot.. The numbers of desire are then in a constant distance from this keyword. Hours minutes and seconds of the next departure. Let’s. Now look into the code.. We have to read and decode the response.. Bigger computers usually read the whole message in one block and decode or parse. It afterwards. For small devices we read line after line and search for the keyword quotdeparturequot here passed to the subroutine as the variable lookupString.. If we found it in a particular line, we extract the three variables hours minutes and seconds using string arithmetic.. At the end, we can return the next departure time to the calling code, But how is the request message? Looking It consists of three lines.. The first is similar to the one we used in the manual scenario, but without the host name.. The second line adds the host information and the third instructs the server.
If we want to keep the connection alive or close it after the request., The respective program code is straightforward., Do not forget the carriage return and line feed characters.. Here I want to call your attention to a particularity of the ESP8266.. The WiFi traffic is handled in parallel to your normal program execution, and you do not feel it because the ESP firmware handles it without intervention by stealing some time of your program.. If you do loops, this stealing can be prohibited and the ESP crashes.. If this happens, you have to enhance waiting loops with a short delay., Never wait in a while 1 1 loop.. The ESP will crash immediately and produce a dump.. Only if you enhance your loop with a small delay1, your ESP will run without any problems.. In this video we were able to discover a web service providing a RESTful API. Check it out, manually. Program, a call from the ESP8266. and decode the JSON formatted messages.. Now we are ready to move on with our IOT framework. In the next video. I will show you how to connect your ESP to your smartphone or PC to enter the needed credentials for the Wi Fi Network and other data.. Here you see the current status. Every seconds. The ESP8266 queries the web service and starts to peep if the time to leave for the bus arrives..
ARTe Arduino Real-Time extension | Home
.Net Micro Framework | Dragonfly Thing Works
Get started with Arduino and ESP32-DevKitC: debugging and …
Posted on Saturday September 28, 2019Attack on Saudi oil facilities demonstrates drone threat | Alessandro Arduino The Arab Weekly … Continue Reading »
Posted on Friday August 30, 2019Arduino On MBed Hackaday … Continue Reading »