(Open source) STC89c51 SP8266-based production environment real-time detection system + APP inventor to make real-time display mobile phone App

@

First, the effects of the first FIG.

In the fourth step c51 program, app program in the sixth step

Here Insert Picture Description

Second, to explain the principle

It outlines the rationale : the use of publish and subscribe model. A first step, STC89c51 acquire various sensor values, a second step, the new theme, then the theme c51 send messages to the third step. app inventor Subscribe to this topic, because the app inventor made app subscribe to the theme, you can receive messages from the subject, that is, you can receive various sensor values.

About publishing Subscribe:

Subscribe (Subscribe): subscribe to a given topic.
Release (release) to send the message to the specified topic.

Subscribers only device that topic before they can receive messages sent to that topic.

Popular terms: subscribe to the blog scene is like, what does it mean, that 100 people subscribed to your blog, if the blogger published an article, then 100 people will receive e-mail notification at the same time, publish / subscribe model is such a principle.

If you do not understand the words again popular to talk about, like life and listen to radio, to listen to the radio, FM it certainly is, only in the right channel above, we only hear nice program, so that we must first subscribe to a subscription channel / theme, only subscribed to the topic, we can receive a message sent to the channel / topic.

In this routine, c51 aid of ESP8266 push message, app subscription theme, c51 can receive messages sent by the real-time.

Third, c51 reads various sensor values

Because everyone's sensor is not the same, there is not a unified doing routines, direct use of virtual value in the program, you know like.

	char data1[] = "32";             ////为了演示定义的模拟数据,可根据自己传感器自行采集数据
	char data2[] = "27.8";		//
	char data3[] = "45"; 
	char data4[] = "26"; 
	char data5[] = "99.12"; 
	char data6[] = "ON"; 

Here only defines six values, according to their own needs, of course, free to increase or decrease the number of sensor values, data types may be freely modified self.

Fourth, the sensor data is pushed to the cloud

c51 sample program Download: Download

Program Description, 9600, 11.0592 crystal
due ESP8266-01 default baud rate is 115200, you need to manually adjust the baud rate esp8266-01.
Adjustment method: ESP8266-01 connected to usb to ttl

Five lines
esp8266 --------- UsbTTL
TX ---------- RX
RX TX ----------
VCC ------- 3.3V
GND- gnd -------
EN ---------- 3.3V

Open the serial debugging assistant, set the baud rate 115200, and find esp8266 com port open, sending

AT+UART=9600,8,1,0,0

Should be added to the end of the carriage return line, serial port will respond ok
if you do not reply ok, may modify the firmware does not support baud rates, you need to brush the official firmware AT, showing me another article brush the official firmware

Here Insert Picture Description

Serial debugging assistant download tool: https://www.lanzous.com/iax97ih Password: 1234

If the previous step sensor data can be read successfully, it can be the basis of the version on the data uploaded to the cloud.

Open the program by keil, WIFI and other information needs to be modified

#define Ssid  "newhtc"	//WIFI名称,,修改为自己路由器的WIFI名称,好像不支持中文
#define PassWord  "qq123456"     //WIFI密码,修改为自己路由器的
#define Uid  "4d9ec352e0376f2110a0c601a2857225" //巴法云UID密钥,控制台获取
#define Topic  "mytemp"   //巴法云控制台创建,名称自定义,app订阅主题要和这个推送主题一致

In the Palestinian law maker culture cloud console to create a new theme, theme name at random, for example mytemp, in this instance with the use mytemp, should be used to modify the sample code for your own theme name, letters, or a combination of numbers or letters plus numbers. UID is the user's private key, the Pakistani law maker culture cloud console available after registration landing.
After you log in, you can see his private key UID in the console, as shown:

Here Insert Picture Description

Create a theme in the console, you can create a theme.

  • Relating to the first input, a combination of letters or numbers or letters + numbers.
  • Click to create a theme.

Here Insert Picture Description

WIFI WIFI router name for their name, case sensitive, can lead to wrong connection is not on the network.

