Mqtt server

Related to the Portal
Post Reply
fnick2812
Posts: 4
Joined: Sun May 16, 2021 5:38 am

Mqtt server

Post by fnick2812 »

Hi, I am currently experimenting RA-standard with esp-link. However, it seems that my esp32 could not send msg to ReefAngel server. I am testing step by step to check where the problem is. And one of the step is testing ReefAngel server. The test is simple only. I used <hivemq>/websocket-client/ and sent a mocked msg as follow "T1:500" to the ReefAngel server.

Here are the mqtt server settings on hivemq

- host=cloud_dot_reefangel_dot_com
- port=1883
- clientId = "RA-fnick2812"
- username = "fnick2812", password = xxxx

Here are the msg to publish

- topic = "fnick2812/out"
- payload = "T1:500"

I wonder if the above settings are correct. I noticed the following behaviors
- if i change port = 9001 --> the client could connect to the server but could not publish msg. What the 9001 port is for?
- one or 2 months ago, i tried host = "104.36.18.211" and used the generated code by webwizard for cloudWifi. It could link to the server and sent sensors' values successfully. However if i used the IP for the current test, it was not connected. I am confused which one is the correct one. I looked up in ReefAngel github and knew that cloud_dot_reefangel_dot_com~{ 69, 198, 171, 165 }. Am I correct?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

You should use the cloud_dot_reefangel_dot_com and I am pretty sure it is port 9001.
Roberto.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

I am using MQTT through Home Assistant and here's what I know:

