User Tools

Site Tools


public:application:rs485_temperature

Remote temperature and humidity readings via LoRa or NB-IoT network



ACR-CV-101N-R-D with temperature probe connected


Introduction

We have encountered request regarding the solution for high-temperature remote readings, that could go up to +120°C but also would measure humidity. This use-case can be found in HACCP applications, in the monitoring of warehouses or anywhere, where the information about temperature and humidity is crucial. The biggest challenge lays in the low-power nature of the solution since the LPWAN network will be used.


Hardware being used

ACR-CV-101N-R-D


Temperature and humidity probe communicating over Modbus (RS485)

This application can be implemented using ACR-CV-101N-R-D converter and this converter is also being used in this application note. The ACR-CV-101N-R-D converter is communicating over NB-IoT, has a non-powered RS485 bus and D battery with the capacity of 17 000 mAh.
More suitable option would be using ACR-CV-101N-R12-D converter, which has powered RS485 bus by 12 volts. The temperature and humidity probe being used can hold anything between 3.3 - 24V.


Technical parameters of the temperature probe and wiring

Wiring of the temperature probe
Red Power + 3.3…24V
Black Power -
Green RS485- (B)
Yellow RS485+ (A)
Communication
Baud rate: 9600 as default
Data bit: 8
Stop bit: 1
Parity None
Modbus ID address: 1-255, default is 1
Protocol Modbus RTU
Function code: 03 (Read), 06 (Write)
Specification
Power supply: 3.3..24VDC
Temperature meassuring range: -40..+120°C
Humidity meassuring range: 0-100% RH
Temperature accuracy: 0.3°C
Humidity accuracy: 3% RH
Measurement resolution: 0.1°C, 0.1%RH
Working current: 0.9mA
Sleeping current: 18uA
Power protection: Anti-reverse connection, ± 15kV ESD surge protection
Refresh interval: >=20ms
Baud rate: 1200,2400,4800,9600,11400,19200
Cable length: 1 meter

Wiring of ACR-CV-101N-R-D


Configuration and payload

LUA script being used

-----------------------
--- CONFIGURATION -----
-----------------------
----- NB-IoT ----------
APN = "nb.m2mc"
PLMNID = "23003"
protocol = "UDP"	-- UDP or TCP
ip = "192.168.0.20"
port = 4242
receiveTimeout = 500 -- the maximum execution time in milliseconds
------ Timing ---------
-- device wakeup interval
periodHours = 0
periodMinutes = 5
-----------------------
-----------------------
-- CONFIGURATION END --
-----------------------
 
function onWake ()
 
 
    api.rs485Setup(9600, 0, 1, 8)
    dataToTransmit = ""
 
    --read temperature
    api.rs485State(1)
    api.voltageSourceState(1)
    api.delayms(500)
    req = pack.pack('<b8', 0x01, 0x03, 0x00, 0x01, 0x00, 0x01, 0xD5, 0xCA)
    api.rs485Receive(0) -- flush input buffer
    api.rs485Send(req)
    ans,len = api.rs485Receive(500) 
 
    if len == 7 then
        dataToTransmit = dataToTransmit .. 'T' .. ans:sub(4,5)
        temperature = string.byte(ans:sub(4,4))*256 + string.byte(ans:sub(5,5))
        if temperature > 0x7FFF then
            temperature = -1 * (0x10000 - temperature)
        end
        temperature = temperature/10
        print("Current temperature is: " .. tostring(temperature) .. "C")
    end
 
    -- read humidity
    req = pack.pack('<b8', 0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A)
    api.rs485Receive(0) -- flush input buffer
    api.rs485Send(req)
    ans,len = api.rs485Receive(500) 
 
    if len == 7 then
        dataToTransmit = dataToTransmit .. 'H' .. ans:sub(4,5)
        humidity = string.byte(ans:sub(4,4))*256 + string.byte(ans:sub(5,5))
        humidity = humidity/10
        print("Current RH is: " .. tostring(humidity) .. "%")
    end
 
    api.voltageSourceState(1)
    api.rs485State(0)
 
    -- send data to LoRaWAN/NB-IoT
    api.dumpArray(dataToTransmit)
 
 
    if #dataToTransmit < 1 then
        buf = "NO DATA RECEIVED"
    else
        buf = dataToTransmit
    end
 
    print("To NBIOT: ")
 
    api.dumpArray(buf)
 
    print("Sending to NB-IoT")
    api.nbSend(ip, port, buf, receiveTimeout, protocol)
 
    print("Done sending")
    print("Sleep now, wake in " .. tostring(periodHours) .. "hrs:" .. tostring(periodMinutes) .. "mins.....")
 
    api.wakeUpIn(0,periodHours,periodMinutes,0)
end
 
function onStartup()
    print("Starting up NB-IoT Abest Modbus script with APN settings")
 
    result = api.nbAT("AT*MCGDEFCONT=\"IP\",\"" .. APN .."\"", 5000, 1)
    print("APN result: " .. result)
 
    result = api.nbAT("AT+COPS=1,2,\"" .. PLMNID .."\"", 5000, 1)
    print("PLMNID result: " .. result)
 
 
end

LUA answer

[17:41:28:193] SYS:- New request —-␍␊
[17:41:28:193] SYS: Battery Voltage: 3679 mV␍␊
[17:41:28:193] LUA: starting lua script version 1␍␊
[17:41:28:865] LUA: Starting onWake() script␍␊
[17:41:29:489] ~>Current temperature is: 28C␍␊
[17:41:29:601] ~>Current RH is: 40%␍␊
[17:41:29:617] ␍␊
[17:41:29:617]00 : 54 01 1A 48 01 92 ␍␊
[17:41:29:633] ~>To NBIOT: ␍␊
[17:41:29:633] ␍␊
[17:41:29:633]00 : 54 01 1A 48 01 92 ␍␊
[17:41:29:649] ~>Sending to NB-IoT␍␊
[17:41:30:241] NBIOT: wake the module up!␍␊
[17:41:31:089] NBIOT: wake the module up!␍␊
[17:41:31:441] NBIOT: Signal level 21.␍␊
[17:41:32:641] NBIOT: No return data␍␊
[17:41:38:672] ~>Done sending␍␊
[17:41:38:720] ~>Sleep now, wake in 0hrs:5mins.....␍␊
[17:41:38:742] SYS: date / time - 2020/10/12 / 17:41:37␍␊
[17:41:38:742] SYS: wake up at day / time - 12 / 17:46:37␍␊
[17:41:38:751] LUA: destroyed all lua objects, exiting␍␊
[17:41:38:751] SYS: entering sleep mode␍␊

Payload on server side

Oct 12 17:34:36 challenger python[31631]: 2020-10-12 17:34:36 diff = 21:07  :  received message from:  ('46.234.125.38', 59164) in hex:  54011C4803D4

Example

The payload captured on server side is “54011C4803D4” in hex. The first and the fourth byte stands for temperature and humidity. After we convert “54” from HEX to ASCII, we get “T”, which stands for temperature. The “48” is “H”, which stands for humidity. The “011C” and “03D4” are temperature and humidity values. After translating the whole payload, we get T284 H980. Temperature is 28.4°C and humidity 98%RH.

Payload
Byte
1 2 3 4 5 6
54 01 1C 48 03 D4
“T” Temperature value*10 “H” Humidity value*10

public/application/rs485_temperature.txt · Last modified: 2020/10/20 17:35 by Acrios Admin