If there was a microcontroller that you could describe as ‘fun’ it should surely be Espressif System’s ESP32 family. Packing the processing power of a Pentium from c. 1999 with Wifi + Bluetooth + many hardware I/O interface protocols, this thumb print sized CPU module on a thumb sized PCB with USB-Serial presents a great little platform. At around $10 for a basic one they are virtually free. Then for a few dollars more add a small screen to display user data, such as the WeMos Lolin32 OLED, you’ve got neat device hub for Internet of Things.

IoT enabled PLCs are available but they are somewhat expensive, and unless using an embedded PLC of some form, the IoT functionality can be rather limited. If one limitation is say not providing secure MQTT (aka MQTTS) then your MQTT data and the MQTT broker & server on the web are more at risk. Assuming the PLC can interface using IP or Serial (even the atrocious AB Rockwell protocols) then a very economical IoT Gateway can be put together using say a WeMos Lolin32 plus a Serial to TTL converter (e.g. MAX3232).

Why a microcontroller vs say embedded Linux? Well from hard knocks RPis and Beaglebones crash too often or the SD card gets corrupt and then they crash. Afterall this is Industrial Internet of Things not a ham IoT proof of concept.

The driver to this project was to provide a very cost effective logging and alarm platform with remote change capability and without the need to open Router ports; basically SCADA plus Change with some caveats. After dabbling with Azure and Google Cloud IoT it soon became apparent that to scale those up was going to be relatively expensive for database and run time. So after much shopping I settled on an Ubuntu Virtual Private Server hosted by interserver.net. So far (10 months) the basic $6/mth package has proven adequate and very reliable. As an aside the VPS also hosts the Apache + MySQL + Joomla with which you are viewing this page, plus Postfix and associated add-in modules for secure email. I'll post/blog somewhere what the config is.

 

Thirsty Nomad Brewing Data Logging

Thirsty Nomad Brewing LLC is a nano brewery in Charlotte that I happen to be one of the owners of and I’m the head-brewer come engineer and maintenance tech. The Fermentation Control at Thirsty Nomad Brewing LLC, Charlotte uses a Koyo CLICK PLC. [BTW I love CLICK PLCs for simple stuff!] ModbusRTU is natively supported by this PLC. In Slave (Server) mode the CLICK PLC responds to the master requests without additional PLC programming.

The basic topology of the system is:

  • ESP32 is connected to LAN and thus the Internet through router.
  • ModbusRTU variable type and address are held in an array of type structure (stored in Flash as json file).
  • At set machine state times ESP32 iterates through array and polls PLC via ModbusRTU Serial.
  • Modbus Byte and Word data is converted to C types and appended to tagged data to send.
  • Data is published securely to cloud MQTTS broker and to cloud MySQL. [Polling interval is 60s for MQTT and 600s for MySQL].
  • Config data (also json file) and variable setup can be changed locally using web interface on ESP32.
  • Cloud data is rendered using a Joomla secure client login and a node.js backend subscribing to the MQTT subjects plus the app is a MySQL client. Both AJAX and socket.io are used between the client and server. The node.js app uses the Joomla cookie to authenticate and determine socket id by.
  • Fermentation settings can be changed remotely using the Joomla webform with the node.js backend Publishing and the ESP32 Subscribing to a particular subject and setting values using Modbus. [and then repolling the PLC, thence the ESP32 republishing MQTT to ultimately send values back to client via socket.io].
  • Node.js app evaluates Alarm statuses of the current MQTT values and sends emails (and text messages using email). 
  • Arduino C++ used for coding and IDE. It was a trade-off for speed of development and slightly non-optimum code vs full-fledged C plus the Espressif esp-idf libraries and sdk.

 Basic Data Flow

 

ESP32 Lolin OLED + MAX3232 powered by 5VDC from CLICK RS232 Serial Port and housed in small box. Box is mounted externally to steel enclosure for WiFi reception.

 

 

Basic Dashboard for current Fermenter and Brite Tank data (plus change of settings) and Graphing of historian data from database.

MBMW Solutions