基于C++的IOT网关和平台1:github项目ctGateway

初级代码游戏的专栏介绍与文章目录-CSDN博客

我的github:codetoys,所有代码都将会位于ctfc库中。已经放入库中我会指出在库中的位置。

这些代码大部分以Linux为目标但部分代码是纯C++的,可以在任何平台上使用。

源码指引:github源码指引_初级代码游戏的博客-CSDN博客


这是一个开源项目,LGPL许可。github位置:https://github.com/codetoys/ctGateway.git

支持Modbus等常见协议,可以定制上报规则和语法,可以扩展协议支持。主要是经过了工厂环境考验,基本架构稳定性比较好,程序该考虑的通用问题都考虑到了。

什么意思呢,意思是各种现场BUG都遇到了,都做了预防,作为一个通用的基础架构是比较理想的。

网关程序基于C++和linux,只需要基本的linux环境,附加依赖的东西都可以自行编译,可以交叉编译为arm,整个程序包括依赖的库不到10M,可以在很小的设备上运行。CPU占用率都测过了,很低(有些设备散热不好,CPU占用率要严格控制)。

网关嘛,一般是个控制台程序,没啥好看。配套的管理工具大概是这样的(就像个专有的MQTT客户端):

这个工具很方便,所有网关支持的指令都支持,还支持通过MQTT远程执行指令和文件传输(也就是原本用telnet和ftp实现的能力在这个网关和工具上用MQTT实现了)。大部分指令也支持批量操作。

文档是比较多的,而且还在补充中,目前的文档是这些(就是项目根目录下的index.html):

下面是readme.md的格式化版本:

目录

ctGateway (Engish-Chinese 英文中文对照)

ctGateway

