Use mesh, Lora and NB communication methods to quickly build Internet of things solutions for shared parking spaces

1, Foreword

This paper mainly discusses how to quickly realize the networking scheme analysis of shared parking spaces based on Internet of things technology.

If you want to be able to quickly build its prototype, you can choose shineblink Com. As a special development board for the Internet of things, the development board has simple programming and powerful functions.
PS: the Core can realize Wifi/Ble/NB/Lora/ThreadMesh/RFID/Eth/Usb/RS485/RS232 communication, as well as more than 30 kinds of sensors / more than 10 kinds of hardware peripherals / more than 10 kinds of Mcu built-in functions with only five or six lines of code, and these functions can be operated simultaneously in up to five random combinations. More information about Core can be found at shineblink Com.

2, Design idea of shared parking space scheme

This scheme adopts mesh wireless networking technology, Lora wireless long-distance strong penetration technology and NBIOT wireless remote communication technology. The following explains why these three wireless technologies are used.
Mesh network: each parking space adopts mesh node networking. Because mesh nodes have the advantages of low cost and large number.
Lora star network: Lora is responsible for connecting all Mesh networks in series, because Lora has a long communication distance and superior wall penetration performance. It is suitable for the communication layout of underground multi-storey parking lot.
NBIOT communication: NBIOT communication module is responsible for remote cloud communication. Generally, the whole parking lot can use one to two.

3, Specific procedures

1, Mesh networking code

--PanID and Channel decided mesh Uniqueness of network
PanID = 0x1234 --16 short 
Channel = 11 --Selection range(11~26)
MyRole = "Client" --One mesh There can be more than one in the network client role
LIB_MeshConfig(MyRole,PanID,Channel) --Start and join mesh network
--client Own name"CONTROL0"and server Mentioned at the end client The names should be consistent
ClientName = "CONTROL0" --ClientName yes Client In the network Server Unique identity identified ID
LIB_GpioOutputConfig("D8","STANDARD") --LED1
LIB_GpioOutputConfig("D9","STANDARD") --LED2
LIB_GpioWrite("D8",1) --Extinguish
LIB_GpioWrite("D9",1) --Extinguish
--Set key 1(occupy D0 mouth,Low level active)
LIB_ButtonConfig("BTN1","D10","L")
net_state = 0
​
--Start a big cycle
while(GC(1) == true)
do
    --Network status led instructions
    net_state = LIB_MeshClientNetStateQuery()
    if net_state == 2 then --client Joined mesh Net and found server
        LIB_GpioWrite("D9",0) --LED2 bright
    else
        LIB_GpioWrite("D9",1) --LED2 Extinguish
    end
    --If BTN1 Press the key briefly and client Already joined mesh And found it server,Just to Server Upload data
    key = LIB_ButtonQuery("BTN1")
    if key == 1 and net_state == 2 then
        data = {0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00} 
        LIB_MeshClientSendData(ClientName,data)
    end
    --Query whether received from server The 8-byte command is issued and parsed
    recv_flag, cmd = LIB_MeshClientRecvCommand()
    if recv_flag == 1 and #cmd == 8 then
        if cmd[1] == 0x10 then --Only parsing here server The first byte of the command issued
            LIB_GpioToggle("D8") --LED1 On or off switching
        end
    end
end

2, Lora code

--Local address(Range: 0-65535),other Lora If the node needs to know the address, it must send the message to the local machine
addr = 100 
--communication channel (Scope: 410-441MHz),Communicating with each other Lora Nodes must be on the same channel
channel = 433
--Wireless rate(Range: 0.3, 1.2, 4.8, 9.6, 19.2kpbs),The lower the rate, the higher the communication quality
baudrate = "9.6kpbs"
--Transmit power(Scope: 11, 14, 17, 20dB),The higher the value, the higher the communication quality, but the power consumption will increase
tx_pwr = "20dB"
​
--set up Lora Module occupancy TX0,RX0,Aux meet D5 Pin, Md0 meet D6 Pin
--Lora Communication parameters:address=100,communication channel =433M,Wireless rate=9.6kbps,Transmit power=20dBm
LIB_LoraConfig("UART0","D5","D6",addr,channel,baudrate,tx_pwr)
​
--Start a big cycle
while(GC(1) == true)
do
    --Query whether data is received, and respond if received
    recv_flag,recv_addr,recv_data = LIB_LoraRecv()
    if recv_flag == 1 then
        --Add 1 to all the received data as a response and return it to the sender
        for i = 1, #recv_data, 1 do 
            recv_data[i] = recv_data[i] + 1
        end
        LIB_LoraSend(recv_addr, recv_data)
    end
end

3, NBIOT cloud connection code

--MQTT Server address (for ONE NET Platform)
server_addr = "183.230.40.96" --China Mobile Internet of things MQTT Access service ip address
server_port = 1883
​
--MQTT Connection parameters (for ONE NET Platform)
mqtt_con_clientID = "TestDevice001"
mqtt_con_username = "353255"
mqtt_con_password = "version=2018-10-31&res=products%2F353255%2Fdevices%2FTestDevice001&et=1893427200&method=md5&sign=%2F5RJwGwytPWvVDB04K7rnw%3D%3D"
​
--MQTT topic Relevant parameters (applicable to ONE NET Platform)
mqtt_sub_topic = "$sys/353255/TestDevice001/cmd/request/+"--Subscription
mqtt_pub_topic = "$sys/353255/TestDevice001/dp/post/json" --For release
​
--set up m5311 NB Module occupancy TX0,RX0,D5,D6 Pin, MQTT pattern
--KeepAlive Cycle 180 seconds
LIB_NbMqttM5311Config("UART0","D5","HIGH","D6","HIGH",server_addr,server_port,mqtt_con_clientID,mqtt_con_username,mqtt_con_password,180,mqtt_sub_topic,"QOS0")
​
--to configure D9 Normal output,control LED2
LIB_GpioOutputConfig("D9","STANDARD")
--Enable the system 10 millisecond timer to start working
LIB_10msTimerConfig("ENABLE")
--set up sht3x Sensor occupancy SCL0 and SDA0 Pin, working at a frequency of 10 data per second,"HIGH"Indicates the highest accuracy
LIB_Sht3xConfig("IIC0","10","HIGH")
​
--Variable initialization
cnt_10ms = 0
cnt1_10ms = 0
pub_id = 0
temprature = 0.00
humidity = 0.00
​
--Definition 10 ms Interrupt callback function
function LIB_10msTimerCallback()
    cnt_10ms = cnt_10ms + 1
    cnt1_10ms = cnt1_10ms + 1
end
​
--Start a big cycle
while(GC(1) == true)
do
    sht3x_flag,temp,humi = LIB_Sht3xGetResult()
    --If the sensor has new temperature and humidity data
    if sht3x_flag == 1 then
        temprature = temp
        humidity = humi
    end
​
    --Query whether to receive the information sent by the server cmd data(Subscribed"$sys/353255/TestDevice001/cmd/request/+")
    recv_flag,topic,data = LIB_NbMqttM5311RecvSub()
    if recv_flag == 1 then
        --according to json route"$.LED"Resolve the information sent by the server json Text and execute LED On off operation
        Json_Val = LIB_JsonParse(data, "$.LED")
        --The server sends"{"LED":0}"
        if Json_Val == "0" then
            LIB_GpioWrite("D9",1) --LED2 Extinguish
        --The server sends"{"LED":1}"
        elseif Json_Val == "1" then
            LIB_GpioWrite("D9",0) --LED2 bright
        --The server sends"{"LED":2}"
        elseif Json_Val == "2" then
            LIB_GpioToggle("D9") --LED2 On off switching
        else 
            LIB_GpioWrite("D9",1) --LED2 Extinguish
        end
        --According to the information received topic Medium cmdid Answering server,
        --Will receive topic in"request"replace with"response"As a response topic Send to server
        topic = string.gsub(topic,"request","response") 
        --The response content can be customized. Here is"Got it!"
        LIB_NbMqttM5311SendPub("QOS0", topic, "Got it!")
    end
​
    --Send temperature and humidity data to every 5 seconds server
    if cnt_10ms >= 500 then
        cnt_10ms = 0
        pub_id = pub_id + 1
        json_str = string.format("{\"id\":%d, \"dp\":{\"temperatrue\":[{\"v\": %.2f,}], \"humidity\":[{\"v\":%.2f,}]}}", pub_id, temprature, humidity)
        --be careful json_str The total length of should not exceed 150 bytes
        LIB_NbMqttM5311SendPub("QOS0", mqtt_pub_topic, json_str) --publish
    end
    
    --Print every 12 seconds NBIOT Module information(contain sim card)
    --Note: This is just to demonstrate how to obtain module information. In practical application, you can query according to your needs, and you don't need to query all the time
    if cnt1_10ms >= 1200 then  --12000ms
        cnt1_10ms = 0
        State,IMEI,IMSI,ICCID,RSSI = LIB_NbStatusQuery()
        print(string.format("module state: %s", State))
        print(string.format("module IMEI: %s", IMEI))
        print(string.format("module IMSI: %s", IMSI))
        print(string.format("module ICCID: %s", ICCID))
        print(string.format("module RSSI: %d dBM", RSSI))
    end
end

**The above procedures are some routines on the official website and need to be changed accordingly.

4, Conclusion

Through the shineblink core IOT development board, you can quickly build the corresponding IOT shared parking space solution, which can easily solve the problem of poor signal in some underground parking lots.

Tags: Single-Chip Microcomputer IoT Network Communications hardware

Posted by derwert on Wed, 04 May 2022 04:33:42 +0300