Firmata Llbrary for Arduino comes preinstalled in the IDE and we can use it with supported boards, Arduino or ESP8266.
- For Arduino; we use StandardFirmata and for ESP8266 we use StandardFirmataWifi
For the “Blink” example; I am showing you Python and Node.js examples; we can program in any language / platform and can find required library
- For the Node.js; I am using firmata
If you are wondering; the code is not compiled and sent to microcontroller; instead microcontroller after firmata firmware is acting as a slave always listening to what’s being sent over the wire in the firmata protocol; you can watch the RX activity clearly on the Arduino board
In case of Arduino, the clear drawback is that we need serial connectivity between the board and the computer running the program. We can either use Ethernet or Wifi shield or ESP8266 where this serial cable connection is avoided and the program can connect to the microcontroller through Wifi. Simply use StandardFirmataWifi; edit the WifiConfig.h according to your Wifi settings, optionally uncomment SERIAL_DEBUG to view the debug logs in the Serial Monitor and you are good to go
I connected an Analog Temperature Sensor to Analog Pin 0 and wrote this little Node.js program that retrieve the temperature value and send it to ThingsSpeak for further analysis / reporting.
I find this firmata approach intuitive and easier; given we can change / manage the program easily on the computer instead of reflashing microcontroller firmware, especially ESP8266 based IoT appliances works great in this way. The appliance can continue to be installed where it is; say Sonoff switch and you can change / update the program on the computer possibly even remotely; say Raspberry Pi by sushing it
ESP8266 comes in all sizes; check this video for inspiration; we can deploy sensors connected to ESP01 (that has two GPIOs) and solder/glue/pack the things to normal wall socket USB chargers (with required voltage regulation)