Application note aims to help you with setting up converter so it always listens for device message. Device it self is connected as usual (polarity doesn't really metter). The main difference here is LUA script, which sets up the device to listen to any message send over RS485. Due to this settings, consumption is also higher (battery version of RS485 converter is not recomended)
Here's LUA script for LoRaWAN version of converter. As you can see, when it registers any message, it sends data to LoRaWAN
-----------------------
--- CONFIGURATION -----
-----------------------
----- LoRaWAN ----------
ack = 0 -- 1 for acknowledged, 0 for non-acknowledged
port = 100 -- transmit port
receiveTimeout = 10000 -- the maximum execution time in milliseconds
----- Modbus -----------
baudrate = 9600 -- baudrate: up to 921600 baud
parity = 0 -- communication parity: 0 for none, 1 for odd and 2 for even parity
stopBits = 1 -- number of stop bits: 1 or 2
dataBits = 8 -- number of data bits: 7 or 8
rxTimeout = 500 -- slave device receive timeout in ms
------ Timing ---------
-- device wakeup interval
periodHours = 2
periodMinutes = 30
-----------------------
-----------------------
-- CONFIGURATION END --
-----------------------
--only for the compiler (the function itslef is not needed)
function onWake ()
end
function onStartup()
print("Starting up LoRaWAN listenning Modbus script")
-- setup RS485 and turn it on
api.rs485Setup(baudrate,parity,stopBits,dataBits)
api.rs485State(1)
-- listen to any message received
while(1) do
api.rs485Receive(0)
ans,length=api.rs485Receive(rxTimeout)
api.delayms(500)
-- Check for received message, if any message received, send it over LoRa
if #ans ~= 0 then
print("Received from RS485 and send to LoRaWAN: ")
api.dumpArray(ans)
print("Sending to LoRaWAN")
res, rxport, rcvd = api.loraSend(ack, receiveTimeout, ans, port)
print("Done sending")
ans=""
end
end
api.rs485State(0)
print("Exited while loop")
end
Serial line
Here's serial line output. I tested this script using RS485 converter connected to PC and sent data over terminal to converter.
~>Done sending
~>Received from RS485 and send to LoRaWAN:
00 : 61
~>Sending to LoRaWAN
[HWAPI_LORA]: setting port to 100.
[HWAPI_LORA]: 1 bytes of data will be sent
[LORA]: send data:
61
[LORA]: McpsConfirm = MCPS_UNCONFIRMED: LORAMAC_EVENT_INFO_STATUS_OK
[LORA]: RX Timeout FAILED!
[LORA]: Receive timeout!
[HWAPI_LORA]: LoRa ACK not received!
~>Done sending
~>Received from RS485 and send to LoRaWAN:
00 : 73
~>Sending to LoRaWAN
[HWAPI_LORA]: setting port to 100.
[HWAPI_LORA]: 1 bytes of data will be sent
[LORA]: send data:
73
[LORA]: McpsConfirm = MCPS_UNCONFIRMED: LORAMAC_EVENT_INFO_STATUS_OK
[LORA]: RX Timeout FAILED!
[LORA]: Receive timeout!
[HWAPI_LORA]: LoRa ACK not received!
~>Done sending