I got the solution but I don´t know why the old sketch doen´t work and the new one does. I changed the buffer[] char to a string and changed the delay(3) to delay(1).
Thanks for the advise anyway! Appreciate it!
TimDe
@TimDe
Best posts made by TimDe
Latest posts made by TimDe
-
RE: SoftwareSerial dropped packages
-
SoftwareSerial dropped packages
Hi there,
I am working on a project where I am using one Arduino Uno with a nRF24L01+ module as a Receiver of sensor data. The sketch I am using is:
#include <SoftwareSerial.h> #include <SPI.h> #include <RF24.h> SoftwareSerial mySerial(7, 8); // RX, TX RF24 radio(9,10); byte addresses[][6] = {"1MZ","2MZ"}; void setup() { mySerial.begin(4800); radio.begin(); radio.setPayloadSize(4); radio.setDataRate(RF24_2MBPS); radio.setPALevel(RF24_PA_MAX); radio.openReadingPipe(1,addresses[1]); radio.startListening(); } void loop() { unsigned long AnkommendeNachricht; if( radio.available()){ while (radio.available()) { radio.read( &AnkommendeNachricht, sizeof(AnkommendeNachricht)); } mySerial.println(AnkommendeNachricht); } }
When I watch on a Serial monitor, every second I receive a 10 number long message (It works how it should). After receiving I want to send the messages to a Wemos D1mini via SoftwareSerial. After receiving the data with the Wemos I want to split the data in 4 parts and then publish them one after another as a MQTT-message. The code I am using is this:
#include <ESP8266WiFi.h> #include <PubSubClient.h> #include <SoftwareSerial.h> #include <SPI.h> SoftwareSerial mySerial(D3, D4); // RX, TX const char* ssid = "..."; const char* password = "..."; //const char* mqtt_server = "..."; const char* mqtt_server = "iot.eclipse.org"; WiFiClient espClient; PubSubClient client(espClient); char msg[50]; char Number[1]; char Idle[3]; char Work[3]; char Height[3]; char Buffer[9]; char Topic; void reconnect() { while (!client.connect("ESP8266Client")) { delay(50); } } void setup() { mySerial.begin(9600); WiFi.begin(ssid, password); client.setServer(mqtt_server, 1883); } void loop() { client.loop(); if (!client.connected()) { reconnect(); } int pos=0; if (mySerial.available()) { while (mySerial.available()) { Buffer[pos++]=mySerial.read(); delay(3); } } for (int i=0; i <3; i++){ Idle[i]=Buffer[i+1]; } for (int i=0; i <3; i++){ Work[i]=Buffer[i+4]; } for (int i=0; i <3; i++){ Height[i]=Buffer[i+7]; } snprintf (msg, 50, Idle); client.publish("Idle", msg); snprintf (msg, 50, Work); client.publish("Work", msg); snprintf (msg, 50, Height); client.publish("Height", msg); } }
When I now watch the received messages on the MQTT-Broker I find that some messages are not being received. So it seams that some messages are lost due to the SoftwareSerial (If I change the delay, the packet error rate changes too...). Are there any advises regarding this topic? I searched a lot and didn´t find a solution.
PS: I do not want to use the MQTT-bridge sketch by mysensor
-
RE: nRF24L01+ MQTT
@gohan until now everything worked well with this 1MHz. Also other libraries directly worked without Problems
-
RE: nRF24L01+ MQTT
So there is the difference. The Uno has 16MHz and the standalone 1MHz... and the wiring is 100% correct, I did this again and again like 10 Times and also tried a Second microcontroller without improvements. And the Strange Thing is that I Receive Messages (from Time to Time) but the Data Sent are Strange)
And so the only difference is in the Frequence and the missing other Parts. Is there anything in the mqtt background which prohibits the correct transmission? -
RE: nRF24L01+ MQTT
A short addition:
After starting the Mikrocontroller, my MQTT broker always receives the same messages. They have no payload and the syntax of the first four messages for example is:nRFGateway-Publish/255/16/3/0/3
nRFGateway-Publish/255/239/3/0/3
nRFGateway-Publish/255/206/3/0/3
nRFGateway-Publish/255/174/3/0/3I hope this may help...
-
RE: nRF24L01+ MQTT
you are right, Nca78.
So here is my sketch of the sender
#include <SPI.h> #define MY_RADIO_NRF24 #include <MySensors.h> int Payload; #define CHILD_ID 2 MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { } void presentation() { } void loop() { Payload = Payload+2; send(msg.set(Payload)); delay(2000); }
and here is the sketch of the recheiver:
#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_ESP8266 #define MY_MQTT_PUBLISH_TOPIC_PREFIX "nRFGateway-Publish" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "nRFGateway-Subscribe" #define MY_MQTT_CLIENT_ID "mysensors-1" // Enable these if your MQTT broker requires usenrame/password //#define MY_MQTT_USER "username" //#define MY_MQTT_PASSWORD "password" #define MY_ESP8266_SSID "..." #define MY_ESP8266_PASSWORD "..." // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. // #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) //#define MY_IP_ADDRESS 192,168,178,87 // If using static ip you can define Gateway and Subnet address as well //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0 // MQTT broker ip address and port. #define MY_CONTROLLER_IP_ADDRESS ... #define MY_PORT ... #include <ESP8266WiFi.h> #include <MySensors.h> void setup() { Serial.begin(38400); } void presentation() { } void loop() { }
I think there is no problem with the sketch, because both sketches work when I am using an Arduino Uno instead of the standalone ATmega with the same sketch and wiring.
And here are photos of the wiring. The radio is wired correctly, I checked it several times. And I also use the same wiring for the ATmega as I do usually...
-
nRF24L01+ MQTT
Hi there,
I am working on a project with a Standalone ATmega328P-PU and a nRF24L01+-module which should communicate with a Wemos D1 mini with an attached nRF24L01+. The Wemos works as a Gateway and should transfer the messages to my MQTT broker. I now hooked up everything and loaded the sketches on the Wemos and the standalone ATmega. But sadly the standalone ATmega sends empty messages and turns down every 10 seconds for 10 seconds. When I use the same sketch on an Arduino Uno instead of the standalone ATmega, everything works fine. Also I am able to communicate with the standalone ATmega and the nRF-module if I use another library (RF24.h). But sadly this library doesnt support MQTT.
Did anybody have same issues? I mean it is very suspicious, that the module turns down every 10 seconds for 10 seconds long...
Thank,
TimDe