π¬ Building a wired RS485 sensor network
-
Hello again. I've soldered this two pull-ups resistors like @ArduiSens wrote before. Now I think the network works much much better but after 24 hours of using something hangs and i can't turn of the light with buttons and with OpenHab also. I think the gateway freezing because after I reset only gateway all starts to work normal when i'm pressing wall switches. I need to reboot controller because after gateway reset OpenHab won't communicate with the gateway... Please take a look at my gateway sketch:
// Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached // #define MY_RADIO_NRF24 // #define MY_RADIO_RFM69 #define MY_NODE_ID 0 // Enable RS485 transport layer #define MY_RS485 // Define this to enables DE-pin management on defined pin #define MY_RS485_DE_PIN 2 // Set RS485 baud rate to use #define MY_RS485_BAUD_RATE 9600 // #define MY_GATEWAY_MQTT_CLIENT // Enable gateway ethernet module type #define MY_GATEWAY_W5100 // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal) // #define MY_W5100_SPI_EN 4 // Enable Soft SPI for NRF radio (note different radio wiring is required) // The W5100 ethernet module seems to have a hard time co-operate with // radio on the same spi bus. #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD) #define MY_SOFTSPI #define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MOSI_PIN 15 #endif // When W5100 is connected we have to move CE/CSN pins for NRF radio // #ifndef MY_RF24_CE_PIN // #define MY_RF24_CE_PIN 5 // #endif // #ifndef MY_RF24_CS_PIN // #define MY_RF24_CS_PIN 6 // #endif // Enable to UDP // #define MY_USE_UDP #define MY_IP_ADDRESS 192,168,0,66 // If this is disabled, DHCP is used to retrieve address // Renewal period if using DHCP //#define MY_IP_RENEWAL_INTERVAL 60000 // The port to keep open on node server mode / or port to contact in client mode #define MY_PORT 5003 // Controller ip address. Enables client mode (default is "server" mode). // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 70 // The MAC address can be anything you want but should be unique on your network. // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use. // Note that most of the Ardunio examples use "DEAD BEEF FEED" for the MAC address. #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED // Set this node's subscribe and publish topic prefix // #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out" // #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in" // Set MQTT client id // #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" // Enable inclusion mode // #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) // #define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button //#define MY_INCLUSION_MODE_BUTTON_PIN 3 // Set blinking period #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Flash leds on rx/tx/err // Uncomment to override default HW configurations //#define MY_DEFAULT_ERR_LED_PIN 7 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin #if defined(MY_USE_UDP) #include <EthernetUdp.h> #endif #include <Ethernet.h> #include <MySensors.h> void setup() { } void loop() { } -
@gohan I'm using soft SPI ? Where ? I taught that there are
#if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD) #define MY_SOFTSPI #define MY_SOFT_SPI_SCK_PIN 14 #define MY_SOFT_SPI_MISO_PIN 16 #define MY_SOFT_SPI_MOSI_PIN 15 #endifso when #define MY_W5100_SPI_EN 4 is commented I'm using hardware SPI ? What should i change than ? Comment the whole #if .... part ??
-
Forget it, I was on mobile and couldn't see well the code. Do you have IDE, boards definitions up to date? Did you try latest version of mysensors in development branch?
@gohan I have IDE 1.6.11 and boards definition 1.6.11 because on newer boards definition I've got boot loop on gateway. I'm using 2.1.1 MySensors library. Maybe I should mention that I can ping my gateway without any problems, only rs485 part seems not responding..
-
Hello again. After a week of thinking and hard work i finally got RS485 network working very close to what I want. I've done everything like it was mentioned here before. Fully bus-like network, termination only on both ends of line and pull-up and pull-down on the gateway. I also change MySensors library to newest 2.1 beta branch. All nodes working very good for last month but some times one node hanging and I can't control it via OpenHab or built in switch. I don't know what cause this behavior. I turn on watchdog timers in every nodes and theoretically when node hangs, watchdog should reboot arduino after 8 seconds. Practically it won't reboot my node.. It seems like the node don't really hangs but the communication stops.. Is it possible that one node can loose connection while other nodes on the same bus/wires working like a charm ?
-
Hello again. After a week of thinking and hard work i finally got RS485 network working very close to what I want. I've done everything like it was mentioned here before. Fully bus-like network, termination only on both ends of line and pull-up and pull-down on the gateway. I also change MySensors library to newest 2.1 beta branch. All nodes working very good for last month but some times one node hanging and I can't control it via OpenHab or built in switch. I don't know what cause this behavior. I turn on watchdog timers in every nodes and theoretically when node hangs, watchdog should reboot arduino after 8 seconds. Practically it won't reboot my node.. It seems like the node don't really hangs but the communication stops.. Is it possible that one node can loose connection while other nodes on the same bus/wires working like a charm ?
-
Hi! My problem still exist. I switched to newest MySensors Library and to HWSERIAL and some nodes acts the same as before... Now i'm thinking that maybe its related to DE_PIN 2 ?? Someone tried to switch to other pin for Enable function for RS485 ?? Now after almost a year I'm thinking about changing my transmission from wired RS485 to wireless nRF.. I choose RS485 because of its stability (thats what I taught over a year ago ). Now I think that RS485 its a piece of garbage..
-
Hi! I think I came up with the solution for all our problems but I don't know if it is worth and possible at all. The thing is that RS485 isn't a multimaster bus, thats what we all know. So the best option is to turn the gateway in to master and all other nodes to slaves. I'm thinking if there are any possibilities to make the gateway to ask nodes in the order one by one for its states (child states). The nodes can only talk to the gateway when the gateway ask for their states. This process should take place in endless loop in the highest possible speed (depending on the count of nodes in the network). I think that in this option the baud rate matters, cause higher baud rates makes the time of a single loop shorter minimizing the delay that may occur in the networks with many nodes. Maybe I'm reinventing the wheel now and this type of transmission needs to rewrite all MySensors protocols..
-
Hi! I think I came up with the solution for all our problems but I don't know if it is worth and possible at all. The thing is that RS485 isn't a multimaster bus, thats what we all know. So the best option is to turn the gateway in to master and all other nodes to slaves. I'm thinking if there are any possibilities to make the gateway to ask nodes in the order one by one for its states (child states). The nodes can only talk to the gateway when the gateway ask for their states. This process should take place in endless loop in the highest possible speed (depending on the count of nodes in the network). I think that in this option the baud rate matters, cause higher baud rates makes the time of a single loop shorter minimizing the delay that may occur in the networks with many nodes. Maybe I'm reinventing the wheel now and this type of transmission needs to rewrite all MySensors protocols..
@nofox absolutely that is one of the problems. Polling as you describe could be a fix, another is having each node listen before transmitting, there is a (not mysensors) library that does that, CAN bus( a mutli master 485 comaptible bus) is another option. I think that running a common ground to all the rs485 adapters is also wise. This is all in theory as I havent wired up my home yet....
-
@nofox absolutely that is one of the problems. Polling as you describe could be a fix, another is having each node listen before transmitting, there is a (not mysensors) library that does that, CAN bus( a mutli master 485 comaptible bus) is another option. I think that running a common ground to all the rs485 adapters is also wise. This is all in theory as I havent wired up my home yet....
another is having each node listen before transmitting
How would you describe this functionality in MySensors rs485 code?
https://github.com/mysensors/MySensors/blob/f5ed26c778c18107d1516bd86704f8c8f99ff571/hal/transport/RS485/MyTransportRS485.cpp#L246
If I'm reading the code correctly it is exactly reading the bus and making sure no other node is sending before sending anything.
The place where collision can happen is those 5 microseconds what the node is waiting to get driver tx enabled pin up.So the collision avoidance is already there. So what MyS R485 transport is missing is collision detection and recovery from collision.
CAN bus( a mutli master 485 comaptible bus) is another option.
Its disadvantage is small payload size.
@nofox Its quite like how the Modbus works. By polling.
I think there is some better ways to do that. Check these out from google:- RS-485 Token ring
- uLAN
- RS-485 RRP (Round Robin Protocol)
- CSMA/CA
-
I think you have found most everything that I have. Something akin to csmacd is what I was thinking. Listen, transmit, back off for random time if a collision still happens. Of course full duplex rs485 is another option, hard to find off the shelf modules.
I think this is the library I had found before.
https://github.com/MichaelJonker/HardwareSerialRS485/wiki -
https://github.com/dukelec/cdbus_doc
This one has some is interesting, not sure if it does multi master or not. There are a few projects that seem to do multimaster/collision avoidance, the trick it to find one with low enough overhead and automatically retransmits if there is a failure, and for this project isolates this enough that my sensors doesnt need restructuring.Good wiring is crucial so you can use higher speeds. The common ground wire in addition to the differential signals seems almost required.
-
https://github.com/gioblu/PJON/wiki
Some works for MySensors done:
https://forum.mysensors.org/topic/3977/transport-based-on-single-wire-pjon-protocol -
But PJON uses completely sw bit by bit sending or HW sending with bad bus arbitration.
My idea - combination CAN bus like arbitration and UART message sending.
With ACK possibility.Time T1 ( two bytes send time for example )
Node sends message and waits T1 time for ACK.
Receiving node must send ACK within T1 interval.Node, witch needs send message listens bus.
BUT not by HW UART or SoftwareSerial - use directo IO operation.
If recognize bus free time greater then T1, it start sending its own ID.
BUT again not by HW UART or SoftwareSerial - but bit by bit by direct IO pin operation.
And listen if bit I am sending is bit I am receiving.
If not - it means, that other node with higher priority ( lower ID ) is sending - then immediately stop sending other bit and wait for next bus free T1 interval.
If yes - bus is free for me end send my message normally by UART ( HW or SW, maybe with 9 bit addressing support - time less than T1 between characters allowed).
Wait max T1 time for ACK.CAN bus driver usage TJA 1050 or MCP2551 - no DE RE pins.
-
I have the problem that I always get this error: !TSM:FPAR:NO REPLY
Once it worked briefly yesterday.
What have I tried everything?
All hardware exchanged - without success.Now I have just written two small scripts that send RS485 back and forth. without problems. So wiring has to fit. I spent then in the serial montior the data which the node sends me, there comes some. Then I once tried to display the data that sends the GW, because nothing comes.
Does anyone have an idea why my GW does not answer?
-
I have the problem that I always get this error: !TSM:FPAR:NO REPLY
Once it worked briefly yesterday.
What have I tried everything?
All hardware exchanged - without success.Now I have just written two small scripts that send RS485 back and forth. without problems. So wiring has to fit. I spent then in the serial montior the data which the node sends me, there comes some. Then I once tried to display the data that sends the GW, because nothing comes.
Does anyone have an idea why my GW does not answer?
-
| / |_ / | ___ _ __ ___ ___ _ __ ___
| |/| | | | _ \ / _ \_ \/ __|/ _ \|_/ __|
| | | | || || | / | | _ \ _ | | _
|| ||_, |/ ___|| ||/_/|| |/
|__/ 2.3.0-alpha17 MCO:BGN:INIT NODE,CP=RSNNA---,VER=2.3.0-alpha
26 TSM:INIT
27 TSF:WUR:MS=0
29 TSM:INIT:TSP OK
30 TSM:FPAR
49 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
2056 !TSM:FPAR:NO REPLY
2058 TSM:FPAR
2075 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
4083 !TSM:FPAR:NO REPLY
4085 TSM:FPAR
4103 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
6111 !TSM:FPAR:NO REPLY
6113 TSM:FPAR
6130 TSF:MSG:SEND,255-255-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:0;255;3;0;9;0 MCO:BG
0;255;3;0;9;29 MCO:BGN:INIT OK,TSP=1
0;255;3;0;9;0 MCO:BGN:INIT GW,CP=RSNGA---,VER=2.3.0-alpha
0;255;3;0;9;5 TSM:INIT
0;255;3;0;9;7 TSF:WUR:MS=0
0;255;3;0;9;9 TSM:INIT:TSP OK
0;255;3;0;9;12 TSM:INIT:GW MODE
0;255;3;0;9;15 TSM:READY:ID=0,PAR=0,DIS=0
0;255;3;0;9;18 MCO:REG:NOT NEEDED
0;255;3;0;14;Gateway startup complete.
0;255;0;0;18;2.3.0-alpha
0;255;3;0;9;22 MCO:BGN:STP
0;255;3;0;9;29 MCO:BGN:INIT OK,TSP=1