Hi! I am trying to create a project that takes a reading from a temperature and humidity sensor and passes it along a mesh network and displays it on a lcd screen. I am using a hdc1080 temperature and humidity sensor and a esp32 development board along with the Painless Mesh library. However, I am having great difficulty in understanding how to implement my project into the "basic" example that is found on the Painless Mesh library. Could someone please help me? I posted the link to the library and the example of the code I am using here. Thanks for your help!
Sincerely,
Jason Soar
//************************************************************
// this is a simple example that uses the painlessMesh library
//
// 1. sends a silly message to every node on the mesh at a random time between 1 and 5 seconds
// 2. prints anything it receives to Serial.print
//
//
//************************************************************
#include "painlessMesh.h"
#define MESH_PREFIX "whateverYouLike"
#define MESH_PASSWORD "somethingSneaky"
#define MESH_PORT 5555
Scheduler userScheduler; // to control your personal task
painlessMesh mesh;
// User stub
void sendMessage() ; // Prototype so PlatformIO doesn't complain
Task taskSendMessage( TASK_SECOND * 1 , TASK_FOREVER, &sendMessage );
void sendMessage() {
String msg = "Hello from node ";
msg += mesh.getNodeId();
mesh.sendBroadcast( msg );
taskSendMessage.setInterval( random( TASK_SECOND * 1, TASK_SECOND * 5 ));
}
// Needed for painless library
void receivedCallback( uint32_t from, String &msg ) {
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
}
void newConnectionCallback(uint32_t nodeId) {
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
}
void changedConnectionCallback() {
Serial.printf("Changed connections %s\n",mesh.subConnectionJson().c_str());
}
void nodeTimeAdjustedCallback(int32_t offset) {
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
}
void setup() {
Serial.begin(115200);
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
mesh.onReceive(&receivedCallback);
mesh.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
mesh.onNodeTimeAdjusted(&nodeTimeAdjustedCallback);
userScheduler.addTask( taskSendMessage );
taskSendMessage.enable();
}
void loop() {
userScheduler.execute(); // it will run mesh scheduler as well
mesh.update();
}
Sorry, I guess I should have been more specific about what exactly I am trying to accomplish. I will try again starting from the beginning.
The Problem:
My project is intended to solve a problem that has been molesting honey bee colonies and beekeepers alike ever since 2006. In 2006 Colony Collapse Disorder (CCD) was first reported and ever since beekeeping has become extremely difficult. Last year alone 40% of all hives in the U.S. died. The root cause of this strange disappearance of bees is still unknown. However, diseases, overuse of pesticides, and varroa mites are all seen as potential causes. The vast majority of these issues can be tracked using temperature and humidity sensors as well as microphones placed inside the hive. There are commercial solutions to this problem, but these are often seen as too expensive in the beekeeping community to be used extensively.
My Idea:
Therefor, I am trying to make a low cost module that that uses temperature and humidity sensors to track the changes inside the hive. And then display that information online for the beekeeper to analyze.
My Solution:
Now for the technical details! I am using an esp32 module, that has bluetooth and wifi integrated into it, along with a hdc1080 temperature and humidity sensor. In order to pass the values to the central node I want to use a BLE mesh network. I have identified this as the most effective way of passing the values to the central node instead of using just a regular BLE network connection. After passing the values to the central node it will then display it on a webpage over wifi.
What I Need:
I am trying to use the Painless mesh library to create my mesh network. However, I am having an extremely difficult time trying to understand how to use the library to make my mesh network. I have never seen code as complicated as this. I have literally spent hours reviewing the code, searching websites for code examples, and I even tried contacting the creator of the library. Unfortunately, I never got a response. I decided to start small and just have one node with a temperature and humidity sensor and the other connected to a lcd screen. This way I think I can work out my bugs in the program easier and I will have something to show as I already have people in my local beekeepers association asking about my project.
I do not usually like to post things on a forum, but this is my last resort. I hope this will help you understand what I am trying to accomplish. Thanks again for your help.
I guess I am not clear on what is wrong. The code you presented is simply the basic example. I see nothing about temp nor humidity in the code. So let us take a step back.
Have you been able to get the Mesh network to work with 2 nodes?
Have you been able to successfully get temp and or humidity from your sensors?
How are you going to power this?
Answer these questions and perhaps we can be of more help.
Have you considered Lora?
They can easily go 2 Km line of sight using simple wire antennas, or up to 20Km with directional antennas, so no mesh needed.
Adafruit has a Lora board for the Raspberry and a breakout board for the Arduino.
I've never worked with Lora, but it's on my list of projects to do soon.
SteveMann:
Have you considered Lora?
They can easily go 2 Km line of sight using simple wire antennas, or up to 20Km with directional antennas, so no mesh needed.
Adafruit has a Lora board for the Raspberry and a breakout board for the Arduino.
That's why I asked about required distance in Reply #4. If you don't need the range of LoRa, RFM69 is less expensive. The RadioHead library supports both on many boards in the Arduino ecosystem. If your range requirements are even shorter, then nRF24L01+ is even cheaper. There's a good library for that too.
Any of the above would be simpler than dealing with the complexity of the BLE protocol and a mesh network.
BLE seems a curious choice for this application. Consider this from Adafruit:
Range is about the same for both classic and low energy. Technically the max range is about 300 feet or 100 meters, but that’s very generous and assumes a powerful radio. In reality, you will find over 10 or 20 meters can be challenging
It might be usable in a scenario where you have multiple hives in close proximity, talking to a master node, but I would think that the longer the range you have, the more beekeepers would find it useful.
Providing only wifi access to the master seems limiting too. Fine for a domestic beekeeper with a hive (very) close to the house, but not so much if your hives are sitting in an apple orchard for a while. I would want something that can alert me from twenty miles away that there is something wrong. So GSM or Lora perhaps. Xbee if you're keen on mesh, but the radios are pricey.
Therefor, I am trying to make a low cost module that that uses temperature and humidity sensors to track the changes inside the hive.
For the sensor/transmitter module, you can't do better for price, accuracy and reliability than the manufacturers of outdoor weather sensors, like these.
They transmit brief messages on a staggered basis, and most have been decoded with the details published on line, so you can make your own base station to monitor several at a time.
As you have discovered, "painless mesh networks" are still a fantasy.