当前位置:网站首页>Design intelligent weighing system based on Huawei cloud IOT (STM32)

Design intelligent weighing system based on Huawei cloud IOT (STM32)

2022-07-07 11:18:00 InfoQ

1. Preface

With network technology , Various communication technologies , The rapid development of sensor technology , Internet of things technology has become a rapidly developing technology in today's technical field . The core of Internet of things technology is still based on Internet technology , The Internet of things is an important part of the new generation of information technology , It is also an important development stage in the information age . Internet of things through intelligent perception 、 Recognition technology, pervasive computing and other communication sensing technology , It is widely used in the integration of network , It's also known as the next computer 、 After the Internet, the third wave of world information industry development .

The model of this design comes from logistics 、 mine 、 Highway and other occasions , Intelligent upgrade requirements of vehicle weighing ground crab , Design an intelligent online weighing scheme based on the Internet of things , Develop intelligent weighing controller , Reasonably select and deploy multiple weight sensors and necessary algorithms 、 adopt WIFF Communication module 、GPS Positioning module , Collect vehicle weight data - geographic location information , And send it to the cloud platform through the network , Graphic design UI The interface shows weighing 、 Important information such as map location , Realize the remote monitoring of symmetrical weight system .

With the gradual development and maturity of Internet of things Technology , Internet of things technology is a large and wide application technology , Not limited to extended applications . It is believed that there will be more innovative application practices for the weighbridge . in general , Weighbridge modernization 、 Promotion of information technology 、 Intellectualization must follow the development of Internet of things technology , The development of Internet of things technology will also promote the rise of a new technological revolution .

Summary of design technology and hardware options :

(1) The cloud communication module adopts ESP8266-WIFI

(2) The networking communication module adopts :ESP8266

(3)GPS modular : use ATGM336H Bimodal GPS modular

(4) Scale module : For weighing

(5) Internet of things cloud platform : Adopt Huawei cloud Internet of things platform

Design summary :

(1) use ESP8266 Connect Huawei cloud to upload weighing data and GPS Data to the cloud ( use MQTT agreement )

The cloud shows 2 Data :GPS Location data -- The map shows , The data value of the load cell

(2)3 One load cell is connected to one scale surface to weigh and calculate the average value

(3) Local OLED The display shows GPS Latitude and longitude data 、 The data value of the load cell .

(4)OLED Design a page to display and set the current alarm upper limit . Add and subtract by pressing the key

When the weighing threshold exceeds the set threshold , Buzzer alarm .

null
null
null
null

2.  Hardware selection

2.1 STM32F103C8T6

STM32F103C8T6 It's based on ARM Cortex-M  kernel STM32 Series of 32 Bit of microcontroller , The capacity of program memory is 64KB, Voltage required 2V~3.6V, Operating temperature: -40°C ~ 85°C.

null

2.2  Scale sensor

null
HX711  It is specially designed for high-precision load cell 24 position A/D  Converter chip .

2.3 ESP8266-wifi

null

2.4 GPS modular

null

2.5  Buzzer

null

3.  Create cloud products and devices

3.1  Create products

Address :https://www.huaweicloud.com/?locale=zh-cn

null
null
null
null

3.2  Create device

Address : https://console.huaweicloud.com/iotdm/?region=cn-north-4#/dm-portal/device/all-device

null
null

3.3  Custom model data

link :https://console.huaweicloud.com/iotdm/?region=cn-north-4#/dm-dev/all-product/7211833377cf435c8c0580de390eedbe/product-detail/6277d70223aaf461a0f72a56 The model data is the data to be uploaded by the device .

null
null
null
null
null
{
 "device_id": "6277d70223aaf461a0f72a56_weigh",
 "secret": "12345678"
}

service ID: weigh
The attribute name   data type   access   describe  
weigh int( integer )  Can be read   weight  
GPS string( character string )  Can be read  GPS Location information  

