User Tools

Site Tools


public:application:wmbus_scan

Wireless M-Bus - Getting the list of W-Mbus addresses by scanning

Introduction

When trying to read any water meters or calorimeters within the apartment building, you need to solve the challenge of getting WMbus slave addresses, loading them into the Wireless M-Bus converter, and trying to estimate, how many units you need to use. The scan function within our converter can help you with all of the tasks above. In this application note, we will take a look into the LUA script which is running the device, and also we will take a look at the list of responses.


Setup

This application note is based on a Wireless M-Bus NB-IoT converter ACR-CV-101N-W-D together with a custom LUA script used to scan the surrounding. Another accessory you may need is a configuration cable “ACR-CONFIG” and serial line monitor running on your laptop.


SW adjustments

To run this application the default LUA script needs to be replaced by custom LUA script. The LUA script used can be found in the public repository. WMBUS Scan - LUA

custom LUA script

The LUA script below is updated as of 30.10.2020

---- CONFIGURATION ----
  scan = 10 --- number of devices after which the scan ends
---------------------
function onWake () 
  print("LOAD WMBUS-NBIOT script NOW!")
end
 
 
 
ids = {}
function hasid(id)
    for i = 1,#ids do
        if ids[i] == id then
            return true
        end
    end
    return false
end
 
