{"id":429,"date":"2015-04-24T14:35:12","date_gmt":"2015-04-24T21:35:12","guid":{"rendered":"http:\/\/internetofhomethings.com\/homethings\/?p=429"},"modified":"2015-04-24T15:24:41","modified_gmt":"2015-04-24T22:24:41","slug":"issues-with-the-esp8266-arduino-ide","status":"publish","type":"post","link":"https:\/\/internetofhomethings.com\/homethings\/?p=429","title":{"rendered":"Issues with the ESP8266 Arduino IDE"},"content":{"rendered":"<h2><strong>Arduino IDE for ESP8266<\/strong><\/h2>\n<hr \/>\n<p>The Arduino IDE version 1.6.1 with ESP8266 support worked well as a webserver using the WiFiWebServer example sketch as a starting point. This basic example supports on\/off control of an LED from a web browser. The example demonstrates how to interpret and respond to requests. It can easily be expanded to support responses any request strings added to the domain:port URL used to access the device. The example, which simply controls an LED, uses domain:port\/gpio\/0 to turn the LED off and\u00a0domain:port\/gpio\/1 to turn it on.<\/p>\n<p>Building my sketch on the back of this example, I soon uncovered issues which had to be addressed in order for my IoT sensor reads to function as required.\u00a0This included:<\/p>\n<p><strong>1. WiFi Connection<\/strong><\/p>\n<p>The connection can and sometimes does get dropped. It is important to have a check in the sketch loop() function to reconnect if it is disconnected.<\/p>\n<p>if (WiFi.status() != WL_CONNECTED) {<br \/>\ndelay(1);<br \/>\nWiFi.config(ipadd, ipgat, ipsub);<br \/>\nWiFi.begin(ssid, password);<br \/>\n\/\/Wait here until connected, up to a timeout period<br \/>\nwhile (WiFi.status() != WL_CONNECTED) {<br \/>\nSerial.print(&#8220;.&#8221;);<br \/>\ndelay(500);<br \/>\n}<br \/>\nreturn;<br \/>\n}<\/p>\n<p><strong>2.\u00a0Ticker<\/strong><\/p>\n<p>Ticker is supposed to provide the capability to perform periodic tasks. This must be using the SDK timer\/callback API. While it worked flawlessly for me with the SDK, it did not work well with the Arduino loop(). I was trying to separate the sensor reads from the server handler, using the timer for sensor reads. Erratic\u00a0resets occurred. From my experience, Ticker is not usable at this time. With the current Arduino IDE, it is necessary to handle all code single threaded within the sequence of the loop() function.<\/p>\n<p><strong>3. Watchdog Timer Resets<\/strong><\/p>\n<p>Disable the watchdog timer and the MPU will halt on the first timeout. It must remain enabled during normal code execution. But I have observed many resets when trying to read attached\u00a0sensors while also supporting the web server. These resets can be reduced or eliminated by structuring the loop() function with returns after every time consuming task, like reading a sensor. The resets are also reduced by using yield(), delay() and\u00a0ESP.wdtFeed() statements after time consuming tasks.<\/p>\n<p><strong>4. Math Functions<\/strong><\/p>\n<p>Using the BMP085 to read Barometric Pressure require use of the pow function. This math function is not supported with the core library and attempts to link the math.h library blows the memory, resulting in a build error. Since the pow function is only used for the calculation of altitude values, the BMP085 will work with the Arduino IDE if you comment out the pow functions in the library and only read the pressure and temperature values from the device driver.<\/p>\n<p><strong>5.\u00a0JSON Encoding<\/strong><\/p>\n<p>The JSON library included \u00a0with the SDK is not available with the Arduino IDE. And linking a JSON library will blow the memory. Since it is advantageous to return a JSON string with sensor values in response to &#8220;http GET&#8221; requests, this becomes a significant\u00a0shortcoming. But a\u00a0simple JSON encoding function used to build the return string is all that is needed to overcome this. This works with minimal code:<\/p>\n<p>void jsonAdd(String *s, String key,String val) {<br \/>\n*s += &#8216;&#8221;&#8216; + key + &#8216;&#8221;&#8216; + &#8220;:&#8221; + &#8216;&#8221;&#8216; + val + &#8216;&#8221;&#8216;;<br \/>\n}<br \/>\nvoid jsonEncode(int pos, String * s, String key, String val) {<br \/>\nswitch (pos) {<br \/>\ncase ONEJSON:<br \/>\ncase FIRSTJSON:<br \/>\n*s += &#8220;{\\r\\n&#8221;;<br \/>\njsonAdd(s,key,val);<br \/>\n*s+= (pos==ONEJSON) ? &#8220;\\r\\n}&#8221; : &#8220;,\\r\\n&#8221;;<br \/>\nbreak;<br \/>\ncase NEXTJSON:<br \/>\njsonAdd(s,key,val);<br \/>\n*s+= &#8220;,\\r\\n&#8221;;<br \/>\nbreak;<br \/>\ncase LASTJSON:<br \/>\njsonAdd(s,key,val);<br \/>\n*s+= &#8220;\\r\\n}&#8221;;<br \/>\nbreak;<br \/>\n}<br \/>\n}<\/p>\n<p><strong>6. Watchdog Timer\u00a0Functionality<\/strong><\/p>\n<p>A richer API to the watchdog timer is needed. This may just be a wish list, but it would be very helpful if the timeout period could be set and a user defined callback function could be registered for timeouts. This would go a long way in resolving the device resets experienced by many ESP8266 users.<\/p>\n<h2><strong>In summary\u00a0<\/strong><\/h2>\n<hr \/>\n<p>The Arduino IDE is a very well-known and supported platform. These shortcomings will probably be overcome with updates in the future. Despite the limited flexibility and functionality of the Arduino IDE, it will likely be the platform of choice for many ESP8266 application developers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arduino IDE for ESP8266 The Arduino IDE version 1.6.1 with ESP8266 support worked well as a webserver using the WiFiWebServer example sketch as a starting point. This basic example supports &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,10],"tags":[],"class_list":["post-429","post","type-post","status-publish","format-standard","hentry","category-alltheposts","category-esp8266"],"_links":{"self":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=429"}],"version-history":[{"count":12,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/429\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=\/wp\/v2\/posts\/429\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/internetofhomethings.com\/homethings\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}