3.4 MQTT Key generation

After creating the product 、 After the device , Then you need to know how to pass MQTT Log in to the Huawei ECS according to the protocol . The official details are here :https://support.huaweicloud.com/devg-iothub/iot_01_2127.html#ZH-CN_TOPIC_0240834853__zh-cn_topic_0251997880_li365284516112

Attribute reporting format :https://support.huaweicloud.com/api-iothub/iot_06_v5_3010.html

null
null
MQTT Device login key generation address : https://iot-tool.obs-website.cn-north-4.myhuaweicloud.com/

null
null
DeviceId 6277d70223aaf461a0f72a56_weigh
DeviceSecret 12345678
ClientId 6277d70223aaf461a0f72a56_weigh_0_0_2022050814
Username 6277d70223aaf461a0f72a56_weigh
Password 0a3d097c6449b8526a562006a74c8c5e61ce63d6c831ea291560736a3332cf77

The domain name of Huawei cloud Internet of things platform is : 
161a58a78.iot-mqtts.cn-north-4.myhuaweicloud.com
Of Huawei's cloud Internet of things platform IP The address is :
121.36.42.100
After the parameters are filled correctly in the software , You can see that the device has been successfully connected . Next, open the device page , You can see that the device is online .

null
null

3.5  Topic subscription and Publishing

// Subscribe to topics :  The platform sends a message to the device
$oc/devices/6277d70223aaf461a0f72a56_weigh/sys/messages/down
// Equipment report data
$oc/devices/6277d70223aaf461a0f72a56_weigh/sys/properties/report
// Reported attribute message  ( Multiple attributes can be reported at a time , stay json Just add it to the )
{"services": [{"service_id": "weigh","properties":{"GPS":"lat:12.345,lng:45.678"}}]}

adopt MQTT Client software simulation report test :

null
View the console page , The data has been uploaded successfully .

null

3.6  Application side development

In order to display equipment data more conveniently , Interact with the device , We also need to develop a supporting host computer , The official provides the application side development API Interface 、SDK Interface , For convenience and versatility , I'm using API Interface to complete data interaction , The upper computer software adopts QT Development .

Help document address : https://support.huaweicloud.com/api-iothub/iot_06_v5_0034.html

The device attribute is the sensor status data information uploaded by the device , The application side provides API Interface , It can actively send request instructions to the device end ; After receiving the instruction, the device needs to report the data according to the agreed data format ; therefore , To realize the data interaction between the application layer and the device side , It needs the cooperation between the application layer and the device end to complete .

null
null
When using interfaces , It's best to use Huawei's own debugging interface to test .https://apiexplorer.developer.huaweicloud.com/apiexplorer/doc?product=IoTDA&api=ListProperties

null
The upper computer software adopts Qt framework design ,Qt It's a cross platform C++ GUI application framework .Qt It's a 1991 Year by year Qt Company Cross platform development C++ GUI application development framework . It can develop GUI Program , It can also be used to develop non GUI Program , For example, console tools and servers . Simply speaking ,QT It can easily help you make software with interface , It doesn't even require you to put a lot of energy .

QT Official website :
 https://www.qt.io/

null

4. STM32 Device side development

4.1  Program download

null

4.2  Schematic diagram

null

4.3  Hardware wiring

(1)OLED Display wiring :
D0----(SCK)------------------->>PB14
D1----(MOSI)------------------>>PB13
RES—( Low level of reset pin is effective )-------->>PB12
DC--( Data and command control pins )------>>PB1
CS--( Chip selection pin )---------------->>PA7
GND--------------------------->>GND
VCC--------------------------->>3.3V perhaps 5V

(2)ATK-ESP8266 WIFI connection
PA2(TX)--RXD  Module receiving pin
PA3(RX)--TXD  Module sending pin
GND---GND  The earth
VCC---VCC  Power Supply (3.3V~5.0V)

