Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MQTT notifications #113

Merged
merged 4 commits into from
Jun 6, 2020
Merged

Conversation

jbaudoux
Copy link
Contributor

@jbaudoux jbaudoux commented Mar 22, 2020

Send MQTT messages. This implements this feature #103
Events can be subscribed (like IFTTT).
Note that this PR does not allow for controlling an OpenSprinkler unit but rather generating notifications when its activity changes.

Supported platforms: OSPI, OS3.0, OS3.2
On OSPI, it requires libmosquitto.

I also rewrite some IFTTT string message generation to use the standard sprintf instead of non-standard itoa.

This replaces my initial PR: #102
This replaces enhancement PR done by PeteBa: #108 Thanks to PetaBa for the review and improvements as well as the implementation for OS3

OSPI instructions

If anyone wants to try out the PR. I suggest using a new SD card with the latest Raspbian Buster so that you can go back to your original setup when finished trying.

Firstly, ensure you have the right dependencies:

pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install git
pi@raspberrypi:~ $ sudo apt-get install libmosquitto-dev

Next, clone the OpenSprinkler repository and download the PR branch:

pi@raspberrypi:~ $ git clone -b ospi-mqtt https://github.com/jbaudoux/OpenSprinkler-Firmware.git
pi@raspberrypi:~ $ cd OpenSprinkler-Firmware/

The PR is meant to be used with an equivalent PR on the App so that you can configure your MQTT server IP and Port address via the UI but if you just want to try this out then you can change line 567 in main.cpp from os.mqtt.begin(); to os.mqtt.begin("server_ip", server_port, 1); where you replace server_ip with the ip address of your MQTT Broker and server_port with the port number (usually 1883). Note that the "1" is needed to set mqtt active.

Then build and run:

sudo ./build.sh
sudo .OpenSprinkler

You should see MQTT messages arrive in your broker when you turn stations on/off. let me know if you have any issues.

OS3.x limitations

The connection to the MQTT broker in this implementation is not asynchronous. This is because WiFi and Wired connection is supported and current arduino core doesn't support yet native wired connection (note there is a wip on core for esp8266: esp8266/Arduino#6680) This requires to have a reliable connection to your MQTT broker otherwise your OS system could hang trying to reconnect until timeout.

This was referenced Mar 22, 2020
@PipeDeveloper
Copy link

PipeDeveloper commented Mar 22, 2020

Nice work!, i just read the whole code and seem to be good, enough to supply the basic information. Just one question, on my case my MQTT broker, every clients connects via an username and a password. To connect it requeries at least 4 fields, IP, port, user, password.
It's possible to add this to the client loging information? thank you!

@Nick-Adams-AU
Copy link

Thanks for the great work. Any reason why this is limited to OSPI? MQTT works fine with other platforms.

@jbaudoux
Copy link
Contributor Author

Thanks for the great work. Any reason why this is limited to OSPI? MQTT works fine with other platforms.

OS3.0, OS3.2 are also supported. I updated the description

@jbaudoux
Copy link
Contributor Author

If you have OS3 install instructions, I'll add them in the description (cc @PeteBa)

@nagyrobi
Copy link

Please add Water Level % and also Operation status (enabled/disabled as on/off) to MQTT notification.

@zachfi
Copy link

zachfi commented May 12, 2020

Hello, this looks interesting. Does this work follow the home assistant topic spec and json payload?

@wifi75
Copy link

wifi75 commented May 19, 2020

My broker mqtt need User and password...

@PipeDeveloper
Copy link

@xaque208 if you're able to connect to Mosquito Broker MQTT provided by home assistant then yes, bu it needs an username and password, just like @wifi75, so you cant connect just with this pull request. Those fields are missing.

@vsoltan
Copy link

vsoltan commented May 19, 2020

Thanks for the great work. Any reason why this is limited to OSPI? MQTT works fine with other platforms.

OS3.0, OS3.2 are also supported. I updated the description

OSPI compilation works flawlessly, but I'm having a little bit of trouble with the demo version:

Building OpenSprinkler...
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libmosquitto.so when searching for -lmosquitto
/usr/bin/ld: cannot find -lmosquitto
collect2: error: ld returned 1 exit status
Done!

I suspect this is happening because the mosquitto lib defaults to 64 bit for ubuntu. Are you aware of any workarounds for this? Eclipse doesn't seem to have a multilib version available for download for any OS other than windows.

Copy link
Member

@rayshobby rayshobby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for the contribution!

@rayshobby rayshobby merged commit f7361b1 into OpenSprinkler:master Jun 6, 2020
@wifi75
Copy link

wifi75 commented Jun 6, 2020

@rayshobby
I update to latest master version... but in Home assistant MQTT I have error:
image

@rayshobby
Copy link
Member

Please, the firmware has not been officially released. You need the App change to go together with the firmware change. Could you just be a bit patient and wait for the official announcement?

@wifi75
Copy link

wifi75 commented Jun 7, 2020

@rayshobby I used the gui app version for configuration, nut not work...
sure I will waiting the official version, maybe there is bugs in this..
Thank you

@jbaudoux
Copy link
Contributor Author

jbaudoux commented Jun 8, 2020

Looks great. Thanks for the contribution!

Thanks @rayshobby for the merge in master ;)

@timbodeit
Copy link

What is the goal behind the error regarding MQTT_KEEPALIVE?

#if MQTT_KEEPALIVE != 60
#error Set MQTT_KEEPALIVE to 60 in PubSubClient.h
#endif

Is the user supposed to make changes in headers from downloaded dependencies?

Is there any reason not to set it like this:

#define MQTT_KEEPALIVE 60
#include <PubSubClient.h>

Also, I couldn't find the new dependency on PubSubClient to be documented anywhere.

@jbaudoux
Copy link
Contributor Author

jbaudoux commented Jun 8, 2020

Please have a look at this proposal #134 and give comments there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants