stc89c51+ esp8266-01 sends WeChat messages, POST routine

Publisher:廿由人Latest update time:2020-10-16 Source: 51heiKeywords:stc89c51  esp8266-01 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Material preparation
STC89c51/52 One
ESP8266-01 One
mobile phone One
First download STC89c51 sample program (keil programming development)
Program download address: cloud.bemfa.com/zip/stc89c51_wechat.zip
Program description, baud rate 9600, crystal oscillator 11.0592
Since the default baud rate of ESP8266-01 is 115200, you need to manually adjust the baud rate of esp8266-01.
Adjustment method: ESP8266-01 is connected to the usb to ttl

five wires
esp8266---------UsbTTL
tx----------rx
rx----------tx
vcc-------3.3v
gnd--------gnd
en----------3.3v

Open the serial port debugging assistant, set the baud rate to 115200, find the com port of esp8266 and open it, send

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


Copy code


A carriage return and line feed should be added at the end, and the serial port will reply ok

If it does not reply OK, the firmware may not support changing the baud rate. You need to flash the official AT firmware. Please refer to my other article Flashing the official firmware


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

Use keil to open the program, you need to modify WIFI and other information


  1. #define Ssid "newhtc" //WIFI name, change it to the WIFI name of your own router, it seems that Chinese is not supported

  2. #define PassWord "qq123456" //WIFI password, change it to your own router

  3. #define Uid "4d9ec352e0376f2110a0c601a2857225" //Bafa Cloud UID key, obtained from the console

  4. #define Device "ewew00232" //Device name, you can name it as you like, in string format

Copy code



The user's private key can be obtained by clicking on the Baffa Cloud Console. After logging in by scanning the WeChat QR code, you can click on the Baffa Maker Cloud Console to obtain it.

Users who registered with an email address need to click "Bind WeChat" in the console to bind, otherwise messages will not be pushed.

After logging in, you can see your private key UID in the console, as shown in the figure:


Second key program explanation

        int dataLen;

        float postData[150];

        char strLen[3];

        char Msg[] = "message"; //Message body, customizable, string format

        char Msg2[] = "Message 2, Remarks"; //Additional message, customizable, string format

         

        sprintf(postData,"uid=%s&type=1&time=0&device=%s&msg=%s&msg2=%srn",Uid,Device,Msg,Msg2); //Integrate the data that needs to be posted through the & symbol

        dataLen = strlen(postData); //Calculate data length

        sprintf(strLen,"%d",dataLen); //int type to char


        ESP8266_Set("AT+CIPMODE=1"); //Enable transparent transmission mode

        ms_delay(1000);

        ESP8266_Set("AT+CIPSTART="TCP","api.bemfa.com",80"); // Connect to server and port

        ms_delay(1000);

        ESP8266_Set("AT+CIPSEND"); //Enter transparent transmission mode, all the following will be transmitted unconditionally

        ms_delay(1000);

        ESP8266_Set_Only("POST /api/wechat/v1/ HTTP/1.1rnHost: ai.bemfa点comrnContent-Type: application/x-www-form-urlencodedrnConnection:closernContent-Length:");//ţքdeviceۅ ţքsensorۅ

        ESP8266_Set(strLen); //Data length (postData data length), must be accurate

        ESP8266_Set(""); //Enter (after sending the data length, there is a carriage return, Baidu http post format for those who don’t understand)

        ESP8266_Set(postData); //Send data        

        ms_delay(2000);

        ESP8266_Set("+++"); //

        memset(strLen,'',3); //Reset array

        memset(strLen,'',sizeof postData);//Reset array

Use HTTP POST to push messages to the WeChat API. For specific interfaces, please refer to: Bafa Cloud Official Document
Third Download the program to STC89c51 to

download the tool STC-ISP: Download: www.lanzous.com/iaxa4fc Password: 1234

STC89 and ESP8266 wiring problem
c51 ----------8266
P30----------TX
P31----------RX
3.3v-----------3.3v
Gnd---------Gnd
3.3v-----------EN
Tried 8266 directly connected to 5v and it also worked, but it is not recommended to use

the fourth effect display

Fifth, some minor problems you may encounter




Keywords:stc89c51  esp8266-01 Reference address:stc89c51+ esp8266-01 sends WeChat messages, POST routine

Previous article:mcu-stc12c5404ad MCU brushless dc motor driver
Next article:51 single chip microcomputer three-way answering machine

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号