dkjonas / Wavin-AHC-9000-mqtt

Esp8266 mqtt interface for Wavin AHC-9000/Jablotron AC-116
MIT License
85 stars 35 forks source link

Move configuration of MQTT server port #18

Closed paller closed 4 years ago

paller commented 4 years ago

Move MQTT_PORT into configuration header for easier configuration as not all MQTT brokers use the default port.

Changed serial configuration as Serial.begin(baud) will default to using 8 bits with 1 stop bit while Wavin communicates 8 bits and 2 stop bits.

Communication will sort of work with one stop bit but have a high error rate. This is easily mitigated by simply trying one more time but I find that using 2 stop bits has zero errors.

jascdk commented 4 years ago

Thanks Paller - I will try to change as you described in my setup, and let you know how it goes;) BTW I have for long time wanted to have some kind of wifimanager and OTA (over the air support) for uploads and such attached in the code. It would be cool not to have hardcoded credentials. I don't have the skills to code that, but maybe you could contribute to that? I have tried with this library https://github.com/tzapu/WiFiManager but I screwed up the code most of the time :D

paller commented 4 years ago

My hardware setup at the moment does not easily let me flash any firmware, so do note that my change is untested. However, I have previously been running a USB<->RS485 converter on a Pi board with my Python code. The difference between 1 and 2 stop bits were significant.

It doesn't seem too hard to add a web server with a dynamic configuration page. When I get my WeMos D1 Mini up and running I will have a look at it.

I did a quick search for OTA update support when using Arduino Core but didn't really like any of the Arduino sketches I found. Maybe https://github.com/esp8266/Arduino as you mentioned has a better solution. I hope it does as I'm quickly getting tired of running back and forth to the Wavin unit in order to update the ESP board.

jascdk commented 4 years ago

@paller Ahh i see. Well I just made the changes to the code according to your PR. I does not work on my setup - i cannot get any values through MQTT:( Maybe I did it wrong - but lets see when others test it on their system. My system is based exactly on the schematic on this page. What unit do you use? The regular 16 channel unit AHC 9000?

It would be so nice, if you could implement the wifimanager library into the code - I know it is not often you change broker IPS´s, wifi pass and so on, but it happens and for this it would be a great addition!

For OTA I mostly found the examples on the repository you mentioned - I think it is the same examples that are in the wifimanager examples page.

paller commented 4 years ago

I finally got it working on a Wemos D1 Mini with an unbranded cheap serial converter. It's the same hardware I used it my previous setup with esp-link sending modbus commands over TCP. I simply can't find the reason why, but with esp-link and when using a USB-to-RS485 dongle I have to use 2 stop bits. Running this software instead it only works with 1 stop bit.

I will change to pull-request to only include the relocation of MQTT server port.

dkjonas commented 4 years ago

Merged. The documentation from Wavin states 1 stop bit, and I have not had any problems with this. In WavinController.cpp line 90 I have a small delay to ensure last char is transmitted before changing direction of the transceiver. That might explain the difference you are seeing.

jascdk commented 4 years ago

@paller did you look at the OTA and WiFi manager capabilities for this project ?

paller commented 4 years ago

@jascdk I did briefly look at adding OTA updates and it should be pretty simple. I just got sidetracked by creating a PCB for my setup. As I'm waiting for it to arrive from JLCPCB I might look at OTA again.

jascdk commented 4 years ago

@paller nice looking PCB you got there :) Please share your experiences with it :) Looking forward to some kind of OTA wifimanager thingy:)

paller commented 4 years ago

The OTA part seems easy. A simple copy/paste of the example sketch is working on my setup now, source here. The only thing I modified was the Serial.swap() at OTA start. On my Wemos setup it's required else the serial debug/logging will be sent to the Wavin controller.

paller commented 4 years ago

@dkjonas would you like a formal pull-request for the OTA feature?

dkjonas commented 4 years ago

If you make a PR, please move the ota functionality to a separate file, and make it possible to disable it with a define. I know others (including myself) are using the eps for multiple different jobs, so I would like to keep the source as simple as possible.

Maybe the Serial.swap or the debug info could also be configurable, so that it will also work for people who are not able to swap on their hardware.

Finally make sure that you are allowed to use the code you copied, and that the license of it is compatible with MIT.

jascdk commented 4 years ago

Hi

As you mention you use your esp for other things . I’m a little curios - could you explain what you and others use the esp for else than running this code :)?

Jacob

dkjonas commented 4 years ago

I use it for reading values from my utility meters. I know others are using it for various data logging purposes.