当前位置:网站首页>[esp8266-01s] get weather, city, Beijing time

[esp8266-01s] get weather, city, Beijing time

2022-06-23 18:02:07A bowl of bean curd

Let's talk about the next problem found during debugging , Use TCP Transparent simulation HTTP GET A note when requesting :

  • That is to send it directly to through the serial port assistant ESP8266 Hit by hand \r\n It's invalid !!!!
     Insert picture description here
    What does this , Use CIPSEND Order or Passthrough mode Escape characters are not supported when sending data .............
    It's okay to think about it , Compilers are supported , If the module supports , You have to escape twice when you type the code .............

There will also be a problem when debugging , That is, the serial port assistant can't simulate multiple lines with one line of text by escaping characters , alas , If you don't need to send multiple messages, you don't have to , You'd better hit "enter" in the single message ..........

  • Connect wifi
AT+CWMODE=1
AT+CWJAP="wifi name ","wifi password "

Get Beijing time

  • Pay attention to check send new line ..
AT+CIPSTART="TCP","quan.suning.com",80
AT+CIPSEND=42
GET http://quan.suning.com/getSysTime.do

The reply is as follows :
 Insert picture description here

  • Note that sometimes you will reply to a lot of messy things , I don't know why , No other suitable interface was found , You can leave a message if you know .

Get weather

  • Go first www.tianqiapi.com Sign up for an account , And then you get appid and appsecret
AT+CIPSTART="TCP","tianqiapi.com",80
AT+CIPSEND=77
GET https://tianqiapi.com/api?version=v61&appid=******&appsecret=******

The reply is as follows :
 Insert picture description here
After decoding, it is like this , There is a lot of information in it :

{
    
    "cityid": "101180101",
    "date": "2022-06-18",
    "week": " Saturday ",
    "update_time": "21:23",
    "city": " zhengzhou ",
    "cityEn": "zhengzhou",
    "country": " China ",
    "countryEn": "China",
    "wea": " cloudy ",
    "wea_img": "yun",
    "tem": "33",
    "tem1": "37",
    "tem2": "26",
    "win": " Southeast wind ",
    "win_speed": "2 level ",
    "win_meter": "5km/h",
    "humidity": "34%",
    "visibility": "30km",
    "pressure": "988",
    "air": "106",
    "air_pm25": "26",
    "air_level": " Light pollution ",
    "air_tips": " children 、 Elderly and heart disease 、 Patients with respiratory diseases should try to reduce outdoor activities with high physical consumption .",
    "alarm": {
    
        "alarm_type": " The high temperature ",
        "alarm_level": " Orange ",
        "alarm_title": " Henan Province issued an orange high temperature warning ",
        "alarm_content": " Henan meteorological observatory 2022 year 6 month 18 Japan 17 when 00 Continue to issue high temperature orange warning : expect 6 month 19 During the day , zhengzhou 、 kaifeng 、 luoyang ( Main city area , Yanshi district , Mengjin District , Xin'an County , Ruyang County , Yiyang County , Yichuan County , Ibin district )、 Pingdingshan 、 anyang 、 Hebi 、 xinxiang 、 Jiaozuo 、 xuchang 、 Luohe 、 Shangqiu 、 Zhoukou 、 Zhumadian ( Xiping County , Shangcai County , Pingyu County , Suiping county )、 Jiyuan 、 The highest temperature in Puyang will rise to 37℃ above , Zhengzhou ( On the street , Xingyang city )、 kaifeng ( Qixian , Tongxu County )、 anyang 、 Hebi 、 xinxiang ( Red flag district , Weibin District , Fengquan district , Pastoral area , Xinxiang County , Huojia County , Weihui City , Huixian City )、 Jiaozuo ( Main city area , Xiuwu County , Boai County , Wuzhi County , Urban rural integration demonstration area )、 Puyang 、 Shangqiu ( Main city area , Civil rights county , Suixian , Ningling county ) The highest temperature rose to 40℃ above .\n6 month 20 During the day , zhengzhou 、 luoyang 、 Pingdingshan 、 xuchang 、 Sanmenxia 、 Nanyang 、 Xinyang ( Pingqiao District , Luoshan county , Gushi County , Huaibin County , Xixian )、 Zhoukou 、 Zhumadian 、 Jiyuan 、 kaifeng 、 anyang 、 Hebi 、 xinxiang 、 Jiaozuo 、 Puyang 、 Luohe 、 The highest temperature in Shangqiu will rise to 37℃ above , Zhengzhou ( Main city area , On the street , Zhongmou county , Airport , Gongyi City , Xingyang city , Xinzheng City )、 kaifeng 、 luoyang ( Old town , Xigong District , Fuhe District , Jianxi District , Yanshi district , Mengjin District , Luolong District , Ibin district )、 Pingdingshan ( Weidong District , Ye county , High-tech zone )、 anyang 、 Hebi 、 xinxiang 、 Jiaozuo 、 Puyang 、 xuchang 、 Luohe 、 Shangqiu 、 Zhoukou ( Chuanhui district ,"
    },
    "aqi": {
    
        "update_time": "21:22",
        "cityid": "101180101",
        "city": " zhengzhou ",
        "cityEn": "zhengzhou",
        "country": " China ",
        "countryEn": "China",
        "air": "106",
        "air_level": " Light pollution ",
        "air_tips": " children 、 Elderly and heart disease 、 Patients with respiratory diseases should try to reduce outdoor activities with high physical consumption .",
        "pm25": "26",
        "pm25_desc": " optimal ",
        "pm10": "41",
        "pm10_desc": " optimal ",
        "o3": "212",
        "o3_desc": " Light pollution ",
        "no2": "6",
        "no2_desc": " optimal ",
        "so2": "6",
        "so2_desc": " optimal ",
        "co": "-",
        "co_desc": "-",
        "kouzhao": " It is recommended to wear a mask ",
        "yundong": " Exercise is not recommended ",
        "waichu": " Not suitable for going out ",
        "kaichuang": " Reduce window opening time ",
        "jinghuaqi": " Turn off the purifier "
    }
}

Tools

原网站

版权声明
本文为[A bowl of bean curd]所创,转载请带上原文链接,感谢
https://chowdera.com/2022/174/202206231644309151.html

随机推荐