This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Lorawan - The Things Network - Dragino sensor PS-LB
#3
(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.

Code:
broker = 'eu1.cloud.thethings.network'
port = 8883
username = 'PUT_USER_HERE@ttn'
password = 'PUT_API_KEY_HERE'
topicname = 'v3/sensor-well-level@ttn/devices/eui-xxxxxxxxxxxxxxxx/up'

require('json')
mqtt = require('mosquitto')
client = mqtt.new()

client.ON_CONNECT = function(status, rc, msg)
  if status then
    log('mqtt connected')
    client:subscribe(topicname)
  else
    log('mqtt connect failed ' .. tostring(msg))
    client:disconnect()
  end
end

client.ON_MESSAGE = function(mid, topic, payload)
  local data = json.pdecode(payload)

  if type(data) ~= 'table' then
    return
  end

  local datetime = data.received_at
  local sensor = data.uplink_message.decoded_payload

  grp.checkwrite('1/1/1', datetime)

  grp.checkwrite('1/1/2', sensor.Bat_V)
  grp.checkwrite('1/1/3', sensor.IDC_intput_mA)
  grp.checkwrite('1/1/4', sensor.Water_deep_cm)
end

client.ON_ERROR = log

client:login_set(username, password)
client:tls_insecure_set(true)
status, rc, msg = client:connect(broker, port)

if status then
  client:loop_forever()
else
  log('connect failed: ' .. tostring(msg))
end

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
Reply


Messages In This Thread
RE: Lorawan - The Things Network - Dragino sensor PS-LB - by kropfm - 09.07.2025, 18:50

Forum Jump: