The narrow band internet of things is coming, as known as NBIoT, which is used for machine to machine communications. Examples are devices for meter reading like electricity, gas, or water consumption. They are often stationary, thus need not an optimized handover. Only a small amount of data is usually transferred, which is even not delay sensitive. However, the number of these devices may become quite big, even up to several orders of magnitude compared to the traditional devices. NB-IoT network is consist of terminal devices, radio access network, core network, IoT server platform and user applications. This part focuses on the IoT server platform and user applications.
System Overview
The details of the network elements from the service operators are ignored here. I just view this system from the applications perspective. There are 5 subsystem for the whole application system. The IOT device part, the data receiving server, the web server, the database and the browser part.
The IOT device part contains sensors, micro control unit and the IOT module. Of course, devices like Raspberry PI or android devices that have operation system will also be ok, I just keep it simple, the control unit has no operation system, the IOT module is used for network acccessing. I will left this part for another article. And a fake client which can send UDP datagrams will used for testing. So no OS, no software updates. I won’t have to consider the NAT hole punching problems.
The data receving server should be accessible through the Internet. MySQL is used as the database. And the webserver is nginx. Actully the web part is a stand alone project and there is too much non-technical business logic. I will start another writing for that.
The browser part can be iOS app, android app, browser on mobile devices or laptops or even WeChat programs. I am not interested in this part, and it’ll be quite easy to implement.
The Data Collection Server
The messages are sent to this server. This server should have a mirror backup for redundancy. If there are performance issues, some load sharing machenism can be involved, the database can be separated if necessary.
Message Reception
The IOTMsgReception is for fetching a incoming message from the socket, transfer it from the bytes to a string and append it to the message queue. The message queue is a typical FIFO structure without size limit. At the same time, the queue is thread safe.
1 | import socket |
Message Processor
IOTMsgProcessors get the message simutaneously from the message queue in parallel, one processor holds a permanent connection to the database. Once the message is processed, it’ll be write to the database.
1 | import threading |
The Main Function
The main creates the queue, the reception thread and the processor threads, finally goes to sleep to wait for joining all the threads.
1 | from queue import Queue |
Configuration File
1 | [db] |
The Client Simulation For Test
Pack a udp datagram and send it out, I was trying to fake the source IP address to make the data more real, but because of the existence of NAT, the source IP address has been changed when it arrives at the server. It’s all right for the simple test, so I’d like to just keep it like this.
1 | from kamene.all import * |