MQTT – setup and use
-
ok thanks for trying to solve my problem.
in the near future i will try to reinstall OpenLuup on my Raspbery, maybe this will fix this problem.
Sorry for taking your precious time -
Is @christian_fabre bridged to mosquitto? As when I reload OpenLuup I have to restart mosquitto to get them talking again.
-
-
@akbooer I will probably add more log, to see the exact payload sent. Sometimes those things are generating strange telemetry data, so maybe that's the case. I'll probably log what's going on around hadevice property as well. I was unable to re-produce it in my own install, so it should be something related to this particular model and its messages.
-
If you are still interested, testing v21.5.3 is available. I have made considerable changes.
-
-
@christian_fabre said in MQTT – setup and use:
Merci bien
Je vous en pris.
Believe me... I'm happy. So sorry for all the mis-steps, but I learned a few things along the way, so it was a worthwhile exercise!
-
@christian_fabre said in MQTT – setup and use:
Merci bien
Je vous en pris.
Believe me... I'm happy. So sorry for all the mis-steps, but I learned a few things along the way, so it was a worthwhile exercise!
Now that you got that figured out, one awesome thing which could be done would be integrate this:
By creating a bridge supporting it on openLuup. It would enable me to move zigbee from home assistant to run directly to openLuup and I would likely take advantage of it to get rid of my hue hub as well, running a single zigbee network through mqtt...
-
Now that you got that figured out, one awesome thing which could be done would be integrate this:
By creating a bridge supporting it on openLuup. It would enable me to move zigbee from home assistant to run directly to openLuup and I would likely take advantage of it to get rid of my hue hub as well, running a single zigbee network through mqtt...
-
@akbooer I hate to add more to the pile... but I'm still seeing a receive error for the connection to mosquitto. openLuup 2021.04.29b
Here's the log error:
2021-05-01 14:22:38.815 openLuup.io.server:: MQTT:1882 connection closed tcp{client}: 0x5579919e9c58 2021-05-01 14:22:38.816 openLuup.mqtt:: RECEIVE ERROR: closed tcp{client}: 0x5579919e9c58 2021-05-01 14:22:43.935 luup.io.incoming:: bytes received: 51, status: OK tcp{client}: 0x557990e7f528 2021-05-01 14:22:48.435 luup.io.incoming:: bytes received: 51, status: OK tcp{client}: 0x557990e7f528 2021-05-01 14:22:49.763 luup.variable_set:: 10181.urn:micasaverde-com:serviceId:EnergyMetering1.KWHReading was: 1619904116 now: 1619904168 #hooks:0 2021-05-01 14:22:50.158 openLuup.io.server:: HTTP:3480 connection closed openLuup.server.receive closed tcp{client}: 0x557991971ff8 2021-05-01 14:22:53.834 openLuup.io.server:: MQTT:1882 connection from 127.0.0.1 tcp{client}: 0x5579920dc0b8 2021-05-01 14:22:53.834 openLuup.mqtt:: client is in ERROR empty 2021-05-01 14:22:53.834 openLuup.mqtt:: credentials is in ERROR empty 2021-05-01 14:22:53.834 openLuup.mqtt:: subscriptions is in ERROR empty
using the below error trapping in function "MQTTservlet"
local function MQTTservlet (client) if client == nil then _log ("client is in ERROR nil") else if table.concat(client) == "" then _log ("client is in ERROR empty") else _log (table.concat {"MQTT ERROR: ", table.concat(client)}) end end if credentials == nil then _log ("credentials is in ERROR nil") else if table.concat(credentials) == "" then _log ("credentials is in ERROR empty") else _log (table.concat {"MQTT ERROR: ", table.concat(credentials)}) end end if subscriptions == nil then _log ("subscriptions is in ERROR nil") else if table.concat(subscriptions) == "" then _log ("subscriptions is in ERROR empty") else _log (table.concat {"MQTT ERROR: ", table.concat(subscriptions)}) end end return function () incoming (client, credentials, subscriptions) end end
I can't find a deeper layer in the stack where I can trap for the incoming message to see what's in the message that is throwing the error. As near as I can tell, if openLuup tries to connect to a running mosquitto instance, then it fails to see the topics and messages, and passes empty--but not nil--strings when the servlet interface sees incoming bytes.
If I restart mosquitto, openLuup then sees the topics and messages and the error messages stop--and the connection to mosquitto remains stable.
This behavior does not occur when I aim an IOT device directly at openLuup--in that the connection to the device always resumes when openLuup reloads--in other words, I don't need to restart the IOT device to enable the connection.
@buxton said in MQTT – setup and use:
As near as I can tell, if openLuup tries to connect to a running mosquitto instance, then it fails to see the topics and messages, and passes empty--but not nil--strings when the servlet interface sees incoming bytes.
OK, I’m ready to take a look at this. However the above statement makes no sense to me, since the server never connects to anything (because it’s a server – clients connect to it.)
-
@buxton said in MQTT – setup and use:
As near as I can tell, if openLuup tries to connect to a running mosquitto instance, then it fails to see the topics and messages, and passes empty--but not nil--strings when the servlet interface sees incoming bytes.
OK, I’m ready to take a look at this. However the above statement makes no sense to me, since the server never connects to anything (because it’s a server – clients connect to it.)
@akbooer Yes, that was poorly worded as it makes it sound like openLuup initiates the connection to Mosquitto.
The symptoms of the problem are that:
- if luup reloads, an occasional message that is sent to openLuup from Mosquitto causes a receive error in openLuup. It is unknown what that/those message(s) are.
- if mosquitto reloads, the openLuup error messages stop, so something changes in the way that openLuup sees the mosquitto data.
- this behavior does not occur with IOT devices.
A possible way to trouble shoot this is to place debug code at the incoming interface that will trap and display packets headed to the MQTT port. By comparing incoming timestamps with the error message timestamp, I should be able to tell what message is causing the receive error message--even though the message variable is empty at the time it causes the luup error. What is odd to me is that there is a lot of error trapping for bad messages in your code, but this message(s) seems to bypass all of that and arrives at the incoming routine empty.....
-
Ah! Yes that explains the empty variable, though I'm going to have to dig into my lua book to understand why! I was assuming that the concat function returned a series of string values from a table, and therefore, the output could be sent to the log for display.
-
It works only for a contiguous array of numbers and/or strings...
local x = {"a ", 1, " b ", 2} local y = table.concat (x) print(y)
gives
a 1 b 2
@akbooer Ok, so the variable "message " contains more than just a value array.
I've never been able to get zerobrane as a debugger working with openLuup, though the instructions on how to do so have been written about previously. I just couldn't get the debugger working on a target remote PC, so it's difficult to watch what's going on within the myriad method code in the object model you've created. I don't write code for a living--never have-- though I use SQL, VBA and Python in my day to day job. The debuggers for those languages are a breeze compared to setting up zerobrane and Vera.....
-
Yes, the message structure is an object with various values and methods:
{ -- variables length = nb, -- byte count for statistics packet_type = packet_type, control_flags = control_flags, body = body, -- may include variable header and payload ptr = 0, -- pointer to parse position in body packet_name = pname, -- string name of packet type -- methods read_bytes = read_bytes, read_flag_byte = read_flag_byte, -- converting octet to 8 separate flag bits read_word = read_word, read_string = read_utf8, }
It's that way, because MQTT message formats are dependent on the type of message, so the methods contain here do some of that job. However, for the publish / subscribe functions, the topic and message parameters are simple strings, so easy to print out.
As for debugging, I run the entire openLuup system within ZeroBrane during development, so most things are directly traceable and the debugging facilities are very adequate. I've never, ever, tried to debug a remote system.
Still keen to discover the cause of your bridged server issue...
...have you tried enabling DEBUG of the MQTT module itself? It provides some useful information.
-
Yes, the message structure is an object with various values and methods:
{ -- variables length = nb, -- byte count for statistics packet_type = packet_type, control_flags = control_flags, body = body, -- may include variable header and payload ptr = 0, -- pointer to parse position in body packet_name = pname, -- string name of packet type -- methods read_bytes = read_bytes, read_flag_byte = read_flag_byte, -- converting octet to 8 separate flag bits read_word = read_word, read_string = read_utf8, }
It's that way, because MQTT message formats are dependent on the type of message, so the methods contain here do some of that job. However, for the publish / subscribe functions, the topic and message parameters are simple strings, so easy to print out.
As for debugging, I run the entire openLuup system within ZeroBrane during development, so most things are directly traceable and the debugging facilities are very adequate. I've never, ever, tried to debug a remote system.
Still keen to discover the cause of your bridged server issue...
...have you tried enabling DEBUG of the MQTT module itself? It provides some useful information.
-
@christian_fabre I added my Shelly 1PM today to OpenLuup v21.4.29b.
At first it did not work, and I could not figure out why. Then I found a post on the Shelly forum that said that there in some cases (or for some devices) could be a problem with the latest Shelly firmware and Mqtt.
I had the latest v1.10.3 in my 1PM. After I downgraded the Shelly to v1.9.4 it worked.
Check what firmware you have in your plug and if you have the latest you can try to downgrade and see if it works.
Go to https://www.shelly-support.eu/index.php?shelly-firmware-archive/ and enter your IP address, select the right plug variant (there are a few to choose from) and firmware release. Then you copy the url that is generated into a browser.
If you have blocked the Shelly in your router from Internet access you probably have to open it temporary for the downgrade.I also added my Shelly Button to OpenLuup and for some reason I could not downgrade it, but I managed to get it working anyway after a few attempts.
(A bit strange since the post I found on the forum was on problems with the Button and v1.10.3.)Another tip is to use MqttExplorer if you do not already use it and see if the Shelly shows up there. If it does, then at least the Mqtt part of the Shelly most likely works.
@archers said in MQTT – setup and use:
I found a post on the Shelly forum that said that there in some cases (or for some devices) could be a problem with the latest Shelly firmware and Mqtt.
Do we know if this issue has been solved yet?
I’ll update all my device firmware if so, but I’m loathe to do so without some sort of confirmation. TIA.
-
@archers said in MQTT – setup and use:
I found a post on the Shelly forum that said that there in some cases (or for some devices) could be a problem with the latest Shelly firmware and Mqtt.
Do we know if this issue has been solved yet?
I’ll update all my device firmware if so, but I’m loathe to do so without some sort of confirmation. TIA.