1. Recommend you ensure you have Uapp up and running at least in web browser (http://forum.reefangel.com/uapp/) There is also an app that I later installed to mess around with. More details here: https://forum.reefangel.com/viewtopic.php?f=8&t=4674

2. In Home Assistant, I added the MQTT Mosquito broker integration and configured with:
Broker: cloud.reefangel.com
Port: 1883
Username: wolfpack
Password: (same password used in uapp)

You can test this in Mosquitto broker by listening to any of these topics:
# to get all payloads
wolfpack/in to get all payloads coming through "in" which are usually commands sent (override on, off, auto and mode changes)
wolfpack/out to get all payloads coming from "out" which are the PH, T1, T2, T3 payloads

3. In Home Assistant /config/configuration.yaml file, if you want to see the feeds as a sensor, you can add these items ("wolfpack" is my cloud username):

Code: Select all

sensor:
  - platform: mqtt
    name: "Reef Angel Out Feed"
    state_topic: "wolfpack/out"
  - platform: mqtt
    name: "Reef Angel In Feed"
    state_topic: "wolfpack/in"
This will create a sensor called reef_angel_out_feed and reef_angel_in_feed. I used these for testing, but I like to leave it up to see the flow of messages as I try to see capability that I might be missing.

4. To break down feeds into useful information, I also created these sensors in Home Assistant configuration.yaml file:

Code: Select all

  - platform: mqtt
    name: "Aquarium PH" #this should create a sensor named sensor.aquarium_ph
    state_topic: "wolfpack/out"
    value_template: >-
      {% if 'PH' in value %}
        {{value.split(':')[1]|float/100 }}
      {% else %}
        {{states('sensor.aquarium_ph')}}
      {% endif %}
      
  - platform: mqtt
    name: "Aquarium T1" #this should create a sensor named sensor.aquarium_t1
    unit_of_measurement: "°F"
    state_topic: "wolfpack/out"
    value_template: >-
      {% if 'T1' in value %}
        {{value.split(':')[1]|float/10 }}
      {% else %}
        {{states('sensor.aquarium_t1')}}
      {% endif %}
      
  - platform: mqtt
    name: "Aquarium T2"
    unit_of_measurement: "°F"
    state_topic: "wolfpack/out"
    value_template: >-
      {% if 'T2' in value %}
        {{value.split(':')[1]|float/10 }}
      {% else %}
        {{states('sensor.aquarium_t2')}}
      {% endif %}
  
  - platform: mqtt
    name: "Aquarium T3"
    unit_of_measurement: "°F"
    state_topic: "wolfpack/out"
    value_template: >-
      {% if 'T3' in value %}
        {{value.split(':')[1]|float/10 }}
      {% else %}
        {{states('sensor.aquarium_t3')}}
      {% endif %}
      
  - platform: mqtt
    name: "Aquarium Relay 1"
    state_topic: "wolfpack/in"
    value_template: >-
      {% if 'r:110' in value %}
        Override OFF
      {% elif 'r:111' in value %}
        Override ON
      {% elif 'r:112' in value %}
        AUTO
      {% elif is_state("sensor.aquarium_relay_1", "unknown")  %}
        AUTO
      {% else %}
        {{states('sensor.aquarium_relay_1')}}
      {% endif %}
From this, whenever "wolfpack/in" or "wolfpack/out" brings in items that match the format I am looking for, I get updates for PH, T1, T2, T3, and all my relays (I just showed Relay 1 from expansion box 1 here -- note on RA Star, all relay boxes are expansions).


By changing things in Uapp and listening on the mosquito broker, I've found the following payloads and format. These only come in on changes to the value so initially my sensors are "unknown" states until they see a value come in to fill in PH, T1, etc.

wolfpack/out:
PH:762 (PH is most common usually flowing every second usually)
T1:771 (temperature probe 1)
T2:707 (temperature probe 2)
T3:761 (temperature probe 3)

wolfpack/in: (commands you can send)
noot:1 (reboots controller)
mt:0 (clear ATO)
10 (lights on mode)
11 (lights on mode: cancel)
r:99 (refresh -- does nothing for me in Home Assistant. I had hoped it would force push all values, nope)
r:150 (override off expansion 1, relay 5)
r:151 (override on expansion 1, relay 5)
r:152 (auto mode expansion 1, relay 5)
mf:1 (feeding mode: on)
mf:0 (feeding mode: off)
mw:1 (water change mode: on)
mw:0 (water change mode: off)

What I'd still love to know is how do I get state changes for all relays and float switch changes? So far I can only override relays and I never get any state change or see anything different for on/off while in auto mode.
Last edited by wolfpack on Fri Mar 18, 2022 10:52 pm, edited 1 time in total.
fnick2812
Posts: 4
Joined: Sun May 16, 2021 5:38 am

Re: Mqtt server

Post by fnick2812 »

tested with hivemq, it can work with port 9001 only. I knew about the port 9001 when i searched through this forum but another thread long ago. But how come the port 1883 is working for wolfpack haha!? Should i set to 9001 or 1883 for the controller @admin?

I was confused between forum_reefangel_com/uapp/ and forum_reefangel_com/portal.php. I totally forgot about the uapp page as I tried it few months ago. In the recent try, i just looked into the portal but did not see any update. Thanks for reminding me.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

In hivemq, I have to use 9001 also. But in mosquito broker in Home Assistant, I use 1883. Odd and I have no idea why. I would love to know if you find an MQTT message or something to tell the system to push payloads for all switch statuses or status changes.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

Any info on getting float switch status or regular relay status (not just overrides)?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

There is a command just like r99.
Look for it on the libraries or the source code for Uapp.
I can only look into this on a week or so.
Roberto.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

Thanks Roberto, but I've tried r:99 in "wolfpack/in" which I think triggers a refresh in Uapp but does seemingly nothing in the "out" or "in" topics. Is there another topic?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

Watch the communication form Uapp and controller using the developer tools on Chrome browser
Roberto.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

Or check the source code. I know there is a command
Roberto.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

Try this:

Code: Select all

all:0
on /in channel
Roberto.
fnick2812
Posts: 4
Joined: Sun May 16, 2021 5:38 am

Re: Mqtt server

Post by fnick2812 »

Oops so many replies. My original issue is resolved. The correct port s 1883. Don't test with hivemq, better with mosquito if u wanna check server/client comm. It happenned that I had a reef angel standard. By making it work with esp-link, it can be updated OTA. But I stripped off many features from the original source too, only left with relay, temperature, ato. I was amazed how much code u can put inside an Uno, learned alot. Thanks for helping.
fnick2812
Posts: 4
Joined: Sun May 16, 2021 5:38 am

Re: Mqtt server

Post by fnick2812 »

When u first view ur uapp, uapp will send an 'all:0' to ur RA controller after the mqtt connection is established. Your controller will reply with a bunch of msg for different functions (relay, temperature, ato)
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

thanks! "all:0" definitely produces a bunch of info, but how do we get updates to see when things change without sending the command every minute?
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

Follow up, here are all the responses I get when I send the "all:0"

Code: Select all

C0:0
...
C7:0
R:0
ROFF:255
RON:0
T1:771
...
T3:773
PH:814
T4:0
...
T6:0
ORP:0
SAL:0
PHE:0
PAR:0
CEXP0:0
...
CEXP7:0
ROFF1:119
Questions:
1: why does it call out expansions as 0-7 instead of 1-8?
2. what are R? RON? ROFF?
3. where's the ATO float switch info?
4. I don't see how we get to know if a port is on or off. Even when I set override off for exp box 1, port 8, I get "ROFF1:119" ... how does that make any sense?? That and I see other ports were on when I ran all:0, but still no indication unless it all went by before I could see it.
5. ^what I asked above -- how do I get this info without sending the all:0 command every minute?
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

Just keep watching the channel.
Whenever there is a change, it gets broadcasted.
Try switching the ATO float switch from off to on and vice versa.
R is the state of the main relay box ports, but RA* doesn't have main relay box.
You should look for R1.
ROFF is the override off state, RON is the override on state.
You should convert to a binary number though. So let's say R1=9, in binary it is 00001001, which means port 1 and port 4 are on.
Roberto.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

This was extremely helpful... Though I did have to figure out the equation to convert int to binary.
rimai wrote:You should convert to a binary number though. So let's say R1=9, in binary it is 00001001, which means port 1 and port 4 are on.
When monitoring "wolfpack/out" and sending overrides to expansion box 1, port 8, here are the results:
override off: "ROFF1:119"
override on: "RON1: 128"
auto (on when in auto state): RON1:0

I'm trying to figure out how to use the override status to leave a value without overriding the auto value
Last edited by wolfpack on Mon Jan 17, 2022 1:29 am, edited 2 times in total.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

I also found out there are so many more things that get sent to out when you send "all:0"

Code: Select all

2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP7:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP6:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP5:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP4:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP3:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP2:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP1:0
2022-01-16 21:50:18Topic: wolfpack/outQos: CEXP0:0
2022-01-16 21:50:18Topic: wolfpack/outQos: PAR:0
2022-01-16 21:50:18Topic: wolfpack/outQos: PHE:0
2022-01-16 21:50:18Topic: wolfpack/outQos: SAL:0
2022-01-16 21:50:18Topic: wolfpack/outQos: ORP:0
2022-01-16 21:50:18Topic: wolfpack/outQos: T6:0
2022-01-16 21:50:18Topic: wolfpack/outQos: T5:0
2022-01-16 21:50:18Topic: wolfpack/outQos: T4:0
2022-01-16 21:50:18Topic: wolfpack/outQos: PH:797
2022-01-16 21:50:18Topic: wolfpack/outQos: T2:707
2022-01-16 21:50:18Topic: wolfpack/outQos: T1:770
2022-01-16 21:50:18Topic: wolfpack/outQos: RON:0
2022-01-16 21:50:18Topic: wolfpack/outQos: ROFF:255
2022-01-16 21:50:17Topic: wolfpack/outQos: R:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C7:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C6:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C5:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C4:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C3:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C2:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C1:0
2022-01-16 21:50:17Topic: wolfpack/outQos: C0:0
2022-01-16 21:50:17Topic: wolfpack/outQos: LEAK:0
2022-01-16 21:50:17Topic: wolfpack/outQos: IO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFIO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFBO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFGO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFRO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFRBO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFWO:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFI:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFB:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFG:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFR:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFRB:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFW:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFD:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFS:0
2022-01-16 21:50:17Topic: wolfpack/outQos: RFM:0
2022-01-16 21:50:17Topic: wolfpack/outQos: AIRB:0
2022-01-16 21:50:17Topic: wolfpack/outQos: AIB:0
2022-01-16 21:50:17Topic: wolfpack/outQos: AIW:0
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME5O:255
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME4O:255
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME3O:255
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME2O:255
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME1O:255
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME0O:255
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME5:0
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME4:0
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME3:0
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME2:0
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME1:0
2022-01-16 21:50:17Topic: wolfpack/outQos: PWME0:0
2022-01-16 21:50:17Topic: wolfpack/outQos: DCT:0
2022-01-16 21:50:17Topic: wolfpack/outQos: DCD:0
2022-01-16 21:50:17Topic: wolfpack/outQos: DCS:0
2022-01-16 21:50:16Topic: wolfpack/outQos: DCM:0
2022-01-16 21:50:16Topic: wolfpack/outQos: HUM:0
2022-01-16 21:50:16Topic: wolfpack/outQos: WL4:0
2022-01-16 21:50:16Topic: wolfpack/outQos: WL3:0
2022-01-16 21:50:16Topic: wolfpack/outQos: WL2:0
2022-01-16 21:50:16Topic: wolfpack/outQos: WL1:0
2022-01-16 21:50:16Topic: wolfpack/outQos: WL:0
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMA2O:255
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMD2O:255
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMA2:92
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMD2:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ALARM:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON8:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF8:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R8:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON7:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF7:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R7:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON6:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF6:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R6:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON5:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF5:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R5:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON4:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF4:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R4:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON3:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF3:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R3:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON2:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF2:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R2:0
2022-01-16 21:50:16Topic: wolfpack/outQos: RON1:0
2022-01-16 21:50:16Topic: wolfpack/outQos: ROFF1:255
2022-01-16 21:50:16Topic: wolfpack/outQos: R1:212
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMAO:255
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMDO:255
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMA:92
2022-01-16 21:50:16Topic: wolfpack/outQos: PWMD:0
2022-01-16 21:50:16Topic: wolfpack/outQos: SF:0
2022-01-16 21:50:16Topic: wolfpack/outQos: AF:0
2022-01-16 21:50:16Topic: wolfpack/outQos: BID:4
2022-01-16 21:50:16Topic: wolfpack/outQos: REM:1
2022-01-16 21:50:16Topic: wolfpack/outQos: EM1:4
2022-01-16 21:50:16Topic: wolfpack/outQos: EM:65
2022-01-16 21:50:16Topic: wolfpack/outQos: ATOHIGH:1
2022-01-16 21:50:16Topic: wolfpack/outQos: ATOLOW:0
2022-01-16 21:50:15Topic: wolfpack/inQos: all:0
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Mqtt server

Post by rimai »

all:0 requests all variables.
Usually when you initially connect so you can grab the latest data. Then you just need to keep watching for changes.
Roberto.
wolfpack
Posts: 24
Joined: Thu Sep 06, 2012 10:11 pm

Re: Mqtt server

Post by wolfpack »

Thanks Roberto! I see it now. Amazing how many messages I missed before. Now I am monitoring R1, R1ON1, ROFF2, ATOLOW, and ATOHIGH. The Rs needed a little bit of math to break out the values, but I think I've just about got it and will send those values to helper variables in Home Assistant for visibility.
Post Reply