Some time ago, a "shortcut command" was added to the mobile phone system update. I also saw others using shortcut commands to control the ESP8266 output. This is indeed more suitable for us electronics enthusiasts who like to tinker!
Others only demonstrated the effect in the Douyin video, but he did not introduce in detail how to achieve it. Without a master to guide you, you can only watch and figure it out on Baidu!
Later, I gradually learned that their work was: using "shortcuts" in the mobile phone, adding "web pages" to send a "push" to the device connected to the MQTT server, and the device receives and parses it and outputs it. I also learned and figured it out!
Implementation in three steps
1. Mobile shortcut settings
1 "Get URL content": http:api.hecoluds.com/cmds?device_id=xxxxxxxxxx
2 "Method": POST
3 Header: "api-key", "xxxxxxxxxxxxxxxx" information APIKey on the MQTT server
4 Request body JSON: The content here is the information received by XCC3200 for judging output, such as "switch ,1" turns on the green light. "switch ,0" turns off the green light.
2. MQTT Settings
I directly refer to the MQTT settings on ONENET!
In particular, some parameters need to be saved
Server Addr 183.230.40.39
Port 6002
ProductID
DeviceID
AuthInfo
APIKey needs ONENET tool to calculate
3 | XCC3200 Configuration
Import the MQTT Client project in TI's CC3200 SDK into CCS, and then modify some basic parameters in main.c
Modify several aspects of main.c
MQTT server address and port
#define SERVER_ADDRESS "mqtt.heclouds.com"//mqtt.eclipse.org api
#define SERVER_IP_ADDRESS "183.230.40.39"//192.168.178.67
#define PORT_NUMBER 6002//1883
There is also some information about the XCC3200 design device
/* connection configuration */
connect_config usr_connect_config[]
{
Basic parameter modification settings
}
There is also the setting of XCC3200 connecting to the wireless network
common.h file
#define SSID_NAME " *********** " /* AP SSID */
#define SECURITY_TYPE SL_SEC_TYPE_WPA_WPA2/* Security type (OPEN or WEP or WPA*/
#define SECURITY_KEY "******** ****** " /* Password of the secured AP */
Finally, the data received in static void
Mqtt_Recv(void *app_hndl, const char *topstr, long top_len, const void *payload,
long pay_len, bool dup,unsigned char qos, bool retain) is judged and output.
//Control output
if(output_str[11]=='5')//{"switch":"1"} Here is the "shortcut command" request body JSON branch
{
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
}
else if(output_str[11]=='4')//{"switch":"1"}
{
GPIO_IF_LedOff(MCU_RED_LED_GPIO);
}
This content is originally created by EEWORLD forum user Lan Yuye . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source