RS485/RS232/Serial transport class for mysensors.org
-
Hello,
I have a problem running gatewayserial to rs-485 and the node with the usual lightsensor.
NODE # 1 as a gateway and tried to upload a sketch of the library 2.0 and 1.5.4, and the monitor serial I can not see any data, I use to check on the serial PuTTy com6 because the converter rs-485 to USB is connected to the PC.NODE # 2 as a light sensor, during the upload Sketch by arduino programmer for serial monitor can see the data being sent but after plugging arduino to rs-485 as below no longer visible.
My question is whether I have something wrong with the connection or sketch, can someone show an example of a complete sketch for the gateway, and a node?
Connection mine looks like this:
TX and RX Connect was to pins 0 and 1 in arduino or 8 and 9, DE is always PIN 2.So what's with the DE+RE pins on that USB-RS485 converter? Will it even work in this configuration? I do have such converter but so far I've used the arduino as a SerialGateway to connect to RPi.
-
I am not sure if I am seeing a normal behavior. I don't know if it is expected that the sensor is taking such long time to become visible to the GW. I have recreated the examples from https://www.mysensors.org/build/rs485
The only difference is that I've added SketchInfo for the GW and used Serial1 on MEGA board instead of AltSoftSerial.
The debug on the motion sensor is as follows:
MCO:BGN:INIT NODE,CP=RSNNA--,VER=2.0.1-beta TSM:INIT TSM:INIT:TSP OK TSF:ASID:OK,ID=1 TSM:FPAR TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: !TSM:FPAR:NO REPLY TSM:FPAR TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: !TSM:FPAR:NO REPLY TSM:FPAR TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: !TSM:FPAR:NO REPLY TSM:FPAR TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: !TSM:FPAR:FAIL TSM:FAILURE TSM:FAILURE:PDT TSM:FAILURE:RE-INIT TSM:INIT TSM:INIT:TSP OK TSF:ASID:OK,ID=1 TSM:FPAR TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l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M:ID:OK,ID=1 TSM:UPL TSF:PING:SEND,TO=0 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 TSF:CHKUPL:FAIL !TSM:UPL:FAIL TSM:FPAR TSF:MSG:SEND,1-1-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSF:MSG:READ,0-0-1,s=255,c=3,t=8,pt=1,l=1,sg=0:0 TSF:MSG:FPAR RES,ID=0,D=0 TSF:MSG:FPAR OK,ID=0,D=1 TSM:FPAR:OK TSM:ID TSM:ID:OK,ID=1 TSM:UPL TSF:PING:SEND,TO=0 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1 TSF:MSG:READ,0-0-1,s=255,c=3,t=25,pt=1,l=1,sg=0:1 TSF:MSG:PONG RECV,HP=1 TSF:CHKUPL:OK TSM:UPL:OK TSM:READY TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100 TSF:MSG:SEND,1-1-0-0,s=255,c=0,t=17,pt=0,l=10,sg=0,ft=0,st=OK:2.0.1-beta TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=11,pt=0,l=13,sg=0,ft=0,st=OK:Motion Sensor TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0 TSF:MSG:SEND,1-1-0-0,s=1,c=0,t=1,pt=0,l=0,sg=0,ft=0,st=OK: MCO:REG:REQ TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 TSF:MSG:SEND,1-1-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2 TSF:MSG:READ,0-0-1,s=255,c=3,t=27,pt=1,l=1,sg=0:1 MCO:PIM:NODE REG=1 MCO:BGN:STP MCO:BGN:INIT OK,ID=1,PAR=0,DIS=1,REG=1 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0 0 TSF:MSG:SEND,1-1-0-0,s=1,c=1,t=16,pt=0,l=1,sg=0,ft=0,st=OK:0I don't know how to obtain debug from the Gateway Serial but as far as the GW messages on the console it looked as follows:
0;255;3;0;14;Gateway startup complete. 0;255;0;0;18;2.0.1-beta 0;255;3;0;11;SerialGateway 0;255;3;0;12;0.1 1;255;3;0;6;0 1;255;3;0;11;Motion Sensor 1;255;3;0;12;1.0 1;1;0;0;1; 1;1;1;0;16;0 1;1;1;0;16;0 1;1;1;0;16;0 1;1;1;0;16;0 1;1;1;0;16;0As you see it takes a fair amount of time (around 30-40 secs) to obtain the readings from the sensor. This happens each time I reset the sensor node but it works instantly if I reset the GW (i.e. the readings appear instantly after the reset). Is it expected behavior?
-
Hi,
I am wondering if I can just use the mySensors Lib to pass on the data via another connection. Currently I have a Loxone Controller which accepts UDP and TCP/IP connections (and others, but I chose these). As gateway I have an ArduinoMega and the network is running on RS485.
So my understanding is that I can setup the network with the mySensors code and all the data is collected by the gateway which passes the data via UDP to the controller. V.v. the controller sends the data to the gateway which passes tha data on to the correspondent node.
Is there any project similar to this?
Thank you very much for your help!
Best regards Kduino -
So what's with the DE+RE pins on that USB-RS485 converter? Will it even work in this configuration? I do have such converter but so far I've used the arduino as a SerialGateway to connect to RPi.
@Bart I do not know what You mean with DE+RE pins on the converter.
On the converter You connect A and B calbe from bus.
DE and RE pins fromMAX485 You connect with sealf and connect to pin in my case D2 on Arduino. -
I have a question, when I wont send do domoticz from Arduino presentation lightsensor I can send by serial something like this:
1;2;0;0;16;V_LIGHT_LEVELand domoticz will understend that is the lightsensor LUX ?
-
30 seconds sound like a long time.. Not sure what could be wrong. I don't have any test setup here unfortunately.
I was able to solve that long initialization problem with removing AltSoftSerial completely and using another Mega board on Serial1 serving as a GW. It looks like the AltSoftSerial on Nano was not working well with Serial1 on Mega.
Strange that although now it works almost instantly, the reading of data from the HA takes longer than before... Not sure what could be causing this.
It looks that these RS485 modules have the resistors already added between A and B cables and +5 and GND so I don't think that could be an issue.
-
Thanks for the feedback.
So how should the modules be inter-connected? Do you have time to create some drawing for the instruction page?
@hek
I will do the schematic once I solve all issues as I am still losing events while connected to Home Assistant. Need to check whether it is because of pymysensors library (Home Assistant side) or if there is still some GW <-> Sensors problem. At this moment my Sensors board has around 48 binary states one can set/read from the controller and at the same time they are changeable via input pins (falling edge toggles the switch).To give a quick overview of my setup:
2 x (MEGA 2560 + RS485 module)

