![]() ![]() The original timer modules provided by NodeMCU are enough for general cases, but it’s not that handy when it comes to certain cases. Those who use Node.js or Javascript a lot should find it very familiar. ![]() This timer module API is written in JavaScript language style and it’s similar to setTimeout(), setInterval(). The Arduino sketch attached to this blog post will include them.Today I am going to introduce a timer module that can be utilized on NodeMCU (on ESP8266 WiFi SoC). This was to keep the code brief and to the point. It’s worth noting that the code examples do not include serial prints. Leave the red LED on and send a message through serial indicating we could not connect.Gets readings and post them to the service.The loop runs as long as the device is active. Unsigned long diff = millis() - lastPost When the loop starts and the process checks whether it should post, it will do so immediately. The last statement sets the last post time to the max duration. If the red LED remains on, then something went wrong during setup and we could not connect. If they stop blinking it means it eventually connected successfully. ![]() This method will, during the while loop where it attempts to connect Wi-Fi, alternately blink the blue and red LEDs. set last post to duration so we post immediately in main loop Try to connect to Wi-Fi a pre-set number of times My setup was responsible for initializing serial communications, connecting and checking that Wi-Fi is working, and wiring up the root web request handler: void setup(void) If you are familiar with Arduino then you know each Arduino sketch includes two main methods: setup and loop. Setup and LoopĪt this point I had my device capable of both sending data as well as providing data upon request. I considered parsing this information and leaving the red LED on or off depending on whether I saw success or not, but Arduino code does not include very helpful utilities for checking whether a string contains text, so I skipped this task for now
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |