I’m working with mesh network. The problem is l’m trying to add the values of sender to the chart that l created for my receiver board. Using you project for chart: https://randomnerdtutorials.com/esp32-esp8266-plot-chart-web-server/
When l plug in my BME280 to the receiver it works like a charm. Issue is getting it from sender for me 😁
Hi.
Try this for your receiver code:
https://gist.github.com/sarasantos/a6cb8752468c4be214c587b80cb1d7fc
The issue was probably related with line 147.
Regards,
Sara
Hi.
Can you better explain what you are trying to achieve.
You say you are unable to get the readings from the sender?
What tutorial are you following for that?
Regards,
Sara
My bad, sorry for bad explanation. First of all tried to make the following project:https://randomnerdtutorials.com/esp32-esp-now-wi-fi-web-server/. After achieving this l wondered if l can ad a chart that will show senders value (The same temperature value that shows BOARD #1) but l couldn’t. Used the code from this project:https://randomnerdtutorials.com/esp32-esp8266-plot-chart-web-server/.
Hi.
Yes. You can do that.
When you say you couldn’t use the code, what happens exactly? What errors are you getting?
Or are you having difficulty combining both projects?
Regards,
Sara
l couldn’t make the chart to show the value that is coming from the sender board. When l plug in my BME280 sensor to receiver esp32 board the chart show all the values but when l plug in to my sender board instead l don’t know how to change the code or how to play with variable.
Receiver code :
https://github.com/Tzelal/CurrentProject/blob/main/Receiver
Photo what l’m trying to do:
https://github.com/Tzelal/CurrentProject/blob/main/Screenshot%202021-01-14%20173623.png
l don’t know which variable to play with. The code below makes it work but when the sensor is pluged in the receiver board (There are few more codes for readBME280Temperature() fonction).
server.on(“/temperature”, HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, “text/plain”, readBME280Temperature().c_str());
});
sender boards code is actually the same with yours only changed the sensor to BME280:
https://github.com/Tzelal/CurrentProject/blob/main/Sender
Which variable or part of the code l need to change to make the chart work with the value that is coming from sender esp32 board.
By the way thanks a lot for your time .
Hi.
Your code is a bit of a mess. You have some lines of code that are never executed. I recommend that you try to clean your code a bit to have a better view on how it works.
In your specific example, you’re sending readings to the browser as events when you receive a new packet via ESP-NOW. In these lines:
// callback function that will be executed when data is received void OnDataRecv(const uint8_t * mac_addr, const uint8_t *incomingData, int len) { // Copies the sender mac address to a string char macStr[18]; Serial.print("Packet received from: "); snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); Serial.println(macStr); memcpy(&incomingReadings, incomingData, sizeof(incomingReadings)); board["id"] = incomingReadings.id; board["temperature"] = incomingReadings.temp; board["humidity"] = incomingReadings.hum; board["readingId"] = String(incomingReadings.readingId); String jsonString = JSON.stringify(board); events.send(jsonString.c_str(), "new_readings", millis()); Serial.printf("Board ID %u: %u bytes\n", incomingReadings.id, len); Serial.printf("t value: %4.2f \n", incomingReadings.temp); Serial.printf("h value: %4.2f \n", incomingReadings.hum); Serial.printf("readingID value: %d \n", incomingReadings.readingId); Serial.println(); }
The line highlighted in bold is the line that actually sends the readings. The readings are sent to the browser as a JSON variable.
In the browser, this part of the code receives the sensor readings and displays them on the corresponding places:
source.addEventListener('new_readings', function(e) { console.log("new_readings", e.data); var obj = JSON.parse(e.data); document.getElementById("t"+obj.id).innerHTML = obj.temperature.toFixed(2); document.getElementById("h"+obj.id).innerHTML = obj.humidity.toFixed(2); document.getElementById("rt"+obj.id).innerHTML = obj.readingId; document.getElementById("rh"+obj.id).innerHTML = obj.readingId; }, false); }
I recommend that you that a look at our tutorial about server-sent events to better understand how they work: https://randomnerdtutorials.com/esp32-web-server-sent-events-sse/
You need to call the functions to build the charts inside the event listener. So, the eventlistener function should be like this:
source.addEventListener('new_readings', function(e) { console.log("new_readings", e.data); var obj = JSON.parse(e.data); document.getElementById("t"+obj.id).innerHTML = obj.temperature.toFixed(2); document.getElementById("h"+obj.id).innerHTML = obj.humidity.toFixed(2); document.getElementById("rt"+obj.id).innerHTML = obj.readingId; document.getElementById("rh"+obj.id).innerHTML = obj.readingId; var x = (new Date()).getTime(), y = obj.temperature.toFixed(2); if(chartT.series[0].data.length > 40) { chartT.series[0].addPoint([x, y], true, true, true); } else { chartT.series[0].addPoint([x, y], true, false, true); } }, false);
This should solve your problem.
Let me know if this helps.
Regards,
Sara
Yes it is completely mess and l have to work a lot for it =D . With the change on eventlistener the chart started to work but still doesn’t show the temperature value. It shows only the date.
Pic 1: CurrentProject/Screenshot 2021-01-16 102434.png at main · Tzelal/CurrentProject (github.com)
Pic 2 Chart: https://github.com/Tzelal/CurrentProject/blob/main/Screenshot%202021-01-16%20102451.png
Hi.
In your web browser press CTRL+SHIFT+J. The console should open.
Tell me what you see in the console.
Regards,
Sara
Hello.
it shows errors in two places. Inside the script “Failed to load resources 500” and for “Get /state 500” like the photos below.
1:https://github.com/Tzelal/CurrentProject/blob/main/Screenshot%202021-01-17%20140100.png
2:https://github.com/Tzelal/CurrentProject/blob/main/Screenshot%202021-01-17%20135633.png
You get that error because you don’t have anything to handle the request on the /states URL.
You should have missed something while copying the code.
Regards,
Sara
Hello again 🙂
This time tried to clean the code little bit and left only the chart and the boxes that are showing the values but still getting the same problem. Chart doesn’t show the eventlistener value that is coming for temperature box from sender esp32 board.
- Photo: https://github.com/Tzelal/TempChart/blob/main/Screenshot%202021-01-18%20100137.png
- TheCode: https://github.com/Tzelal/TempChart/blob/main/TheCode
Thanks.