一、设计目的
随着信息网络技术的不断发展,各类规模大小不等,设备种类不同的网络设备机房随着数据处理能力和数据量急剧增长。数据中心机房内,环境监控十分重要,一旦机房环境出问题,轻则引起服务器故障,重则导致大量设备损毁和数据丢失,甚至酿成火灾。结合现有的XR806
开发板,作为一个IOT模组,可以拿来实现一个搭配鸿蒙APP的IOT智慧机房方案,实现对机房环境温湿度、烟感等的实时检测、查看、设置和报警功能。
二、系统组成及功能说明
XR806芯片是一款基于安谋科技STAR-MC1处理器来研发设计的支持WIFI和BLE的高集成度无线MCU芯片,同时搭载了鸿蒙L0系统,眼下鸿蒙开发正当热,所以想到将XR806运用于机房中,实现对机房环境的实时检测,并上报到自家服务平台,同时开发一个鸿蒙APP实现对其的查看,设置功能等。
此次先实现的是将手上现有的sht30温湿度传感器模块外接到XR806上,通过I2C通讯,对传感器实时采集温湿度数据;然后通过MQTT协议将XR806设备注册到自己搭建的服务器平台,同时维持心跳,并将主控实时采集到的温湿度数据上报到MQTT服务器;最后,自行开发一个鸿蒙
手机APP,通过WebSocket协议实现对温湿度传感器数据的实时展示及报警阈值设置等业务功能。
三、具体实施步骤- 环境及物料准备
编译环境采用的是openharmony官网的docker镜像(省去了自己折腾环境的过程)
XR806开发板、sht30温湿度传感器模块、鸿蒙系统的手机、自己搭建的服务器一台。
sht30温湿度传感器模块通过I2C0引脚外接到XR806上(参照主芯片引脚说明图进行接线)。
参照如上两图;sht30和主控I2C通讯,使用I2C0,手动将sht30上的GND接到XR806的11引脚,将SDA和SCL接到XR806上的第7、8引脚。
2.新建工程及代码实现
参考ohosdemo目录下的各种demo示例代码,创建自己的工程目录iot_smartroom。
目录结构如下:
- iot_smartroom
- |-- BUILD.gn
- |-- include
- | |-- i2c.h
- | |-- mqtt.h
- |-- src
- |-- i2c.c
- |-- main.c
- |-- mqtt.c
其中mqtt.c是封装了mqtt相关接口,i2c.c是封装了i2c相关接口,main.c负责业务流程,依赖mqtt.h和i2c.h中提供的接口进行调用(后续再将main.c中有关wifi热点扫描及连接的接口独立封装出来)
详细代码如下:
devicexradioxr806ohosdemoBUILD.gn
新增"iot_smartroom:app_smartroom"
- group("ohosdemo") {
- deps = [
- #"hello_demo:app_hello",
- #"iot_peripheral:app_peripheral",
- #"wlan_demo:app_WlanTest",
- #"led:app_led",
- "iot_smartroom:app_smartroom",
- ]
- }
devicexradioxr806ohosdemoiot_smartroomBUILD.gn
- import("//device/xradio/xr806/liteos_m/config.gni")
- static_library("app_smartroom") {
- configs = []
- sources = [
- "src/main.c",
- "src/i2c.c",
- "src/mqtt.c",
- ]
- cflags = board_cflags
- include_dirs = board_include_dirs
- include_dirs += [
- "//kernel/liteos_m/kernel/arch/include",
- "include",
- "//base/iot_hardware/peripheral/interfaces/kits",
- ".",
- "//utils/native/lite/include",
- "//foundation/communication/wifi_lite/interfaces/wifiservice",
- "//device/xradio/xr806/xr_skylark/project"
- ]
- }
- devicexradioxr806ohosdemoiot_smartroomsrci2c.c 主要代码:
- #include
- #include
- #include
- #include "stdarg.h"
- #include "kernel/os/os.h"
- #include "i2c.h"
- #include "ohos_init.h"
- #define I2C_SPEED (400000)
- #define I2C_DEVICE_ADDR (0x45)
- #define I2C_DEVICE_ID_ADDR (0x0F)
- #define I2C_DEVICE_ID (0x65)
- #define I2C_ID (0)
- static OS_Thread_t g_main_thread;
- static SHT30_DATA sht30_data;
- static unsigned char sht30_checkcrc(unsigned char data[], unsigned char numOfBytes, unsigned char checkSum)
- {
- unsigned char crc = 0xFF;
- unsigned char bit = 0;
- unsigned char byteCtr ;
- const unsigned short POLYNOMIAL = 0x131;
- for(byteCtr = 0; byteCtr < numOfBytes; ++byteCtr)
- {
- crc ^= (data[byteCtr]);
- for ( bit = 8; bit > 0; --bit)
- {
- if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL;
- else crc = (crc << 1);
- }
- }
- if(crc != checkSum)
- return 1;
- else
- return 0;
- }
- static float sht30_calcrh(unsigned short u16sRH)
- {
- float humidityRH = 0; // variable for result
-
- u16sRH &= ~0x0003; // clear bits [1..0] (status bits)
- //-- calculate relative humidity [%RH] --
- humidityRH = (100 * (float)u16sRH / 65535); // RH = rawValue / (2^16-1) * 10
-
- return humidityRH;
- }
- static float sht30_calctemperature(unsigned short u16sT)
- {
- float temperature = 0; // variable for result
- u16sT &= ~0x0003; // clear bits [1..0] (status bits)
- //-- calculate temperature [℃] --
- temperature = (175 * (float)u16sT / 65535 - 45); //T = -45 + 175 * rawValue / (2^16-1)
-
- return temperature;
- }
- static int sht30_init(void)
- {
- int s32Ret;
- unsigned char send_data[2] = {0x23, 0x34};
- s32Ret = IoTI2cWrite(I2C_ID, I2C_DEVICE_ADDR, send_data, 2);
- if (s32Ret != 0) {
- printf("Error: I2C write s32Ret = 0x%x!rn", s32Ret);
- return -1;
- }
- return 0;
- }
- int IotI2C_Init(void)
- {
- int s32Ret = 0;
- s32Ret = IoTI2cInit(I2C_ID, I2C_SPEED);
- if(s32Ret != 0){
- printf("IoTI2cInit failed.rn");
- return -1;
- }else{
- printf("IoTI2cInit success.rn");
- }
- s32Ret = sht30_init(); //sht30温湿度模块初始化
- if(s32Ret != 0){
- printf("sht30_init failed.rn");
- return -1;
- }else{
- printf("sht30_init success.rn");
- }
- return 0;
- }
- int IoTI2c_Deinit(void)
- {
- IoTI2cDeinit(I2C_ID);
- return 0;
- }
- int IotI2C_ReadData(SHT30_DATA *pData)
- {
- float a = 0;
- unsigned int s32Ret;
- float temperature = 0;
- float humidity = 0;
- unsigned char data[3]; //data array for checksum verification
- unsigned short dat, tmp;
- unsigned char SHT3X_Data_Buffer[6]; //byte 0,1 is temperature byte 4,5 is humidity
- unsigned char send_data[2] = {0xE0,0x00};
- s32Ret = IoTI2cWrite(I2C_ID, I2C_DEVICE_ADDR, send_data, 2);
- if (s32Ret != 0) {
- printf("Error: I2C write s32Ret = 0x%x!rn", s32Ret);
- return -1;
- }
- s32Ret = IoTI2cRead(I2C_ID, I2C_DEVICE_ADDR, SHT3X_Data_Buffer, 6);
- if (s32Ret != 0) {
- printf("Error: I2C read s32Ret = 0x%x!rn", s32Ret);
- return -1;
- }
- //check tem
- data[0] = SHT3X_Data_Buffer[0];
- data[1] = SHT3X_Data_Buffer[1];
- data[2] = SHT3X_Data_Buffer[2];
- tmp = sht30_checkcrc(data, 2, data[2]);
- if(!tmp) /* value is ture */
- {
- dat = ((unsigned short)data[0] << 8) | data[1];
- temperature = sht30_calctemperature(dat);
- printf("Temperature = %frn",temperature);
- }
- //check humidity
- data[0] = SHT3X_Data_Buffer[3];
- data[1] = SHT3X_Data_Buffer[4];
- data[2] = SHT3X_Data_Buffer[5];
- tmp = sht30_checkcrc(data, 2, data[2]);
- if(!tmp) /* value is ture */
- {
- dat = ((unsigned short)data[0] << 8) | data[1];
- humidity = sht30_calcrh(dat);
- printf("Humidity = %.02frn",humidity);
- }
- pData->temperature = temperature;
- pData->humidity = humidity;
- return 0;
- }
devicexradioxr806ohosdemoiot_smartroomsrcmqtt.c 主要代码:
- #include
- #include
- #include "ohos_init.h"
- #include "kernel/os/os.h"
- #include "iot_gpio.h"
- #include "wifi_device.h"
- #include "net/mqtt/MQTTClient-C/MQTTClient.h"
- #define MQTT_DEMO_USERNAME "admin"
- #define MQTT_DEMO_PASSWORD "Unionman"
- #define MQTT_DEMO_CLIENT_ID "plug_ipc"
- #define MQTT_DEMO_BUF_SIZE (2*1024)
- static MQTTPacket_connectData mqtt_demo_connectData = MQTTPacket_connectData_initializer;
- static Client mqtt_client;
- static Network mqtt_demo_network;
- static int max_duty_ratio = 0;
- int IoTMqtt_init(void)
- {
- char *send_buf;
- char *recv_buf;
- mqtt_demo_connectData.clientID.cstring = MQTT_DEMO_CLIENT_ID;
- mqtt_demo_connectData.keepAliveInterval = 30; // 30s
- mqtt_demo_connectData.cleansession = 0;
- mqtt_demo_connectData.MQTTVersion = 4; //Version of MQTT 3.1.1
- send_buf = malloc(MQTT_DEMO_BUF_SIZE);
- if (send_buf == NULL) {
- printf("no memoryn");
- return -1;
- }
- recv_buf = malloc(MQTT_DEMO_BUF_SIZE);
- if (recv_buf == NULL) {
- free(send_buf);
- printf("no memoryn");
- return -1;
- }
- /* init network */
- NewNetwork(&mqtt_demo_network);
- /* init mqtt client object */
- MQTTClient(&mqtt_client, &mqtt_demo_network, 6000,
- (unsigned char *)send_buf, MQTT_DEMO_BUF_SIZE,
- (unsigned char *)recv_buf, MQTT_DEMO_BUF_SIZE);
- /* set username and password */
- mqtt_demo_connectData.username.cstring = MQTT_DEMO_USERNAME;
- mqtt_demo_connectData.password.cstring = MQTT_DEMO_PASSWORD;
- return 0;
- }
- int IoTMqtt_connect(char *host_name, char *host_port)
- {
- int ret = -1;
- ret = ConnectNetwork(&mqtt_demo_network, host_name, atoi(host_port));
- if (ret != 0) {
- printf("mqtt connect faild, ret:%d, host:%s, port:%sn", ret, host_name, host_port);
- goto exit;
- }
- ret = MQTTConnect(&mqtt_client, &mqtt_demo_connectData);
- if (ret != 0) {
- printf("mqtt connect faild, ret:%dn", ret);
- mqtt_demo_network.disconnect(&mqtt_demo_network);
- goto exit;
- }
- printf("mqtt connectedn");
- exit:
- return ret;
- }
- int IoTMqtt_subscribe(char *topic)
- {
- int ret = -1;
- if (mqtt_client.isconnected) {
- ret = MQTTSubscribe(&mqtt_client, topic, 0, NULL);
- if (ret != 0)
- printf("mqtt subscribe faild ret:%dn", ret);
- }
- return ret;
- }
- int IoTMqtt_unsubscribe(char *topic)
- {
- int ret = -1;
- if (mqtt_client.isconnected) {
- ret = MQTTUnsubscribe(&mqtt_client, topic);
- if (ret != 0)
- printf("mqtt unsubscribe faild, ret:%dn", ret);
- }
- return ret;
- }
- int IoTMqtt_publish(char *topic, char *msg)
- {
- int ret = -1;
- MQTTMessage message;
- memset(&message, 0, sizeof(message));
- message.qos = 0;
- message.retained = 0; /* disable retain the message in server */
- message.payload = msg;
- message.payloadlen = strlen(msg);
- ret = MQTTPublish(&mqtt_client, topic, &message);
- if (ret != 0)
- printf("mqtt publish faild, ret:%dn", ret);
- return ret;
- }
- int IoTMqtt_disconnect(void)
- {
- int ret = -1;
- if (mqtt_client.isconnected) {
- ret = MQTTDisconnect(&mqtt_client);
- if (ret != 0)
- printf("mqtt disconnect fail, ret:%dn", ret);
- mqtt_demo_network.disconnect(&mqtt_demo_network);
- }
- return ret;
- }
- void IoTMqtt_deinit(void)
- {
- if (mqtt_client.buf) {
- free(mqtt_client.buf);
- mqtt_client.buf = NULL;
- }
- if (mqtt_client.readbuf) {
- free(mqtt_client.readbuf);
- mqtt_client.readbuf = NULL;
- }
- }
- devicexradioxr806ohosdemoiot_smartroomsrcmain.c主要代码:
- #include
- #include "wifi_device.h"
- #include "ohos_init.h"
- #include "kernel/os/os.h"
- #include "mqtt.h"
- #include "i2c.h"
- #include "common/framework/net_ctrl.h"
- #define IOT_DEVICEID "666666"
- #define MQTT_DEMO_HOST_NAME "192.168.220.220" //MQTT服务器IP
- #define MQTT_DEMO_PORT "1883"
- #define WIFI_DEVICE_CONNECT_AP_SSID "yur"
- #define WIFI_DEVICE_CONNECT_AP_PSK "06184188"
- #define MQTT_PUB_REG_TOPIC "/device/register" //设备注册
- #define MQTT_PUB_HEART_TOPIC "/device/heartbeat" //设备心跳
- #define MQTT_PUB_TEM_TOPIC "/door/device/temperature" //设备发布温度TOPIC
- #define MQTT_PUB_HUM_TOPIC "/door/device/humidity" //设备发布湿度TOPIC
- static OS_Thread_t g_mqtt_thread;
- static OS_Thread_t g_main_thread;
- static SHT30_DATA sht30_data;
- static void iot_task(void *arg)
- {
- int ret;
- int reconnect_times = 0;
- unsigned char payload[64] = "";
-
- //温湿度传感器初始化
- IotI2C_Init();
-
- //MQTT初始化
- IoTMqtt_init();
- ret = IoTMqtt_connect(MQTT_DEMO_HOST_NAME, MQTT_DEMO_PORT);
- if (ret != 0)
- {
- goto exit;
- }
-
- //发布设备注册主题
- IoTMqtt_publish(MQTT_PUB_REG_TOPIC, IOT_DEVICEID);
- while (1)
- {
- IoTMqtt_publish(MQTT_PUB_HEART_TOPIC, IOT_DEVICEID);
-
- IotI2C_ReadData(&sht30_data);
- memset(payload, 0x0, sizeof(payload));
- snprintf(payload, sizeof(payload), "%s/%.2f/%d", IOT_DEVICEID,
- sht30_data.temperature, 0);
- IoTMqtt_publish(MQTT_PUB_TEM_TOPIC, payload);
- memset(payload, 0x0, sizeof(payload));
- snprintf(payload, sizeof(payload), "%s/%.2f/%d", IOT_DEVICEID,
- sht30_data.humidity, 0);
- IoTMqtt_publish(MQTT_PUB_HUM_TOPIC, payload);
-
- OS_MSleep(2000); //2s
- }
- exit:
- IoTMqtt_unsubscribe(MQTT_PUB_TEM_TOPIC);
- IoTMqtt_unsubscribe(MQTT_PUB_HUM_TOPIC);
- IoTMqtt_disconnect();
- IoTMqtt_deinit();
- IoTI2c_Deinit();
- OS_ThreadDelete(&g_mqtt_thread);
- }
- static void net_cb(uint32_t event, uint32_t data, void *arg)
- {
- uint16_t type = EVENT_SUBTYPE(event);
- switch (type)
- {
- case NET_CTRL_MSG_NETWORK_UP:
- printf("NET_CTRL_MSG_NETWORK_UPn");
- if (!OS_ThreadIsValid(&g_mqtt_thread))
- {
- OS_ThreadCreate(&g_mqtt_thread, "iot_task",
- iot_task, (void *)NULL, OS_THREAD_PRIO_APP, (8 * 1024));
- }
- break;
- case NET_CTRL_MSG_NETWORK_DOWN:
- break;
- default:
- break;
- }
- }
- static int MainThread(void *arg)
- {
- int s32Ret = 0;
-
- //使能、扫描、连接热点
- if (WIFI_SUCCESS != EnableWifi())
- {
- printf("Error: EnableWifi failn");
- return;
- }
- OS_Sleep(1);
- if (WIFI_SUCCESS != Scan()) {
- printf("Error: Scan fail.n");
- return;
- }
- OS_Sleep(3);//这里为了方便用延时,实际用回调更好,否则3秒可能不够
- const char ssid_want_connect[] = WIFI_DEVICE_CONNECT_AP_SSID;
- const char psk[] = WIFI_DEVICE_CONNECT_AP_PSK;
- WifiScanInfo scan_results[30];
- unsigned int scan_num = 30;
- if (WIFI_SUCCESS != GetScanInfoList(scan_results, &scan_num))
- {
- printf("Error: GetScanInfoList fail.n");
- return;
- }
- WifiDeviceConfig config = { 0 };
- int netId = 0;
- int i;
- for (i = 0; i < scan_num; i++)
- {
- printf("ssid: %s ", scan_results[i].ssid);
- printf("securityType: %dn", scan_results[i].securityType);
- if (0 == strcmp(scan_results[i].ssid, ssid_want_connect))
- {
- memcpy(config.ssid, scan_results[i].ssid,
- WIFI_MAX_SSID_LEN);
- memcpy(config.bssid, scan_results[i].bssid,
- WIFI_MAC_LEN);
- strcpy(config.preSharedKey, psk);
- config.securityType = scan_results[i].securityType;
- config.wapiPskType = WIFI_PSK_TYPE_ASCII;
- config.freq = scan_results[i].frequency;
- break;
- }
- }
- if (i >= scan_num)
- {
- printf("Error: No found ssid in scan_resultsn");
- return -1;
- }
- if (WIFI_SUCCESS != AddDeviceConfig(&config, &netId))
- {
- printf("Error: AddDeviceConfig Failn");
- return -1;
- }
- printf("Config Successn");
- if (WIFI_SUCCESS != ConnectTo(netId))
- {
- printf("Error: ConnectTo Failn");
- return -1;
- }
-
- observer_base *net_ob;
- net_ob = sys_callback_observer_create(CTRL_MSG_TYPE_NETWORK, NET_CTRL_MSG_ALL, net_cb, NULL);
- if (net_ob == NULL)
- {
- return -1;
- }
- if (sys_ctrl_attach(net_ob) != 0)
- {
- return -1;
- }
- while(1)
- {
- OS_MSleep(2000);
- }
- return 0;
- }
- void SmartRoomMain(void)
- {
- printf("rSmartRoomMain Startrn");
- if (OS_ThreadCreate(&g_main_thread, "MainThread", MainThread, NULL,
- OS_THREAD_PRIO_APP, 4 * 1024) != OS_OK) {
- printf("[ERR] Create MainThread Failedn");
- }
- }
- SYS_RUN(SmartRoomMain);
完整代码上传到:
链接:
https://pan.baidu.com/s/11Iy-...
提取码:80qj
3.编译及烧录
编译:
- hb build -f
- [OHOS INFO] [238/256] AR libs/libxr_wifi_adapter.a
- [OHOS INFO] [239/256] STAMP obj/device/xradio/xr806/adapter/hals/adapter.stamp
- [OHOS INFO] [240/256] gcc cross compiler obj/kernel/liteos_m/kal/cmsis/libcmsis.cmsis_liteos.o
- [OHOS INFO] [241/256] AR libs/libcmsis.a
- [OHOS INFO] [242/256] AR libs/libkal.a
- [OHOS INFO] [243/256] gcc cross compiler obj/third_party/bounds_checking_function/src/libsec.secureinput_w.o
- [OHOS INFO] [244/256] gcc cross compiler obj/kernel/liteos_m/kernel/src/mm/libkernel.los_memory.o
- [OHOS INFO] [245/256] gcc cross compiler obj/third_party/bounds_checking_function/src/libsec.secureinput_a.o
- [OHOS INFO] [246/256] AR libs/libsec.a
- [OHOS INFO] [247/256] AR libs/libwifiservice.a
- [OHOS INFO] [248/256] STAMP obj/foundation/communication/wifi_lite/wifi.stamp
- [OHOS INFO] [249/256] gcc cross compiler obj/kernel/liteos_m/kernel/src/libkernel.los_task.o
- [OHOS INFO] [250/256] AR libs/libkernel.a
- [OHOS INFO] [251/256] STAMP obj/kernel/liteos_m/kernel.stamp
- [OHOS INFO] [252/256] STAMP obj/build/lite/ohos.stamp
- [OHOS INFO] [253/256] ACTION //build/lite:gen_rootfs(//build/lite/toolchain:arm-none-eabi-gcc)
- [OHOS INFO] [254/256] STAMP obj/build/lite/gen_rootfs.stamp
- [OHOS INFO] [255/256] ACTION //device/xradio/xr806:libSDK(//build/lite/toolchain:arm-none-eabi-gcc)
- [OHOS INFO] [256/256] STAMP obj/device/xradio/xr806/libSDK.stamp
- [OHOS INFO] /sdg/xiaoyuan.cai/project/xr806/vendor/xradio/xr806/fs.yml not found, stop packing fs. If the product does not need to be packaged, ignore it.
- [OHOS INFO] wifi_skylark build success
- [OHOS INFO] cost time: 0:00:11
- [OpenHarmony][xr806]#
代码编译成功,参照官方烧录文档,使用PhoenixMC工具烧录到XR806开发板上:
4.服务端搭设及鸿蒙APP开发
MQTT服务端搭设省略,可自行百度;服务端由于需要同时MQTT对接XR806设备端以及WebSocket对接鸿蒙APP端,所以需要实现业务逻辑,在此是通过java编写打包成jar运行于服务器上,主要是实现了对接XR806 MQTT发起的设备注册以及心跳,同时通知给APP,此实现还涉及到mqsql数据库的应用,在此不赘述。
因为XR806是运行的鸿蒙L0系统,为了统一到鸿蒙的旗帜下,此次手机应用也采用了基于鸿蒙手机开发APP,重点是实现了对设备端采集到的温湿度实时展示,其他功能后续继续完善。
服务端运行LOG监视(接收XR806的心跳及上报的温湿度信息):
- 2022-01-11 16:41:14.692 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 接收到信息topic:/device/heartbeat msg:666666,开始处理
- 2022-01-11 16:41:14.692 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : ------刷新心跳------
- 2022-01-11 16:41:14.696 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 接收到信息topic:/door/device/temperature msg:666666/23.33/0,开始处理
- 2022-01-11 16:41:14.696 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : ------温度信息处理------
- 2022-01-11 16:41:14.696 DEBUG 1 --- [C41A5031E110123] c.u.d.m.N.findNewDeviceBySerialId : ==> Preparing: select * from um_new_device where serial_id=?
- 2022-01-11 16:41:14.697 DEBUG 1 --- [C41A5031E110123] c.u.d.m.N.findNewDeviceBySerialId : ==> Parameters: 666666(String)
- 2022-01-11 16:41:14.697 DEBUG 1 --- [C41A5031E110123] c.u.d.m.N.findNewDeviceBySerialId : <== Total: 1
- 2022-01-11 16:41:14.697 DEBUG 1 --- [C41A5031E110123] d.m.N.UpdateTemperatureAndWarnBySerialId : ==> Preparing: update um_new_device set temperature = ?, temperature_warn = ? where serial_id = ?
- 2022-01-11 16:41:14.698 DEBUG 1 --- [C41A5031E110123] d.m.N.UpdateTemperatureAndWarnBySerialId : ==> Parameters: 23.33(String), 0(Integer), 666666(String)
- 2022-01-11 16:41:14.725 DEBUG 1 --- [C41A5031E110123] d.m.N.UpdateTemperatureAndWarnBySerialId : <== Updates: 1
- 2022-01-11 16:41:14.725 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 更新温度信息成功!
- 2022-01-11 16:41:14.725 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : ------------666666--------
- 2022-01-11 16:41:14.725 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 发送消息+channelId:0242acfffe150002-00000001-0000004a-140074f3a73178fa-1e4d0f61param:{"temperatureWarn":0,"temperature":"23.33","state":1,"type":"smart_computer_room","deviceId":"666666"}
- 2022-01-11 16:41:14.725 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 接收到信息topic:/door/device/humidity msg:666666/48.00/0,开始处理
- 2022-01-11 16:41:14.725 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : ------湿度信息处理------
- 2022-01-11 16:41:14.725 DEBUG 1 --- [C41A5031E110123] c.u.d.m.N.findNewDeviceBySerialId : ==> Preparing: select * from um_new_device where serial_id=?
- 2022-01-11 16:41:14.725 DEBUG 1 --- [C41A5031E110123] c.u.d.m.N.findNewDeviceBySerialId : ==> Parameters: 666666(String)
- 2022-01-11 16:41:14.726 DEBUG 1 --- [C41A5031E110123] c.u.d.m.N.findNewDeviceBySerialId : <== Total: 1
- 2022-01-11 16:41:14.726 DEBUG 1 --- [C41A5031E110123] .u.d.m.N.UpdateHumidityAndWarnBySerialId : ==> Preparing: update um_new_device set humidity = ?, humidity_warn = ? where serial_id = ?
- 2022-01-11 16:41:14.726 DEBUG 1 --- [C41A5031E110123] .u.d.m.N.UpdateHumidityAndWarnBySerialId : ==> Parameters: 48.00(String), 0(Integer), 666666(String)
- 2022-01-11 16:41:14.750 DEBUG 1 --- [C41A5031E110123] .u.d.m.N.UpdateHumidityAndWarnBySerialId : <== Updates: 1
- 2022-01-11 16:41:14.750 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 更新湿度信息成功!
- 2022-01-11 16:41:14.750 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : ------------666666--------
- [0242acfffe150002-00000001-0000004a-140074f3a73178fa-1e4d0f61]
- 2022-01-11 16:41:14.750 INFO 1 --- [C41A5031E110123] c.u.smartroom.common.util.LogUtils : 发送消息+channelId:0242acfffe150002-00000001-0000004a-140074f3a73178fa-1e4d0f61param:{"humidityWarn":0,"humidity":"48.00","state":1,"type":"smart_computer_room","deviceId":"666666"}
最终华为Mate40E运行效果:
PS:由于鸿蒙APP开发经验不足,过程还是遇到不少问题,由于文章篇幅原因,这里不详细讲解服务端及APP代码,需要服务器JAVA及鸿蒙APP源码的可以私信。
四、参考资料
https://aijishu.com/a/1060000...(基于安谋科技STAR-MC1处理器的「全志科技XR806开发板」简介)
https://aijishu.com/a/1060000...(全志XR806开发板硬件bomlist,开发板及底板设计原理图下载)
https://aijishu.com/a/1060000...(全志XR806开发板软件系统简介)
https://aijishu.com/a/1060000...(【开发板试用报告】学习MQTT开发)
文章转自极术社区