[introduction 介绍](#introduction 介绍)

[Source 源码](#Source 源码)

[Copyright 许可证](#Copyright 许可证)

ManageTools

[introduction 介绍](#introduction 介绍)

ServerDemon

[introduction 介绍](#introduction 介绍)

[Document 文档](#Document 文档)

[Quick Guide 快速指南](#Quick Guide 快速指南)

[1. Compile and run 编译和运行](#1. Compile and run 编译和运行)

[2. North Config MQTT config 北向配置 MQTT配置](#2. North Config MQTT config 北向配置 MQTT配置)

[3. Using Modbus 使用Modbus](#3. Using Modbus 使用Modbus)

[4. Using Tunnel Protocol(Transparent transmission) 使用隧道协议(透传)](#4. Using Tunnel Protocol(Transparent transmission) 使用隧道协议(透传))

[5. Using Custom Protocol 使用定制协议](#5. Using Custom Protocol 使用定制协议)

[6. More protocols 更多协议](#6. More protocols 更多协议)

[7. ServerDemon and MySql](#7. ServerDemon and MySql)

[8. ManageTools and MySql](#8. ManageTools and MySql)


ctGateway (Engish-Chinese 英文中文对照)

IOT gateway C++ OpenSSL GmSSL Linux Arm/Arm64

Open Source , Modular and Scalable

物联网网关 C++ OpenSSL GmSSL Arm/Arm64

开源 模块化 可扩展

ctGateway

introduction 介绍

The gateway program is implemented in C++,Use the UTF-8 character set.<br>

Support Modbus and transparent transmission, MQTT and MQTTS.<br>

Log files and data files are limited in size to ensure that there is no disk full failure.<br>

The data is saved instantly to ensure not lost data when power lost.<br>

The data sequence number and confirmation mechanism ensure that there is no data loss from the gateway to the platform.<br>

The storage capacity of the network is different depending on the amount of data, and the gateway supports data compression.<br>

This program has been tested in harsh production environments in large quantities,<br>

Performance, stability, reliability, and environmental adaptability have all been verified.<br>

网关程序以C++实现,使用utf-8字符集。<br>

支持Modbus和透传,支持MQTT和MQTTS。<br>

日志文件和数据文件大小受限,确保不出现磁盘满故障。<br>

数据即时存盘,确保断电不丢失。<br>

数据序号和确认机制保证网关到平台不存在数据丢失。<br>

断网存储能力取决于数据量,网关支持数据压缩。<br>

这个程序已经经过了大批量恶劣生产环境的考验。<br>

性能、稳定性、可靠性、环境适应性均经过了验证。<br>

Source 源码

subdirectory ctGateway<br>

Gateway program, C++, Linux.<br>

The sln file can be opened with Visual Studio 2022, but only used to edit file.<br>

How to compile the project see [readme.txt](ctGateway/readme.txt) in subdirectory ctGateway.<br>

子目录 ctGateway<br>

网关程序, C++, Linux.<br>

sln 文件可以用 Visual Studio 2022 打开, 但只用来编辑。<br>

如何编译项目请看子目录ctGateway下的 [readme.txt](ctGateway/readme.txt)。<br>

Please see the file [LICENSE](./LICENSE) for copyright.<br>

Copyright notices for third-party software used in this software:<br>

See [third-party-LICENSE.txt](./third-party-LICENSE.txt)<br>

请看文件 [LICENSE](./LICENSE) 了解许可证信息。<br>

本软件用到的第三方软件的许可证信息:<br>

请看 [third-party-LICENSE.txt](./third-party-LICENSE.txt)<br>

ManageTools

introduction 介绍

Supporting management tools.(a mqtt client)<br>

C# .Net 8.0<br>

The basic functionality depends MQTT only.<br>

The program is for testing purposes only.<br>

配套的管理工具。(一个 mqtt 客户端工具)<br>

C# .Net 8.0<br>

基本功能仅仅依赖 MQTT 。<br>

这个程序仅用作测试目的<br>

ServerDemon

introduction 介绍

Simple server to insert all mqtt message into MySql database.<br>

C# .Net 8.0<br>

It also supported InfluxDB(in source code).

The program is just a demo.<br>

用来把mqtt消息插入MySql数据库的服务程序。<br>

C# .Net 8.0<br>

也支持InfluxDB(在源码里)。

这个程序只是个演示<br>

Document 文档

Please see the file [index.html](https://codetoys.github.io/ctGateway/index.html) , English and Chinese.<br>

请看文件 [index.html](https://codetoys.github.io/ctGateway/index.html) ,英文和中文。<br>

Quick Guide 快速指南

1. Compile and run 编译和运行

Linux or Linux virtual machine, MQTT broker(server), [Developer Guide](https://codetoys.github.io/ctGateway/doc/en/ctGateway_DeveloperGuide.htm)<br>

Linux 或 Linux 虚拟机, MQTT 代理(服务器), [开发指南](https://codetoys.github.io/ctGateway/doc/zh/ctGateway_DeveloperGuide.htm)<br>

2. North Config MQTT config 北向配置 MQTT配置

defaultNorthConfig.json:

```json

{

"func": "connt",

"data": {

"comment": "本机测试",

"type": "MQTTS",

"platform": "localtest",

"hostname": "mqtt.test.com",

"port": "8883",

"userid": "user",

"upwd": "user1234",

"ntp": "time.windows.com"

}

}

```

3. Using Modbus 使用Modbus

```json

{

"func": "conf",

"data": [

{

"protocolCode": "MODBUS_TCP",

"protocolName": "ModbusTcp协议",

"resolvePropertyMap": {

"port": "10503",

"rate": "30000",

"ip": "127.0.0.1"

},

"confTabs": [

{

"deviceCode": "device503",

"stationCode": "1",

"resolveParamConfigVOList": [

{

"paramCode": "code1",

"paramName": "工单规格",

"dataType": "ushort",

"paramAddr": "0001",

"functionCode": "03",

"transferRuleStr": "",

"dataLength": 1,

"processType": "3",

"reportStrategy": 1

},

{

"paramCode": "code2",

"paramName": "负值",

"dataType": "short",

"paramAddr": "0002",

"functionCode": "03",

"transferRuleStr": "",

"dataLength": 1,

"processType": "3",

"reportStrategy": 1

},

{

"paramCode": "codef1",

"paramName": "浮点",

"dataType": "float",

"paramAddr": "0004",

"functionCode": "03",

"transferRuleStr": "ABCD",

"dataLength": 1,

"processType": "3",

"reportStrategy": 1

}

]

}

]

}

]

}

```

4. Using Tunnel Protocol(Transparent transmission) 使用隧道协议(透传)

```json

{

"func": "conf",

"data": [

{

"protocolCode": "TCP_TUNNEL",

"protocolName": "TCP隧道协议",

"resolvePropertyMap": {

"ip": "192.168.136.1",

"port": "503",

"rate": "30000"

},

"confTabs": [

{

"deviceCode": "deviceTcpTunnel",

"encodeType": "hex",

"resolveParamConfigVOList": [

{

"paramCode": "read",

"paramName": "从0开始读取10个保持寄存器",

"paramCommand": "00 06 00 00 00 06 01 03 00 00 00 0A"

}

]

}

]

},

{

"protocolCode": "SERIAL_PORT_TUNNEL",

"protocolName": "串口隧道协议",

"resolvePropertyMap": {

"rate": "30000",

"serial_port": "/dev/ttyS0",

"baudRate": 115200,

"parity": "N",

"dataBit": 8,

"stopBit": 1,

"timeout": 1

},

"confTabs": [

{

"deviceCode": "deviceSerialPortTunnel",

"encodeType": "hex",

"resolveParamConfigVOList": [

{

"paramCode": "read",

"paramName": "从0开始读取10个保持寄存器",

"paramCommand": "01 03 00 00 00 0A C5 CD "

}

]

}

]

}

]

}

```

5. Using Custom Protocol 使用定制协议

gateway/gwprotocol/ProtocolDemo.h .cpp

QJ57B_1A is an instrument for measuring the resistance of a cable.<br>

QJ57B_1A 是一款测量电缆电阻的仪器.<br>

```json

{

"func": "conf",

"data": [

{

"protocolCode": "TCP_DEMO",

"protocolName": "TCP demo协议",

"resolvePropertyMap": {

"ip": "192.168.213.1",

"port": "2200",

"rate": "30000"

},

"confTabs": [

{

"deviceCode": "QJ57B_1A",

"encodeType": "hex",

"deviceModel": "QJ57B_1A"

}

]

}

]

}

```

6. More protocols 更多协议

Some of the adapted protocols will be available in an extended manner<br>

部分适配过的协议将以扩展的方式提供<br>

DLT645,Siemens S7,OPC-UA<br>

7. ServerDemon and MySql

Connection info just in source code.<br>

连接信息就在源码里。

8. ManageTools and MySql

Connection info is ("127.0.0.1", "user1", "user1", "gateway").<br>

Of course, I could change to parameterization.<br>

连接信息是("127.0.0.1", "user1", "user1", "gateway")。<br>

当然,我可以改成参数化的。<br>

相关推荐
爱凤的小光4 分钟前
图漾官网Sample_V1版本C++语言完整参考例子---单相机版本
开发语言·c++·数码相机
青瓦梦滋10 分钟前
【语法】C++的继承
开发语言·c++
ttk2191 小时前
【算法练习】归并排序和归并分治
数据结构·c++·算法·排序算法
Code_流苏1 小时前
如何使用Git参与GitHub开源项目:入门全流程
git·开源·github·开源项目·入门学习
mooridy1 小时前
设计模式 | 详解常用设计模式(六大设计原则,单例模式,工厂模式,建造者模式,代理模式)
c++·设计模式
梁辰兴2 小时前
数据结构:实验7.3Huffman树与Huffman编码
数据结构·c++·算法·c
小_t_同学2 小时前
C++之类和对象:构造函数,析构函数,拷贝构造,赋值运算符重载
开发语言·c++
wuqingshun3141592 小时前
经典算法 最长单调递增子序列
java·c++·算法·蓝桥杯·机器人