I have the following connections for each mega+rs485 module:
- +5/GND connected to respective pins on rs485 module
- D2 connected to RE/DE
- D18 <-> RO
- D19 <-> DI
The A and B lines are connected to each other. (A-A, B-B). And most importantly I am using the above mentioned minor change in the MyTransportRS485.cpp to replace altSoftSerial with Serial1 (https://forum.mysensors.org/topic/1947/rs485-rs232-serial-transport-class-for-mysensors-org/99)
and just if anyone would like to try it here's the config I am using:
// Gateway: #define MY_RS485 #define MY_RS485_DE_PIN 2 #define MY_RS485_BAUD_RATE 9600 #define MY_GATEWAY_SERIAL // below not official for getting the Serial1 #define MY_RS485_SERIAL Serial1// Sensor node #define MY_DEBUG #define MY_RS485 #define MY_RS485_DE_PIN 2 #define MY_RS485_BAUD_RATE 9600 // below not official for getting the Serial1 #define MY_RS485_SERIAL Serial1 -
@Bart
Does it work with serial1 on mega2560?I can't get a single bit out of the harware serial1.
Is it only the smal patch in MyTransportRS485.cpp? -
@Bart
Does it work with serial1 on mega2560?I can't get a single bit out of the harware serial1.
Is it only the smal patch in MyTransportRS485.cpp?@karlheinz2000
Yes. Got it working with this patch. Although not reliably when other board was using the altsoftserial. -
Got it working too :smile:
Problem was: RX1 and TX1 labels on the chinese Mega2560 board are swapped. :angry:
All other RX/TX labels are right. -
Got it working too :smile:
Problem was: RX1 and TX1 labels on the chinese Mega2560 board are swapped. :angry:
All other RX/TX labels are right.@karlheinz2000 Are any of your boards using AltSoftSerial instead of HW serial? I was not able to get a reliable connection with software serial library....
-
I use a mega with hw-serial and a nano (gateway) with AltSoftSerial.
It works fine the last 24 hours. Still running...
I did not test other configurations. -
30 seconds sound like a long time.. Not sure what could be wrong. I don't have any test setup here unfortunately.
-
Hmm, strange. Wonder if this PR affected the behaviour of AltSoftSerial (in a good way).