(3) External buzzer module :  High level response
BEEP----->PB8

(4) External keys :
KEY1 -PB3  Pressing is low   Zero clearing
KEY2 -PB2  Pressing is low   Page turning
KEY3 -PB6  Pressing is low   Add
KEY4 -PB7  Pressing is low   reduce

(5) external LED Light module :
LED1-PB4  Low level light
LED2-PB5  Low level light

(6) The weighing sensor 1
VCC--->5V
SCK--->PA4  Timing control pin -- Yes STM32-- The output mode
DT---->PA5  Output pin - Yes STM32-- The input mode
GND--->GND

(7) The weighing sensor 2
VCC--->5V
SCK--->PA11  Timing control pin -- Yes STM32-- The output mode
DT---->PA12  Output pin - Yes STM32-- The input mode
GND--->GND

(8) The weighing sensor 3
VCC--->5V
SCK--->PA6  Timing control pin -- Yes STM32-- The output mode
DT---->PA8  Output pin - Yes STM32-- The input mode
GND--->GND

(9)GPS Module wiring instructions
GND----GND
VCC---3.3V
PB11----GPS_TX
PB10----GPS_RX

(--) On board LED The lamp : Low level light
LED1--PC13 
BEEP2--PC14

(--) Onboard keys : 
KEY1--PA0  Press to high level

4.4 MQTT Connection code

MQTT The protocol connects Huawei cloud IOT Source project : https://download.csdn.net/download/xiaolong1126626497/81993720

#include "stm32f10x.h"
#include "led.h"
#include "delay.h"
#include "key.h"
#include "usart.h"
#include <string.h>
#include &quot;timer.h&quot;
#include &quot;bluetooth.h&quot;
#include &quot;esp8266.h&quot;
#include &quot;mqtt.h&quot;

// Equipment information of Huawei Internet of things server
#define MQTT_ClientID &quot;61b9ba3a2b2aa20288c1e7f1_QQ1126626497_0_0_2021121510&quot;
#define MQTT_UserName &quot;61b9ba3a2b2aa20288c1e7f1_QQ1126626497&quot;
#define MQTT_PassWord &quot;385ce91dfe7da5b7431868d5d87e7998163c493344040935d5a00024d6324242&quot;

// Topics subscribed and published
#define SET_TOPIC &quot;$oc/devices/61b9ba3a2b2aa20288c1e7f1_QQ1126626497_0_0_2021121510/sys/messages/down&quot; // subscribe
#define POST_TOPIC &quot;$oc/devices/61b9ba3a2b2aa20288c1e7f1_QQ1126626497_0_0_2021121510/sys/properties/report&quot; // Release

char mqtt_message[200];// Report data buffer

