Universal LoRaWAN converter has reserved 3 uplink ports - 123, 124 and 125. Received data are processed by firmware itself.
This example script sets value to memory index 22 using configuration frame.
When uplink is detected, device sets the variable and prints updated data.
Example (hex):
434f4e464947191600017378100530ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
If you're using chirpstack don't forget to convert hexadecimal frame to base64 and then use (enqueue downlink payload).
Example (Base64):
Q09ORklHGRYAAXN4EAUw////////////////////////////////////////////////
function onWake()
buf,err,wake = api.getGUIContext()
api.delayms(5000)
ref_num = api.getVar(30)
version = 1
m-type = 0
h_sum = (version + m_type + ref_num + 1 +1) % 256
header = pack.pack('<b6', version, m_type, ref_num, 0x01, 0x01, h_sum)
sn=api.getVar(22)
b1 = bit.rshift(sn, 0) %256
b2 = bit.rshift(sn, 8) %256
b3 = bit.rshift(sn, 16) %256
b4 = bit.rshift(sn, 24) %256
sn = pack.pack('<b4', b4, b3, b2, b1)
print("serial num:")
api.dumpArray(sn)
h_sum = (version + m_type + ref_num + 1 +1) % 256
header = pack.pack('<b6', version, m_type, ref_num, 0x01, 0x01, h_sum)
snd = ""..header..sn
print("data:")
api.dumpArray(snd)
api.loraSend(0, 1000, snd)
api.setVar(30, ref_num+1)
api.wakeUpIn(0,0,10,0)
end
function onStartup()
print("Starting up LUA interface ...")
end