Cricket is a tiny low power IoT module from ThingsOnEdge. It’s capable of connecting to most local or cloud-based IoT services and runs on batteries for thousands of hours.
In this project, you’ll learn how to connect Cricket modules to a local network using Wifi with MQTT. You will store readings from the Cricket’s onboard temperature sensor using InfluxDB with Telegraf and display the results in a Grafana dashboard. All these components are open-source and can be hosted on a Raspberry Pi.
At the end of the project, you will have a powerful and extendable IoT platform that can be used to monitor a network of Cricket modules in any space with Wifi access.
The Raspberry Pi will host all of the software components that enable Cricket to publish MQTT messages and display that information as graphs and gauges in a dashboard. The Raspberry Pi will act as a server on the local network which we will access from a host PC (Windows 10 / Mac OS / Linux) using OpenSSH.
If the Raspberry Pi hostname is not resolved try using ssh email@example.com or check your router’s admin page and use the Pi’s IP address – ssh pi@XXX.XXX.XXX.XXX
Now all the required software can be installed. Several packages are needed to connect everything together. Mosquitto MQTT broker acts as a queue for messages published by the Cricket. Telegraf server agent connects the MQTT broker to the InfluxDB database while Grafana will present the stored data as a dashboard.
sudo apt update sudo apt upgrade
sudo apt-get install mosquitto mosquitto-clients
sudo apt install apt-transport-https wget -qO - https://repos.influxdata.com/influxdb.key | sudo apt-key add - source /etc/os-release test $VERSION_ID = "10" && echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update && sudo apt install telegraf
sudo apt install influxdb
wget -qO - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update && sudo apt install grafana
Cricket modules are designed for battery power and consume only 0.5uA in deep sleep, so can run for thousands of hours on one pair of AA batteries, depending on setup.
Each module has an accurate onboard temperature sensor and a battery monitor. There is 3.3V power output, digital and analogue inputs and an external wake-up pin for additional sensors. Configuration can be set locally via the Cricket’s own Wireless AP or using a free Cloud-based option provided by ThingsOnEdge. No coding is required to send data from the module.
We will power the Cricket using 2 x AA batteries and configure it using the local AP mode.
Crickets have 6 castellated through-hole solder pads at 2.54mm spacing, suitable for various connectors or soldering to PCB’s.
Several configuration options allow Cricket to communicate with most local and cloud-based IoT services, using HTTP or MQTT protocol.
For testing we will setup Cricket to send readings from its onboard temperature sensor every 20 sec using MQTT.
This example uses a Raspberry Pi hostname raspberrypi and MQTT broker port 1883.
Cricket is now configured and will restart. The LED will flash a few times as it connects to Wifi and attempts to sends data via MQTT. Now every 20 sec the real-time clock will wake the module, the LED will flash and the current temperature in degrees Celsius will be sent, then it will turn off until the next update.
This step tests the Mosquitto broker and checks that Cricket is able to send MQTT messages successfully.
Mosquitto starts automatically on boot-up and listens on default port 1883. Check the status with the following command:
systemctl status mosquitto.service
The service can be started with the following command if it isn’t running:
sudo systemctl start mosquitto.service
Mosquitto listens for devices publishing MQTT messages and holds them in a queue called the Topic path. By default, Cricket publishes temperature readings to topic path /<your-device-serial-number>/temp.
Our Cricket’s serial number is 20DC6FE33A so it publishes temperature readings on topic /20DC6FE33A/temp – the slash characters are significant!
Clients can subscribe to topics and receive messages each time they are published:
mosquitto_sub -F '%I:%t:%p' -h raspberrypi -t /20DC6FE33A/temp
You should see temperature readings being updated about every 20 seconds showing the Cricket is connecting and the broker is working. Temperature readings are over-stated when polled this quickly due to heating of the PCB. This will be corrected later on.
Now InfluxDB can be configured so we have a database to store our temperature readings.
systemctl status influxdb.service
If not start it:
systemctl status influxdb.service
influx create database cricket use cricket create user grafana with password 'jg99ifF&kln' with all privileges grant all privileges on cricket to grafana exit
Telegraf uses plug-ins to support many different data inputs and outputs. We will use the MQTT Consumer input plug-in and the InfluxDB output plug-in to connect the Mosquitto broker to the InfluxDB database so messages will be saved each time they are published.
cd /etc/telegraf sudo sh -c 'telegraf config > telegraf.conf'
Plug-ins should be configured in /etc/telegraf/telegraf.d/ with a filename ending in .conf
[[inputs.mqtt_consumer]] # MQTT broker servers = ["tcp://localhost:1883"] topics = ["/20DC6FE33A/temp"] qos = 0 connection_timeout = "30s" data_format = "value" data_type = "float" [[outputs.influxdb]] # InfluxDB instance url = "http://localhost:8086" database = "cricket"
sudo systemctl restart telegraf.service
influx use cricket select * from mqtt_consumer exit
Now that temperature readings are being saved in InfluxDB, we can connect up Grafana and build a dashboard to present the data in a useful way.
sudo systemctl enable grafana-server.service sudo systemctl start grafana-server.service systemctl status grafana-server.service
You will now be redirected to the Grafana welcome screen:
Add a data source:
Further down the page, using the same details set up in Step 5 for the database:
If all is well Grafana will show feedback or an error message.
You should now have a nice time-series graph of your temperature readings.
Experiment with all the various settings and panels to build a dashboard that suits you. There are loads of panel types, trigger points, threshold levels and even alerts.
Grafana has brilliant documentation including video tutorials here.
Here’s ours showing readings from 2 Crickets in different locations with gauges for current temperature and graphs for historical readings. The gauges change colour at different threshold temperatures.
Once everything is connected up and data is flowing:
You will then get really accurate temperature readings and extend the battery life to many months or longer.
This project has guided you through the basics of connecting Cricket modules to a Grafana dashboard using MQTT and InfluxDB with Telegraf.
If you followed the instructions carefully you should have a powerful IoT platform running on your Raspberry Pi that can support multiple Cricket modules deployed around any space with Wifi connectivity. Set up appropriately, each Cricket can run for many months on a set of batteries without writing any code.
More information about Cricket and the Open Source software used in this project is available:
InfluxDB and Telegraf: https://www.influxdata.com/
Anyone for Cricket?
Please select an option to see content specific to your location and shop online.