I want to create ESP32 ESP-NOW net of sensors (eg. temprature sensors, but for now just…
- User
I want to create ESP32 ESP-NOW net of sensors (eg. temprature sensors, but for now just random numbers) and send them to master node and from there to MQTT broker. Could you write code to do this?
Assistant
Sure. Here’s a quick example that demonstrates how to set up a network using the ESP-NOW protocol. This code will run on an ESP32, and will create a “sensor” node that periodically publishes data to the master node. The master node will subscribe to data published by the sensor node, and then re-publish the data using the MQTT protocol.
- User
Regenerate master node code again
Assistant
Sure. Here’s a new version of the master node code. This code subscribes to data published by the sensor node, and then publishes the data using the MQTT protocol.
- User
How can I get master node macadress?
Assistant
The master node’s MAC address is printed to the serial monitor when you run the code. You can also find the address using the “ifconfig” command in the Arduino IDE.
- User
I always get this (Sent data successfully Last Packet Send Status: Delivery fail)output on slave node. I set mac from last sketch, any troubleshoot steps?
Assistant
This indicates that the master node is not able to successfully deliver the data published by the sensor node. This could be due to a number of reasons. The first thing to check is that you’ve set the MAC address correctly on both nodes. You should also check that both nodes are on the same WiFi network. Finally, you could try removing the MQTT portion of the code, and just sending data directly from the sensor node to the master node using ESP-NOW, to see if you get better results that way.
- User
I removed MQTT part and got succesful delivery, does this mean I can use ESPNOW and MQTT simultaniously?
Assistant
Yes, you should be able to use both ESP-NOW and MQTT simultaneously. If you’re still having issues with delivery, you could try increasing the broadcast interval for the sensor node, or reducing the broadcast interval for the master node.
- User
Unfortunatly that did not help, any other advice?
Assistant
Here are some other things you can try:
- Make sure the MQTT library you are using is compatible with the ESP32 and the ESP-NOW library.
- Try using a different MQTT broker to see if the issue is specific to a particular broker.
- Check the network settings of the ESP32, including the IP address, subnet mask, and gateway.
- Ensure that the MQTT client ID and topic names are not too long or complex, as this can cause issues with some libraries.
- Try simplifying the code and removing any unnecessary features to see if that resolves the issue.
If none of these suggestions help, it may be helpful to post the full code and error messages to a forum or community for further assistance.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.