int main()
{
 u32 time_cnt=0;
 u32 i;
 u8 key;
 LED_Init();
 BEEP_Init();
 KEY_Init();
 USART1_Init(115200);
 TIMER1_Init(72,20000); // Timeout time 20ms
 USART2_Init(9600);// A serial port - bluetooth
 TIMER2_Init(72,20000); // Timeout time 20ms
 USART3_Init(115200);// A serial port -WIFI
 TIMER3_Init(72,20000); // Timeout time 20ms
 USART1_Printf(&quot; Initializing WIFI One moment please .\n&quot;);
 if(ESP8266_Init())
 {
 USART1_Printf(&quot;ESP8266 Hardware detection error .\n&quot;); 
 }
 else
 {
 // Unencrypted port
 USART1_Printf(&quot;WIFI:%d\n&quot;,ESP8266_STA_TCP_Client_Mode(&quot;CMCC-Cqvn&quot;,&quot;99pu58cb&quot;,&quot;121.36.42.100&quot;,1883,1));
 
 }
 
 //2. MQTT Protocol initialization  
 MQTT_Init(); 
 //3.  Connect to Huawei server  
 while(MQTT_Connect(MQTT_ClientID,MQTT_UserName,MQTT_PassWord))
 {
 USART1_Printf(&quot; Server connection failed , Retrying ...\n&quot;);
 delay_ms(500);
 }
 USART1_Printf(&quot; Server connection successful .\n&quot;);
 
 //3.  Subscribe to topics
 if(MQTT_SubscribeTopic(SET_TOPIC,0,1))
 {
 USART1_Printf(&quot; Topic subscription failed .\n&quot;);
 }
 else
 {
 USART1_Printf(&quot; Topic subscription succeeded .\n&quot;);
 } 
 
 .........

4.5 ESP8266 Code

#include &quot;esp8266.h&quot;
u8 ESP8266_IP_ADDR[16]; //255.255.255.255
u8 ESP8266_MAC_ADDR[18]; // Hardware address
/*
The functionality : ESP8266 Command sending function
Function return value :0 It means success  1 It means failure
*/
u8 ESP8266_SendCmd(char *cmd)
{
 u8 i,j;
 for(i=0;i<10;i++) // Number of tests -- Number of times the command was sent
 {
 USARTx_StringSend(USART3,cmd);
 for(j=0;j<100;j++) // Waiting time
 {
 delay_ms(50);
 if(USART3_RX_FLAG)
 {
 USART3_RX_BUFFER[USART3_RX_CNT]='\0';
 USART3_RX_FLAG=0;
 USART3_RX_CNT=0;
 if(strstr((char*)USART3_RX_BUFFER,&quot;OK&quot;))
 {
 return 0;
 }
 }
 }
 }
 return 1;
}

/*
The functionality : ESP8266 Hardware initialization detection function
Function return value :0 It means success  1 It means failure
*/
u8 ESP8266_Init(void)
{
 // Exit through mode
 USARTx_StringSend(USART3,&quot;+++&quot;);
 delay_ms(50);
 return ESP8266_SendCmd(&quot;AT\r\n&quot;);
}

/*
The functionality :  One click configuration WIFI by AP+TCP Server mode
Function parameter :
char *ssid  Created hotspot name
char *pass  Create a new hotspot password  ( least 8 position )
u16 port  Created server port number
Function return value : 0 It means success   Other values represent the corresponding error value
*/
u8 ESP8266_AP_TCP_Server_Mode(char *ssid,char *pass,u16 port)
{
 char *p;
 u8 i;
 char ESP8266_SendCMD[100]; // Combine commands in the sending process
 /*1.  Test the hardware */
 if(ESP8266_SendCmd(&quot;AT\r\n&quot;))return 1;
 /*2.  Close back display */
 if(ESP8266_SendCmd(&quot;ATE0\r\n&quot;))return 2;
 /*3.  Set up WIFI Pattern */
 if(ESP8266_SendCmd(&quot;AT+CWMODE=2\r\n&quot;))return 3;
 /*4.  Reset */
 ESP8266_SendCmd(&quot;AT+RST\r\n&quot;);
 delay_ms(1000);
 delay_ms(1000);
 delay_ms(1000);
 /*5.  Close back display */
 if(ESP8266_SendCmd(&quot;ATE0\r\n&quot;))return 5;
 /*6.  Set up WIFI Of AP Mode parameters */
 sprintf(ESP8266_SendCMD,&quot;AT+CWSAP=\&quot;%s\&quot;,\&quot;%s\&quot;,1,4\r\n&quot;,ssid,pass);
 if(ESP8266_SendCmd(ESP8266_SendCMD))return 6;
 /*7.  Open multiple connections */
 if(ESP8266_SendCmd(&quot;AT+CIPMUX=1\r\n&quot;))return 7;
 /*8.  Set the server port number */
 sprintf(ESP8266_SendCMD,&quot;AT+CIPSERVER=1,%d\r\n&quot;,port);
 if(ESP8266_SendCmd(ESP8266_SendCMD))return 8;
 /*9.  Query local IP Address */
 if(ESP8266_SendCmd(&quot;AT+CIFSR\r\n&quot;))return 9;
 // extract IP Address
 p=strstr((char*)USART3_RX_BUFFER,&quot;APIP&quot;);
 if(p)
 {
 p+=6;
 for(i=0;*p!='&quot;';i++)
 {
 ESP8266_IP_ADDR[i]=*p++;
 }
 ESP8266_IP_ADDR[i]='\0';
 }
 // extract MAC Address
 p=strstr((char*)USART3_RX_BUFFER,&quot;APMAC&quot;);
 if(p)
 {
 p+=7;
 for(i=0;*p!='&quot;';i++)
 {
 ESP8266_MAC_ADDR[i]=*p++;
 }
 ESP8266_MAC_ADDR[i]='\0';
 }
 
 // Print general information
 USART1_Printf(&quot; At present WIFI Pattern :AP+TCP The server \n&quot;);
 USART1_Printf(&quot; At present WIFI Hot spot name :%s\n&quot;,ssid);
 USART1_Printf(&quot; At present WIFI Hot code :%s\n&quot;,pass);
 USART1_Printf(&quot; At present TCP Server port number :%d\n&quot;,port);
 USART1_Printf(&quot; At present TCP The server IP Address :%s\n&quot;,ESP8266_IP_ADDR);
 USART1_Printf(&quot; At present TCP The server MAC Address :%s\n&quot;,ESP8266_MAC_ADDR);
 return 0;
}

/*
The functionality : TCP Sending function in server mode
Send instructions : 
*/
u8 ESP8266_ServerSendData(u8 id,u8 *data,u16 len)
{
 u8 i,j,n;
 char ESP8266_SendCMD[100]; // Combine commands in the sending process
 for(i=0;i<10;i++)
 {
 sprintf(ESP8266_SendCMD,&quot;AT+CIPSEND=%d,%d\r\n&quot;,id,len);
 USARTx_StringSend(USART3,ESP8266_SendCMD);
 for(j=0;j<10;j++)
 {
 delay_ms(50);
 if(USART3_RX_FLAG)
 {
 USART3_RX_BUFFER[USART3_RX_CNT]='\0';
 USART3_RX_FLAG=0;
 USART3_RX_CNT=0;
 if(strstr((char*)USART3_RX_BUFFER,&quot;>&quot;))
 {
 // Continue sending data
 USARTx_DataSend(USART3,data,len);
 // Wait for the data to be sent successfully
 for(n=0;n<200;n++)
 {
 delay_ms(50);
 if(USART3_RX_FLAG)
 {
 USART3_RX_BUFFER[USART3_RX_CNT]='\0';
 USART3_RX_FLAG=0;
 USART3_RX_CNT=0;
 if(strstr((char*)USART3_RX_BUFFER,&quot;SEND OK&quot;))
 {
 return 0;
 }
 } 
 } 
 }
 }
 }
 }
 return 1;
}

/*
The functionality :  To configure WIFI by STA Pattern +TCP Client mode
Function parameter :
char *ssid  Created hotspot name
char *pass  Create a new hotspot password  ( least 8 position )
char *p  The server to which you will connect IP Address
u16 port  The port number of the server to be connected
u8 flag 1 Indicates that transparent transmission mode is enabled  0 Indicates that the transparent transmission mode is turned off
Function return value :0 It means success   Other values indicate the corresponding error
*/
u8 ESP8266_STA_TCP_Client_Mode(char *ssid,char *pass,char *ip,u16 port,u8 flag)
{
 char ESP8266_SendCMD[100]; // Combine commands in the sending process
 // Exit through mode
 //USARTx_StringSend(USART3,&quot;+++&quot;);
 //delay_ms(50);
 /*1.  Test the hardware */
 if(ESP8266_SendCmd(&quot;AT\r\n&quot;))return 1;
 /*2.  Close back display */
 if(ESP8266_SendCmd(&quot;ATE0\r\n&quot;))return 2;
 /*3.  Set up WIFI Pattern */
 if(ESP8266_SendCmd(&quot;AT+CWMODE=1\r\n&quot;))return 3;
 /*4.  Reset */
 ESP8266_SendCmd(&quot;AT+RST\r\n&quot;);
 delay_ms(1000);
 delay_ms(1000);
 delay_ms(1000);
 /*5.  Close back display */
 if(ESP8266_SendCmd(&quot;ATE0\r\n&quot;))return 5;
 /*6.  Configure the to be connected WIFI hot spot information */
 sprintf(ESP8266_SendCMD,&quot;AT+CWJAP=\&quot;%s\&quot;,\&quot;%s\&quot;\r\n&quot;,ssid,pass);
 if(ESP8266_SendCmd(ESP8266_SendCMD))return 6;
 /*7.  Set up a single connection */
 if(ESP8266_SendCmd(&quot;AT+CIPMUX=0\r\n&quot;))return 7;
 /*8.  Configure the to connect TCP server information */
 sprintf(ESP8266_SendCMD,&quot;AT+CIPSTART=\&quot;TCP\&quot;,\&quot;%s\&quot;,%d\r\n&quot;,ip,port);
 if(ESP8266_SendCmd(ESP8266_SendCMD))return 8;
 /*9.  Turn on transmission mode */
 if(flag)
 {
 if(ESP8266_SendCmd(&quot;AT+CIPMODE=1\r\n&quot;))return 9; // Turn on
 if(ESP8266_SendCmd(&quot;AT+CIPSEND\r\n&quot;))return 10; // Start penetrating
 if(!(strstr((char*)USART3_RX_BUFFER,&quot;>&quot;)))
 {
 return 11;
 }
 // If you want to quit sending : &quot;+++&quot;
 }
 
 // Print general information
 USART1_Printf(&quot; At present WIFI Pattern :STA+TCP client \n&quot;);
 USART1_Printf(&quot; Currently connected WIFI Hot spot name :%s\n&quot;,ssid);
 USART1_Printf(&quot; Currently connected WIFI Hot code :%s\n&quot;,pass);
 USART1_Printf(&quot; Currently connected TCP Server port number :%d\n&quot;,port);
 USART1_Printf(&quot; Currently connected TCP The server IP Address :%s\n&quot;,ip);
 return 0;
}


/*
The functionality : TCP Sending function in client mode
Send instructions : 
*/
u8 ESP8266_ClientSendData(u8 *data,u16 len)
{
 u8 i,j,n;
 char ESP8266_SendCMD[100]; // Combine commands in the sending process
 for(i=0;i<10;i++)
 {
 sprintf(ESP8266_SendCMD,&quot;AT+CIPSEND=%d\r\n&quot;,len);
 USARTx_StringSend(USART3,ESP8266_SendCMD);
 for(j=0;j<10;j++)
 {
 delay_ms(50);
 if(USART3_RX_FLAG)
 {
 USART3_RX_BUFFER[USART3_RX_CNT]='\0';
 USART3_RX_FLAG=0;
 USART3_RX_CNT=0;
 if(strstr((char*)USART3_RX_BUFFER,&quot;>&quot;))
 {
 // Continue sending data
 USARTx_DataSend(USART3,data,len);
 // Wait for the data to be sent successfully
 for(n=0;n<200;n++)
 {
 delay_ms(50);
 if(USART3_RX_FLAG)
 {
 USART3_RX_BUFFER[USART3_RX_CNT]='\0';
 USART3_RX_FLAG=0;
 USART3_RX_CNT=0;
 if(strstr((char*)USART3_RX_BUFFER,&quot;SEND OK&quot;))
 {
 return 0;
 }
 } 
 } 
 }
 }
 }
 }
 return 1;
}

原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070909198456.html