Read RS485 bus from ESP32 #216
Replies: 12 comments 7 replies
-
This is similar to #203 it would be much easier to use a Pi Zero W or run cat5 from your panel to the server. RS485 can be several 100 ft. |
Beta Was this translation helpful? Give feedback.
-
You can install on server, (I even put a docker image out due to a request). but no using an esp (or anything else) at the RS485 to use as an IP bridge for the serial connection. It would introduce way too much latency. I’ve played with AqualinkD on ESP devices, and if you strip out all functionality that requires multiple threads it works well, but at that point AqualinkD looses all the functionality people like and it simply becomes a proxy for on/off commands. Cost of pi zero W (or equiv) is only a few $ more than a capable ESP device that it doesn’t seem worth the effort to peruse. And for one off it’s cheaper and easier to use a pi zero as no usb programmer or development knowledge is needed to get a pi up and running. |
Beta Was this translation helpful? Give feedback.
-
Ok. Understood. I’ve got an esp32 at my pool controller for reading ph/orp and dosing. Thought maybe I could incorporate this, but as you mentioned, probably not worth the effort. |
Beta Was this translation helpful? Give feedback.
-
Be best to simply add a pi zero and move the esp functionality to that if you only want one device. |
Beta Was this translation helpful? Give feedback.
-
Sure. Here is a writeup I did on it a while back https://community.home-assistant.io/t/swimming-pool-chemical-dispenser/205561/112?u=jm123. It has changed a bit since--I dont use the Atlas Scientific pumps anymore (they didnt last). I use this probe from Atlas Scientific https://atlas-scientific.com/kits/ph-kit/ for pH and this probe for ORP https://atlas-scientific.com/kits/orp-kit/. They communicate on the i2c bus with an esp32 currently running tasmota which sends the data to Home Assistant via MQTT (planning to switch over to ESP Home eventually). The pH probe works great, very accurate. I calibrate it about once a year at the beginning of pool season. The ORP probe is not perfect--it is mostly useful for telling me when my water has a good level of chlorine, and the readings will start to drop off when the chlorine levels get low (usually because my chlorine tank runs empty). I am told the ORP probe also wont work well if you have high CYA. I keep mine around 40-50. I also have a couple of stenner peristaltic pumps which I use to dose acid and chlorine. These pumps are 24v attached to a relay, also run with the esp32. For acid, I bought the pentair intellichem acid tank already with the pump. I'm sure there is a cheaper way to do this one, but it works well, and has a way to vent the tank away from your pad so you dont have any corrosion. For the chlorine, I bought the same pump on the intellichem but put it in a seperate housing and it feeds from 2.5G chlorine tanks I buy from the pool store, |
Beta Was this translation helpful? Give feedback.
-
Any experience with these RS485 to wifi adapters? |
Beta Was this translation helpful? Give feedback.
-
I have not. |
Beta Was this translation helpful? Give feedback.
-
I have a similar version the 2nd adapter listed above for tapping in to my PV systems Inverter communication to the cloud monitoring box I have to use. LOTS of great information not unusually provided to customers. The devices above can be used in a couple of different ways. As Modbus RTU to IP , as well as RS485 Client/Server via UDP and TCP. I use the RS485 UDP client/server functions as my older inverters were not strict Modbus. This works well where I have 2 inverters behind the 'server mode device' which I run a UDP server that I poll from a docker container running the app. For aqualinkd, you will need to run a virtual serial driver on your host running the aqualinkd application and connect that to the device, or you will need to get two devices and use the USB-RS485 cable to a local device acting as the client, and the remote device on the bus acting as a server. What I think will be need to be tested regarding making it work with AqualinkD is if some sort of multi-host functionality may be needed if you also have iAqualink or other controllers. I am not sure if this is required in Jandy world, but when I get to this project I had planned to test just moving my iAqualink and the AqualinkD devices behind the serial converter device and hoping it would work. sfeakes has mentioned several times there are strict timing dependencies with Aqualink, which if the device adds does weird stuff with the protocol conversion it could add a few ms to the data path. Still a lot faster than the RS485 serialization delay, but something to consider. Also I would avoid the Wifi serial devices if you need something close to real time continuous control like AqualinkD/RS requires. |
Beta Was this translation helpful? Give feedback.
-
I think the main problem with this approach and any Jandy device is the timing. RS485 protocol is basically the master sends a message with an specific device ID in it, then expect an acknowledgment reply from that device, then send another message to a different ID (and again expect a reply). If the device doesn't reply, it assumes it's dead. So if the device reply's too late, ie the master has already sent the next message, the device is basically replying to the wrong message, and this can cause havoc. Depending on many things, I think you have about 60 milliseconds to reply to a Jandy message, I try to keep it under 20ms. So in the above consider
Then Aqualinkd passes message and creates reply. That then has to go back over that convoluted path. All that happening in under 60ms, (from master send to master receives reply) is a tall order. Since AqualinkD has a whole host of ways to interface, your best bet would be to modify the source to receive and send the TCP/IP message directly and cut out the second adapter. But over wifi, I'm still not sure you can guarantee latency wouldn't effect the timing. |
Beta Was this translation helpful? Give feedback.
-
I gave up trying to make this more complicated than necessary and just used a pi zero as you recommended... |
Beta Was this translation helpful? Give feedback.
-
I am going to write this up separately, but I have an esp32 that I use for my "digital pool filler", which talks to a "hub" running on a Raspberry Pi 4. They have always used mqtt to communicate, as there are not that many concerns with timing or latency. The Arduino device has a couple of water level sensors attached, and has logic to control a (soft open/close) valve, so the whole thing can be autonomous. I have just done an interface to aqualinkd to tap into the mqtt messages and forward them to the hub described above (so as not to burden the Pi 4 running aqualinkd). I have web and mobile access to my hub through a framework I have developed (details to come). I wanted to have the Pool Filler and the other pool devices all reporting on a single page on my app, and the mqtt bridge (forwarding) worked very well for this. I have no real need at this point, but it is entirely feasible (IMO) to hook up basic aqualinkd commands (like Filter Pump on/off), and send these back through the aqualinkd mqtt message processor. The bridge software would just need to have a "return lane" added as it is only one way right now (with aqualinkd as the source and pool filler hub as the destination). All is working well so far, and I even have some notifications going to my iPhone for potential error or (SWG) fault conditions. |
Beta Was this translation helpful? Give feedback.
-
I came to this thread through the lens of viewing the microcontroller as an asset and not a liability. I recently implemented a Raspberry Pi interface to a security panel that had some pretty bad timing-related consequences if you didn't get the timing right. But microcontrollers -- especially ones dedicated to the task -- have excellent timing properties if they aren't having to multitask. Bottom line -- by moving the entire serial interface code onto the microcontroller, and having that be aware of the entire state of the other device, while treating the Raspberry Pi as a "slow" client that could talk at its own pace -- I was able to achieve EXCELLENCE in the timing that was absolutely unmatchable with the Raspberry Pi -- consistently complying with response timing requirements to the single millisecond. If we viewed an ESP32 as the low-level serial interface with the responsibility for managing timing, the entire solution gets more reliable. (Trivia item: for my other interface, I used a different microcontroller with no wireless capabilities, just multiple serial ports, so I never had any concern that a network stack I didn't write or control could have any influence on my timing. The analogous setup would be to have an ESP32 talk to the network, and some dumber dedicated microcontroller go between the ESP32 and RS485) |
Beta Was this translation helpful? Give feedback.
-
Is it possible to install the Aqualinkd on a server and then use an esp32 at the pool panel to read/relay commands to the aqualinkd service?
Beta Was this translation helpful? Give feedback.
All reactions