Chongqing Gas Group Corporation wants to deploy next-generation gas meters to millions of family housing units to help monitor gas-meter status and gas usage automatically.
JCBLE, a startup established in 2014, is a vendor of Chongqing Gas. JCBLE offers Internet of Things (IoT) solutions; their key technology is long-distance wireless data transfer.
Normally, the signal from a wireless access point (AP) covers one building floor. But APs using JCBLE technologies can cover more than three building floors and a wider area. That's the reason Chongqing Gas selected JCBLE as their partner.
The pain point for JCBLE is that they are skilled in device and wireless data transfer but not in server-side technologies. Before they met Microsoft, they had only one service, named "NS Service," running on a single Ubuntu Linux computer to receive and decrypt data from sensor devices. They needed a way to scale up device connections and add a message store with high availablity. Microsoft Azure offers the server-side capabilities that JCBLE needs, including IoT Hub, Stream Analytics, SQL Database, and Blob storage.
JCBLE is using a customized version of Linux on their device that they call simply "Gateway." The Gateway is a transparent device. Any endpoint device with sensors issued by JCBLE can connect to any Gateway device without configuration. So the JCBLE wireless solution is very easy to deploy.
For security, data transfer between sensor devices, Gateway devices, and NS Service is encrypted by JCBLE. All devices are logged in the JCBLE database, and NS Service issues a security token to each device. (The encryption methods are confidential.)
![picture of team working]({{ site.baseurl }}/images/2016-12-22-JCBLE/team-1.jpg)
![picture of team working]({{ site.baseurl }}/images/2016-12-22-JCBLE/team-2.jpg)
## Customer profile ##
[Chongqing JCBLE Network Technology Co., Ltd.](http://www.jcble.com) was founded in May 2014. The company is mainly engaged in wireless IoT with augmented reality (AR) technology in both software and hardware design, as well as research and development. Based on their core technology, they provide AR-based solutions related to building smart cities, intelligent scenic spots, intelligent businesses, and so on.
## Problem statement ##
In the past ten years, a thousand employees of Chongqing Gas would periodically read gas meters. To save operating costs, Chongqing Gas decided to deploy a new generation of gas meters that include IoT functionality.
After the gas meters are deployed, employees won't need to knock on doors to check the meter readings. A few employees in the office will be able to monitor the meters and analyize gas-usage trends, saving ¥30 million in operating costs each year.
By using the JCBLE wireless solution, Chongqing Gas doesn't need to deploy cable to each housing unit. A few JCBLE Gateway devices around the building would save hundreds of millions of yuan for Chongqing Gas. The challenge is that, on the server side, JCBLE can offer only one Linux server for collecting data, with no further data-processing ability.
Per the requirements of Chongqing Gas, each gas meter sends one data packet every 30 seconds. The size of each data packet is less than 1 KB. In a scenario with one million devices, the server side must process 2,880,000,000 data packets per day. A single Linux server simply can't the load. JCBLE needs a way to collect the data from millions of gas meters.
Another challenge is that JCBLE doesn't have the ability to analyize real-time data and historical data. When a malfunctioning gas meter sends abnormal data, JCBLE needs to generate an alert to notify Chongqing Gas employees. And Chongqing Gas needs trend graphs so that they can adjust their natural-gas pressure.
> “We have to find an easy way to collect gas-meter data from millions of gas meters. JCBLE is a startup company; we cannot afford payment for a lot of engineers on the server side.” —Shiping Li, CTO, JCBLE
> “In cooperation with Microsoft, we want to enable Azure to help us resolve the problems that we are facing.” —Chili Meng, CEO, JCBLE
Communication between the JCBLE Linux server and Gateway devices is double encrypted (AMQP over TLS and JCBLE encryption) and uses a private protocol. The challenge of integrating IoT Hub with the JCBLE on-premises solution is decrypting data sent from the Gateway on the server side. After the data is decrypted, it can be processed by Stream Analytics and other Azure services.
## Solution and steps ##
JCBLE and Microsoft teamed up to create a proof of concept that would simulate the key measurements to be collected from a Gateway device, which will be located on an apartment building. The data is sent from the sensors through the Gateway to an Azure IoT hub, where the data is decrypted by a JCBLE service running on Linux. The decrypted data is saved to Azure Event Hubs and handled by Stream Analytics, where alerts are generated for abnormal events and aggregated data is stored for insight into the overall status of the housing units.
The solution was developed over the course of a few days at a hackfest held at the JCBLE office in Chongqing. The Microsoft DX China team worked with JCBLE on the following tasks:
- Knowledge transfer about Azure deployment (Azure Resource Manager, Storage, Virtual Machines, IoT Hub, Stream Analytics, and so on)
- Add IoT Hub to the front end to provide real-time data transmission from device to cloud
- Create an application, named IoTConnector, that retrieves data and sends it to NS Service for data decryption
- Deploy NS Service behind Azure Internal Load Balancer for best performance
- Use Stream Analytics to analyze real-time data, generate alerts, and put data into various locations
> “It's amazing that Azure can really help us solve the problems we are facing. The Microsoft team is working with us,
coding with us, and coaching us how to set up Azure services. It's really helpful.” —Shiping Li
The gas meter device sends two packets of encrypted data every minute to IoT Hub through the Gateway device. When a data packet arrives, IoTConnector retrieves it and sends it to NS Service for decryption. After the data is decrypted, IoTConnector saves the data to Event Hubs. Then a Stream Analytics job processes the data. The data includes a device ID that is used by the rest of the system to determine the tenant to whom the device belongs.
The Gateway devices communicates with IoT Hub using the AMQP protocol over a TLS connection. Each device has a unique access token, that is scoped to allow the device to send data to IoT Hub but not to allow any management of the device registry.
The data from the gas meter depends on NS Service for decryption. For best performance, the NS Service application has been changed to a stateless model and deployed behind Azure Internal Load Balancer. IoTConnector can also be deployed as multiple instances. It can retrieve data from one or more specific IoT Hub queues and then send encrypted data to NS Service
for data decryption.
The Stream Analytics job has two queries: a raw data query and an alert query. All data is placed in Blob storage as historical data for HDInsight analysis in future. Some alert data will be save to SQL Database.
## Technical delivery ##
IoTConnector connects to queues in IoT Hub and retrieves encrypted data as it comes from the gas meters. To retrieve data, we
used Event Hub SDK, which also establishes TCP/UDP endpoint connections as shown in the following code. (In the old architecture, NS Service was designed to receive data from an UDP port for efficiency. JCBLE doesn't want to change NS Service a lot, so IoTConnector uses a UDP port for compatibility.)
_infoLogger.InfoFormat("Buffer data : {0} has been written to Event Hub.", Convert.ToBase64String(buffer));
}
}
Thread.Sleep(50);
}
}
catch (Exception ex)
{
_errorLogger.ErrorFormat("Handling TCP received data encounter error: {0}",
ex.ToString().Replace("\r\n", " "));
// Reconnect
try
{
Close();
Open();
}
catch
{
}
}
}
```
The decrypted data from NS Service looks like this:
```json
{
"originData": {
"gw": null,
"mote": null,
"app": {
"moteeui": "ffffffffffffff01",
"dir": "up",
"userdata": {
"seqno": 0,
"port": 1,
"payload": "AgEAD0JAAA7w4wAAUV0ABHYxLjA"
},
"motetx": {
"freq": 481.5,
"mode": null,
"datr": "SF12BW125",
"codr": "4/5",
"adr": false
},
"gwrx": [{
"eui": "fffe020100000011",
"time": "2016-12-21T03:24:34Z",
"timefromgateway": false,
"chan": 4,
"rfch": 0,
"rssi": -13,
"lsnr": 9
}]
}
},
"userData": {
"type": 2,
"code": 1,
"bought": 3.84,
"left": 3.584,
"used": 0.0,
"status": 1024,
"version": "v1.0",
"time": "2016-12-21T03:24:34Z"
}
}
```
When decrypted data arrives in Event Hub, it goes into Stream Analytics. To save raw data to Blob storage, we use the following SQL statements:
```sql
SELECT
originData.app.moteeui AS [DeviceID],
userData.[time] AS [DateTime],
userData.[type] AS [MeterType],
userData.[code] AS [FactoryCode],
userData.[bought] AS [Bought],
userData.[left] AS [Remaining],
userData.[used] AS [TotalUsed],
userData.[status] AS [MeterStatus],
userData.[version] AS [MeterSoftwareVer]
INTO BlobOutput
FROM EventHubInput
```
To generate alerts, we focus on gas meters that read less than 5 cubic meters, as shown here:
```sql
SELECT
originData.app.moteeui AS [DeviceID],
userData.[time] AS [DateTime],
userData.[type] AS [MeterType],
userData.[code] AS [FactoryCode],
userData.[bought] AS [Bought],
userData.[left] AS [Remaining],
userData.[used] AS [TotalUsed],
userData.[status] AS [MeterStatus],
userData.[version] AS [MeterSoftwareVer]
INTO SQLOutput
FROM EventHubInput
WHERE Remaining <5.0
```
## Conclusion ##
The proof of concept is now complete and deployed into the JCBLE Azure subscription. JCBLE is now working with Chongqing Gas to build a small physical network to verify the whole solution. Learnings from the pilot will be integrated into other JCBLE solutions that will become available for other JCBLE customers.
> “It's happy to work with Microsoft. In these days we learned a lot of knowledge about Azure services. Azure really helped us resolve the problems we are facing. IoT Hub can help us scale up the ability of device connecting, and Stream Analytics can analyze real-time data without development.” —Shiping Li
## Additional resources ##
- To cross-compile the IoT Hub SDK on their Gateway devices, JCBLE referenced [Cross Compiling the Azure IoT Hub SDK](https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/SDK_cross_compile_example.md).
- For interoperability with Azure Event Hubs, we referenced [Get started sending messages to Event Hubs](https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-csharp-ephcs-getstarted)
- For Stream Analytics query syntax, see [Stream Analytics Query Language Reference](https://msdn.microsoft.com/en-us/library/azure/dn834998.aspx)
- For more information on JCBLE technologies, see this news release: [JCBLE innovative JuRa protocol for wireless transmission](http://www.lieyunwang.com/archives/190239)