Since our IoT Converter is using LUA scripting language to configure it, there is very high change to encounter some mistakes, or so called "bugs" inside of LUA script itself. For that reasong, it's very convinient to use technique to localize the problem and fix it.
Since our new GUI is by default adding debug symbols to compiled LUA script. You can use lua function debug.sethook(print, "l") to enable the line tracing of the lua script.
The only thing you have to do, is to enable this inside of onStartup() function, and read the serial line.
Here is a snippet of onStartup() function from LoRaWAN S0 LUA script:
function onStartup()
debug.sethook(print, "l")
print("onStartup(), S0 persistent emulation - 4 channels ...")
--set to threshold
api.S0setThreshold(1, 0)
api.S0setThreshold(2, 0)
api.S0setThreshold(3, 0)
api.S0setThreshold(4, 0)
s01 = api.getVar(20)
s02 = api.getVar(21)
s03 = api.getVar(22)
s04 = api.getVar(23)
api.S0initializeCounter(1, s01)
api.S0initializeCounter(2, s02)
api.S0initializeCounter(3, s03)
api.S0initializeCounter(4, s04)
end
After uploading the script to the converter (with a new GUI), the output from the serial line will look similar to the one below.
As you can see, the serial line output now contains lines of the script. You may also notice a box containing a number, for example [ 2710][LORA]: Setting power to 14 dBm
. The box [ 2710] is a value of the systick timer and the second box (in this case [LORA]) describes which module is used.
[ 2710][LORA]: Setting power to 14 dBm
[ 2715][LORA]: Setting DR to mode - 0
[ 2720][LORA]: Setting ADR - OFF
[ 2753][SYS]: FW version: CV_FW_2.8.0-0-g3830646c8499
--- CONVERTER S0-LORA ---
[ 2762][SYS]: date / time - 2016/01/01 / 00:00:02
[ 2768][SYS]: build date / time - Jul 11 2022 / 16:22:17
[ 2774][SYS]: S0 initialization done
[ 2778][LORA]: initialization
[ 2826][LORAMAC]: DevEui : 00-00-00-00-00-00-00-00
[ 2832][LORAMAC]: JoinEui : 00-00-00-00-00-00-00-00
[ 2839][LORAMAC]: Pin : 00-00-00-00
[ 2844][LORA]: OTAA
[ 2846][LORA]: DevEui=
⇥ 70 B3 D5 CE E0 00 00 E4
[ 2975][LORA]: initialization done!
[ 2979][SYS]: configuration mode entered
[ 6979][SYS]: configuration mode exited
<break>
[ 7980][LUA]: starting lua script version 2
[ 8045][LUA]: Starting onStartup() script
~>line⇥ 80
~>onStartup(), S0 persistent emulation - 4 channels ...
~>line⇥ 83
~>line⇥ 84
~>line⇥ 85
~>line⇥ 86
~>line⇥ 88
~>line⇥ 89
~>line⇥ 90
~>line⇥ 91
~>line⇥ 93
~>line⇥ 94
~>line⇥ 95
~>line⇥ 96
~>line⇥ 97
[ 8947][SYS]: --- New request ---
[ 8952][SYS]: Battery Voltage: 3609 mV
[ 8957][LORA]: setting battery state - 254/254
[ 8962][LUA]: Starting onWake() script
~>line⇥ 56
~>onWake(), periodic wake up
~>line⇥ 57
~>line⇥ 10
~>line⇥ 11
~>S0-1: 138109
~>line⇥ 12
~>line⇥ 13
~>S0-2: 46412
~>line⇥ 14
~>line⇥ 15
~>S0-3: 0
~>line⇥ 16
~>line⇥ 17
~>S0-4: 15
~>line⇥ 20
~>line⇥ 21
~>line⇥ 22
~>line⇥ 23
~>line⇥ 25
~>line⇥ 26
~>line⇥ 27
~>line⇥ 28
~>line⇥ 31
~>line⇥ 32
~>line⇥ 33
~>line⇥ 34
~>line⇥ 36
~>line⇥ 37
~>line⇥ 38
~>line⇥ 39
~>line⇥ 42
~>line⇥ 45
~>line⇥ 48
~>Frame in hex: <devClass, voltage, S0_1, S0_1_last, ...>
~>line⇥ 49
⇥ 00 : 05 18 0E 7D 1B 02 00 7D 1B 02 00 7D 1B 02 00 4C
⇥ 10 : B5 00 00 4C B5 00 00 4C B5 00 00 00 00 00 00 00
⇥ 20 : 00 00 00 00 00 00 00 0F 00 00 00 0F 00 00 00 0F
⇥ 30 : 00 00 00
~>line⇥ 51
~>line⇥ 58
~>Sending to LORA
~>line⇥ 59
[ 12304][HWAPI_LORA]: Port is not set. Using default value instead (port = 1).
[ 12313][HWAPI_LORA]: setting port to 1.
[ 12318][HWAPI_LORA]: 51 bytes of data will be sent
[ 12324][LORA]: Force confirmed message after join!
[ 12330][LORA]: Not joined, join and continue.
[ 12351][LORAMAC]: # === MLME-Request == #
[ 12357][LORAMAC]: # MLME_JOIN #
[ 12364][LORAMAC]: # ===== #
[ 12367][LORAMAC]: STATUS : OK
[ 18711][LORAMAC]: # === MLME-Confirm == #
[ 18716][LORAMAC]: STATUS : Rx 2 timeout
[ 18721][LORA]: Failed to join
[ 18729][LORAMAC]: # == CTXS STORED == #
[ 18734][LORAMAC]: Size : 1112
[ 20336][LORA]: Could not join OTAA - general error!
[ 20342][LORA]: Could not join OTAA - error joining
[ 20347][HWAPI_LORA]: LoRa ACK not received! ␊
␍
~>line⇥ 60
~>Done sending
~>line⇥ 61
~>No error, sent to lora
~>line⇥ 63
[ 20547][HWAPI_TIME]: Seconds to wait 3600
~>line⇥ 65
[ 20610][SYS]: entering sleep mode
<break>
function trace (event, line)
print("::" .. line)
end
function onStartup()
debug.sethook(trace, "l")
print("onStartup(), S0 persistent emulation - 4 channels ...")
--set to threshold
api.S0setThreshold(1, 0)
api.S0setThreshold(2, 0)
api.S0setThreshold(3, 0)
api.S0setThreshold(4, 0)
s01 = api.getVar(20)
s02 = api.getVar(21)
s03 = api.getVar(22)
s04 = api.getVar(23)
api.S0initializeCounter(1, s01)
api.S0initializeCounter(2, s02)
api.S0initializeCounter(3, s03)
api.S0initializeCounter(4, s04)
end
In the case of old GUI and firmware versions (2.7.5 and lower), there are two options.
One of the options is simply placing function print("string") everywhere you can and tracing down the problem. In the old GUI, if there is a mistake in formatting, it will warn you with the first one it detects, with the line on which the bug appears.
Here is an example of how it may look like:
function onStartup()
print("onStartup(), S0 persistent emulation - 4 channels ...")
--set to threshold
print("1:")
api.S0setThreshold(1, 0)
print("2:")
api.S0setThreshold(2, 0)
print("3:")
api.S0setThreshold(3, 0)
print("4:")
api.S0setThreshold(4, 0)
api.setVar(16, 0)
api.setVar(17, 0)
api.setVar(18, 0)
api.setVar(19, 0)
api.setVar(20, 0)
api.setVar(21, 0)
api.setVar(22, 0)
api.setVar(23, 0)
s01 = api.getVar(20)
s02 = api.getVar(21)
s03 = api.getVar(22)
s04 = api.getVar(23)
api.S0initializeCounter(1, s01)
api.S0initializeCounter(2, s02)
api.S0initializeCounter(3, s03)
api.S0initializeCounter(4, s04)
end
Here is a part of the output showing the result of the modification:
[ 8045][LUA]: Starting onStartup() script
~>onStartup(), S0 persistent emulation - 4 channels ...
1:
2:
3:
4:
[ 8947][SYS]: --- New request ---
[ 8952][SYS]: Battery Voltage: 3609 mV
[ 8957][LORA]: setting battery state - 254/254
[ 8962][LUA]: Starting onWake() script