void POST(void)//POST数据函数
{
	int dataLen;
	uchar postData[150];
        char strLen[3];
	
	char data1[] = "32";             ////为了演示定义的模拟数据,可根据自己传感器自行采集数据
	char data2[] = "27.8";		//
	char data3[] = "45"; 
	char data4[] = "26"; 
	char data5[] = "99.12"; 
	char data6[] = "ON"; 
	
	//通过&符号整合需要post的数据。传感器数据用#分开,以便app进行数据分割
	//自己要知道每个数据代表的意思,一会app端会按排列分割提取数值
	sprintf(postData,"uid=%s&topic=%s&msg=#%s#%s#%s#%s#%s#%s#\r\n",Uid,Topic,data1,data2,data3,data4,data5,data6); 
	dataLen = strlen(postData);             //计算数据长度
        sprintf(strLen,"%d",dataLen); 					//int类型转char

        ESP8266_Set("AT+CIPMODE=1"); //开启透明传输模式
        ms_delay(1000);
        ESP8266_Set("AT+CIPSTART=\"TCP\",\"api.bemfa.com\",80");  // 连接服务器和端口
        ms_delay(1000);
        ESP8266_Set("AT+CIPSEND"); //进入透传模式,下面发的都会无条件传输
	ms_delay(1000);
	ESP8266_Set_Only("POST /api/device/v1/data/1/ HTTP/1.1\r\nHost: api.bemfa.com\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection:close\r\nContent-Length:");//ţքdeviceۅ ţքsensorۅ
	ESP8266_Set(strLen);//数据长度(postData数据长度),一定要准确
	ESP8266_Set("");//回车(发完数据长度后,有回车,不懂的百度http post 格式)
	ESP8266_Set(postData);//发送数据	
	ms_delay(2000);
	ESP8266_Set("+++"); //
	memset(strLen,'\0',3);  //重置数组
	memset(strLen,'\0',sizeof postData);//重置数组
}
通过&符号整合需要post的数据。传感器数据用#分开,以便app进行数据分割
自己要知道每个数据代表的意思,一会app端会按排列分割提取数值

Use HTTP POST form, push a message to the server, refer to specific interfaces: Palestinian official document Fayun

You can download the program to the fifth STC89c51

Download tool STC-ISP: Downloads: https://www.lanzous.com/iaxa4fc Password: 1234

STC89c51 / 52 and wiring issues ESP8266
C51 ---------- 8266
P30 ---------- the TX
P31 ---------- the RX
3.3V ----- 3.3V ------
Gnd Gnd ---------
3.3V ----------- EN
test the 8266 direct access 5v also work, but is not recommended

If you have a network router, it will automatically upload the data available in the Palestinian law maker culture cloud console refresh the page, you can see the data upload. As shown below:

! [Inserted here described image] ( https://img-blog.csdnimg.cn/20200103122337583.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9iZW1mYS5ibG9nLmNzZG4ubmV0,size_16,color_FFFFFF,t_70#pic_center = 350x )

Sixth, app inventor made app to receive real-time data

In appInventor click to jump domestic stations to create an account, and log in.

This operation provides only a app of the demo, the interface is too ugly, you can change the interface free play.

app inventor download: Download

The top navigation bar, then click (Project -> Import Project aia), select the previous step to download aia file import. Click Import items, you can see the control panel, the panel is divided into the formation in design and logic design, the user can switch modes in the upper right corner.

![app](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA3LzI1L2VtVlpvNC5wbmc#pic_center =350x)

(Formation of the design) can be added to the panel set up to screen for secondary development. (Logical panel) associated logic to write is performed.

! [App] ( https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA3LzI1L2VtVmx5Ni5wbmc#pic_center = 500X)
After you import the file aia, if only simple to use, only need to change two places, one is the subject of names, a UID, need to be developed who replaced his own topic (theme name) and UID (user's private key), the maker culture can get cloud console click to jump .

Theme topic should be here and ESP8266 program which set the theme changed to the same, or will not receive the message. UID modify for their own private key.

Here Insert Picture Description

Interface also function like they can freely add, change is good, download the apk file.

![app](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9zMi5heDF4LmNvbS8yMDE5LzA3LzI1L2VtVnRGSC5wbmc#pic_center =350x)

The key to explain the program

Program download, modify key parameters can be used directly, the following procedures are the key to explain:

Here Insert Picture Description

After receiving the data with a sensor in accordance with the string number # division, there are several values, it is split several times, they have to remember a few of which values ​​representative of the line sensor, such as temperature data1 to remember, data2 humidity, etc., where the number of division and the number of required data upload equal, six values, dividing it six times, seven times the value will split 7 is sequentially increased or decreased on the line.

When the screen is initialized, it will first subscribe to a topic, only subscribe to this theme, you can receive a message sent to the topic of real-time, cmd = 1 is subscription instructions, is to subscribe to topics of meaning; cmd = 9 is a testament to the instruction, it is to get values stored in the server, about the specific instruction format, the document can learn access: access Issue

Here Insert Picture Description

Seventh, results show

Here Insert Picture Description

app shows the current real-time information from various sensors, remote monitoring can do, as long as the phone network can receive data. Whether it is 2G 3G 4G WIFI will do

Eighth some minor problems that may be encountered

Here Insert Picture Description
Here Insert Picture Description

Guess you like

Origin www.cnblogs.com/bemfa/p/12623887.html