![]() |
Lorawan - The Things Network - Dragino sensor PS-LB - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Lorawan - The Things Network - Dragino sensor PS-LB (/showthread.php?tid=5136) |
Lorawan - The Things Network - Dragino sensor PS-LB - clue9 - 06.12.2023 Hi. I had a need for a remote sensor to monitor the waterlevel in a well in the forest 200m from house uphill with terrain in the way from the house, and ended out with a lorawan sensor from Dragino (PS-LB model) Have it communicating to the things network now and gets the payload decoded by a code i got from draginos websites in the TTN console. But in MQTT explorer it seems like every package is formatted in a .json format in one topic and not with the decoded data as separate topics to subscribe to. here is a copy paste the end topic (v3/sensor-well-level@ttn/devices/eui-xxxxxxxxxxxxxxxx/up) from MQTT explorer. Code: { I need to get subscribed to new updates (each 20 minutes) for the data of interest, (se below snippet of the above where i add double ## in front to mark the interest) and send it to group adresses in my LM, one value to KNX ( "Water_deep_cm" ). Someone here who could help as i see this involves .json and doble encoding and all this [ and { parts making me as a newbe lua guy confused how to sort this out. MQTT server is eu1.cloud.thethings.network:1883 and i have to supply a username and a password i get from TTN to connect as a client. Code: ##"received_at": "2023-12-06T23:01:24.067287960Z", RE: Lorawan - The Things Network - Dragino sensor PS-LB - admin - 07.12.2023 Create a resident script with non-zero sleep time. Modify username, password and topicname variables as needed. Change group addresses in the ON_MESSAGE callback. Code: broker = 'eu1.cloud.thethings.network' RE: Lorawan - The Things Network - Dragino sensor PS-LB - kropfm - 09.07.2025 (07.12.2023, 08:52)admin Wrote: Create a resident script with non-zero sleep time. Modify username, password and topicname variables as needed. Change group addresses in the ON_MESSAGE callback. Hello there Apology, for my ignorance. I'm trying to get a temperature value from a LoRaWan sensor. I use this script, as I also use the the things network, and while I seem to connect to MQTT, I never get any values. I run this resident script with a 60 seconds delay. I use a virtual variable. Now, there I wasn't sure either. Is the result a text or 2 byte value? I see no errors but also no values. Your help is much appreciated. Martin RE: Lorawan - The Things Network - Dragino sensor PS-LB - Erwin van der Zwart - 10.07.2025 Your payload might be different then in this sample, try adding this in the client.ON_MESSAGE function: Code: local data = json.pdecode(payload) RE: Lorawan - The Things Network - Dragino sensor PS-LB - Daniel - 10.07.2025 Use MQTT Explorer to see the topics and values. RE: Lorawan - The Things Network - Dragino sensor PS-LB - admin - 10.07.2025 Script sleep time should not be zero. Sleep time only affects the reconnect period because normally script does not return due to loop_forever() call. RE: Lorawan - The Things Network - Dragino sensor PS-LB - kropfm - 11.07.2025 (10.07.2025, 07:26)admin Wrote: Script sleep time should not be zero. Sleep time only affects the reconnect period because normally script does not return due to loop_forever() call. Thanks Admin and Daniel for your inputs. I will give it another try this weekend. Can I just ask you to confirm the resident script with a sleep time of 60 seconds would do? Thank you Erwin van der Zwart, I'm already logging the data but no data show in the log. But I'll test some more and report. RE: Lorawan - The Things Network - Dragino sensor PS-LB - admin - 11.07.2025 60 seconds sleep time is ok. The first thing you should check is the topic name. RE: Lorawan - The Things Network - Dragino sensor PS-LB - kropfm - 13.07.2025 (11.07.2025, 09:06)admin Wrote: 60 seconds sleep time is ok. The first thing you should check is the topic name. Hello there Thank you for all your inputs and your tireless support. I checked the topic name and that seemed to match the one from TTN. I then copy and pasted the code into a new resident script, and suddenly the on.message part of the LUA script was performed and the data retrieved. So, I don't really know what happened. But I really appreciate this forum. I've run two logic machine for some time now, and I really rely on them. Because they run so well, I barely need to code in Lua. That's why I turn to this forum for code snippets and support. I will run some test and if I find the root of the original problem, I will post it. Cheers! Martin |