esp8266 微信 提醒 server酱 使用心得

server酱官网 http://sc.ftqq.com/3.version
参考 实例https://www.arduino.cn/forum.php?mod=viewthread&tid=82977&highlight=%E5%BE%AE%E4%BF%A1

8266微信

#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#define LED 2
String payload = "";
String str = "";//获取数据储存变量
String com, tem1, tem2, humi, temnow, sta, state1, state2, time0, time1, time2, englis,hbaojing,comdata;
String webadd = "http://flash.weather.com.cn/wmaps/xml/zhengzhou.xml"; //天气接口地址
String time_url = "http://quan.suning.com/getSysTime.do"; //时间接口地址
String english_url = "http://open.iciba.com/dsapi/"; //英语接口地址
String key = "获取的key";//sever酱获取的key
void smartConfig()
{
WiFi.mode(WIFI_STA);
Serial.println("\r\nWait for Smartconfig");
WiFi.beginSmartConfig();
while (1)
{
Serial.print(".");
digitalWrite(LED, 0);
delay(500);
digitalWrite(LED, 1);
delay(500);
if (WiFi.smartConfigDone())
{
  Serial.println("SmartConfig Success");
  Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str());
  Serial.printf("PSW:%s\r\n", WiFi.psk().c_str());
  break;
}
}
}
void setup()
{
Serial.begin(9600);

pinMode(LED, OUTPUT);
digitalWrite(LED, 0);
smartConfig();
}

//http数据获取**/
void http() {
HTTPClient http;
http.begin(webadd);
int httpCode = http.GET();
if (httpCode > 0) {
payload = http.getString();
//Serial.println(payload);
int a = payload.indexOf("101180101");//自己搜索链接可知指定城市的id郑州市的id为‘101180101’
//indexof();在字符串中中查找字符位置,返回值为给定字符的第一个位置,查找失败返回-1
com = payload.substring(a - 280, a + 12);
//字符串解析函数:substring(?,…),返回值为指定位置的字符串值
//Serial.println(com);
//
}
http.end();
}
//获取时间*****/
void get_time()
{
HTTPClient http;
http.begin(time_url);
int httpCode = http.GET();
if (httpCode > 0) {
payload = http.getString();
str= payload.substring(54,56);
delay(1000);
Serial.println(str);

}
http.end();
}

//报警显示*****/

void wechat(String title,String message)
{
HTTPClient http;
   //发送post请求,把消息发出去
http.begin("http://sc.ftqq.com/"+key+".send?text="+title+"&desp="+message);
 
  
   int httpCode = http.GET();
   
 
    http.end();
//结束
  }
void loop()
{
digitalWrite(LED, 1);

get_time();
http();

 wechat("220V电源已上线。","我已经活过来了");//发送微信通知消息

// show();

delay(2000);
}

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值