function addid(id)
    ids[#ids+1] = id
end
 
function wordToBuffer(word)
    local buff = ""
    buff = buff  .. string.char(word%256) .. string.char((word/256)%256) .. string.char(((word/256)/256)%256) .. string.char((((word/256)/256)/256)%256)
    return buff
end
 
function loadit(arr)
  filter = ""
  for i = 1,#arr do
    filter = filter .. wordToBuffer(arr[i])
  end
  api.wmbusFilter("populate", filter)
end
 
 
function onStartup()
 
  print("Starting up WMBUS scan and save script!")
 
  -- fool the compiler: api.nbSend( api.loraSend(
 
  -- Start receiving at C1/T1 mode/frequency
  api.wmbusSetup(10, "master","T1", 1)
 
  api.wmbusFilter("purge")
 
  print("--- SCAN "..tostring(scan).." ---")
  start = api.getTick()
 
  while true do
    status, CI, manID, id, ver, devType, ctrlInfo, data, raw, filterId =  api.wmbusReceiveFrame(60000, 0)    
    if raw ~= nil then
      if not hasid(id) then
        print("Adding " .. tostring(string.format("%X",id)) .. " number " .. tostring(#ids))
        addid(id)
        print("RAW DATA: ")
        api.dumpArray(raw)
        if #ids > (scan-1) then
          print("reached goal!")
          break
        end
      end
    end
  end
 
 
  asstring = "{"
  for i = 1,#ids do
    if i == #ids then
      asstring = asstring .. ids[i].."}"
    else
      asstring = asstring ..ids[i]..","
    end
  end
  print(asstring)
 
  elapsed = api.getTick()-start
  print("scanned "..tostring(scan).." devices in " ..tostring(elapsed/1000) .. " seconds")
 
  loadit(ids)
 
end

Serial line monitor

The answer shown below is copied from serial line monitor Termite.

00: 
BOOTLOADER v1.3
............................
starting...
[00]
02: SYS: date / time - 2016/01/01 / 00:00:02
SYS: build date / time - Oct 20 2020 / 10:01:43
05: SYS: configuration mode entered
09: SYS: configuration mode exited
LUA: starting lua script version 1
LUA: Starting onStartup() script
~>Starting up WMBUS scan and save script!
WMBUS: Setting power to 10 dBm
LUA: purge WMBUS filter
~>--- SCAN 10 ---
11: WMBUS: RSSI = -73 dBm
 
~>Adding 83903245 number 0
~>RAW DATA: 
 
	00 : 36 44 68 50 45 32 90 83 95 37 72 04 51 93 62 24 
	10 : 23 FE 06 99 00 20 25 7F E8 7D C0 43 4F A3 14 14 
	20 : B0 9B 97 89 F4 35 06 3A AB B3 E7 12 E0 44 CA E6 
	30 : EF 78 D5 9C C3 99 3A 
WMBUS: RSSI = -91 dBm
 
~>Adding 31670019 number 1
~>RAW DATA: 
 
	00 : 32 44 68 50 19 00 67 31 69 80 A0 11 9F 27 00 00 
	10 : E0 15 00 00 F6 08 12 09 00 00 00 00 00 00 00 00 
	20 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
	30 : 00 00 00 
14: WMBUS: RSSI = -77 dBm
 
~>Adding 40876560 number 2
~>RAW DATA: 
 
	00 : 32 44 68 50 60 65 87 40 69 80 A0 11 9F 27 76 01 
	10 : E0 15 3F 04 F9 09 74 0C 5A 31 00 31 0E 00 00 00 
	20 : 00 00 00 00 0F 22 1E 54 8A 7B 7E 71 C2 4D 45 43 
	30 : 00 00 00 
15: WMBUS: RSSI = -94 dBm
 
~>Adding 44375671 number 3
~>RAW DATA: 
 
	00 : 32 44 68 50 71 56 37 44 69 80 A0 11 9F 27 15 02 
	10 : E0 15 D4 02 F3 0A C0 0C 3C 2A 00 2A 02 00 00 00 
	20 : 00 00 00 00 0C 0C 0D 0A 26 38 60 7A 8F 76 6D 72 
	30 : 57 5E 56 
WMBUS: RSSI = -79 dBm
 
~>Adding 40876204 number 4
~>RAW DATA: 
 
	00 : 32 44 68 50 04 62 87 40 69 80 A0 11 9F 27 00 00 
	10 : E0 15 00 00 98 06 7B 06 00 00 00 00 00 00 00 00 
	20 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
	30 : 00 00 00 
WMBUS: RSSI = -68 dBm
 
~>Adding 40876502 number 5
~>RAW DATA: 
 
	00 : 32 44 68 50 02 65 87 40 69 80 A0 11 9F 27 65 00 
	10 : E0 15 30 00 D5 06 C6 06 01 03 00 03 00 00 00 00 
	20 : 00 00 00 00 00 00 02 02 0A 01 01 0B 08 09 08 08 
	30 : 05 08 01 
17: WMBUS: RSSI = -71 dBm
 
18: WMBUS: RSSI = -83 dBm
 
~>Adding 81504525 number 6
~>RAW DATA: 
 
	00 : 36 44 68 50 25 45 50 81 95 37 72 42 99 58 60 24 
	10 : 23 FE 07 48 00 20 25 6E 52 16 BA B2 38 EE 8F 0D 
	20 : A4 EB 47 14 DD 67 6E 78 80 3C E6 40 B3 A1 35 71 
	30 : CA 95 E1 F2 49 66 33 
20: WMBUS: RSSI = -79 dBm
 
~>Adding 80316512 number 7
~>RAW DATA: 
 
	00 : 36 44 68 50 12 65 31 80 95 37 72 37 44 28 60 24 
	10 : 23 FE 07 13 00 20 25 43 C4 82 36 CE F7 4E D5 C1 
	20 : 92 D2 20 DD 57 48 6B DF 61 79 2E AA D6 3E 50 69 
	30 : 92 8E AA FC 89 F7 75 
25: WMBUS: RSSI = -88 dBm
 
~>Adding 40601327 number 8
~>RAW DATA: 
 
	00 : 32 44 68 50 27 13 60 40 69 80 A0 11 9F 27 06 00 
	10 : E0 15 00 00 2C 08 F5 07 00 00 00 00 00 00 00 00 
	20 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 
	30 : 00 00 00 
27: WMBUS: RSSI = -94 dBm
 
~>Adding 83816991 number 9
~>RAW DATA: 
 
	00 : 2F 44 68 50 91 69 81 83 95 62 A2 06 9F 27 93 00 
	10 : E0 15 9A 00 00 00 08 08 08 07 08 07 07 06 06 06 
	20 : 05 08 09 09 0A 0B 08 07 08 09 07 0B 07 09 07 08 
~>reached goal!
~>{-2087701947,828833817,1082615136,1144477297,1082614276,1082615042,-2125445851,-2144246510,1080038183,-2088670831}
~>scanned 10 devices in 20 seconds
LUA: populate WMBUS filter
28: LUA: WMBUS FILTER 01: ID 83903245
LUA: WMBUS FILTER 02: ID 31670019
LUA: WMBUS FILTER 03: ID 40876560
LUA: WMBUS FILTER 04: ID 44375671
LUA: WMBUS FILTER 05: ID 40876204
LUA: WMBUS FILTER 06: ID 40876502
LUA: WMBUS FILTER 07: ID 81504525
LUA: WMBUS FILTER 08: ID 80316512
LUA: WMBUS FILTER 09: ID 40601327
LUA: WMBUS FILTER 10: ID 83816991
LUA: destroyed all lua objects, exiting
30: NBIOT: Initializing the module...
NBIOT: Received AT response, module is up!
NBIOT: Received SIM card is present and ready!
NBIOT: MCGDEFCONT set to - 'nb.m2mc'
NBIOT: PLMNID set to - '23003'
52: NBIOT: Registered to roaming network
55: NBIOT: Got time from network
NBIOT: Setting time date...
NBIOT: Connected to IP network!
NBIOT: Time is 18:53:53+04
 
NBIOT: module setup done successfully!
SYS: --- New request ---
SYS: Battery Voltage: 3641 mV
LUA: starting lua script version 1
LUA: Starting onWake() script
~>LOAD WMBUS-NBIOT script NOW!
LUA: destroyed all lua objects, exiting
SYS: entering sleep mode
[00]

Note

After the successful finish of scanning, the found devices are set as new addresses that are going to be read. It can be seen in this part of the serial line monitoring:

 ~>scanned 10 devices in 20 seconds
LUA: populate WMBUS filter
28: LUA: WMBUS FILTER 01: ID 83903245
LUA: WMBUS FILTER 02: ID 31670019
LUA: WMBUS FILTER 03: ID 40876560
LUA: WMBUS FILTER 04: ID 44375671
LUA: WMBUS FILTER 05: ID 40876204
LUA: WMBUS FILTER 06: ID 40876502
LUA: WMBUS FILTER 07: ID 81504525
LUA: WMBUS FILTER 08: ID 80316512
LUA: WMBUS FILTER 09: ID 40601327
LUA: WMBUS FILTER 10: ID 83816991


In LUA script, the function loadit is responsible for this behavior. If needed, this part can be removed (or commented) from the LUA script.

function loadit(arr)
  filter = ""
  for i = 1,#arr do
    filter = filter .. wordToBuffer(arr[i])
  end
  api.wmbusFilter("populate", filter)
end

and also you need to remove this line, which is located in the end of the script.

loadit(ids)
public/application/wmbus_scan.txt · Last modified: 2020/10/30 19:53 by Acrios Admin