Micropython学习交流群 学习QQ群:786510434 提供多种固件下载和学习交流。
Micropython-扇贝物联 QQ群:31324057 扇贝物联是一个让你与智能设备沟通更方便的物联网云平台
Micropython学习交流群 学习QQ群:468985481 学习交流ESP8266、ESP32、ESP8285、wifi模块开发交流、物联网。
Micropython老哥俩的IT农场分享QQ群:929132891 为喜欢科创制作的小白们分享一些自制的计算机软硬件免费公益课程,由两位多年从事IT研发的中年大叔发起。
#import start
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()
import socket
import network
from machine import Pin, I2C
import time
led1=Pin(12,Pin.OUT)
led2=Pin(13,Pin.OUT)
def led_random():
led1.on()
time.sleep(0.1)
led1.off()
led2.on()
time.sleep(0.1)
led2.off()
def http_get(url):
_, _, host, path = url.split('/', 3)
addr = socket.getaddrinfo(host, 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8'))
while True:
data = s.recv(200)
if data:
print(data.decode('utf-8'), end='')
else:
led_random()
break
s.close()
led1.on()
led2.on()
def do_connect():
sta_if = network.WLAN(network.STA_IF)
if not sta_if.isconnected():
print('connecting to network...')
sta_if.active(True)
sta_if.connect('NBWIFI', 'z7758521')
while not sta_if.isconnected():
led_random()
pass
print('network config:', sta_if.ifconfig())
# 注意替换成自己的接口信息
http_get("http://www.tianqiapi.com/api?version=v9&appid=YourAppId&appsecret=YourSecret&city=%E5%8C%97%E4%BA%AC")
try:
do_connect()
except Exception as e:
print(e)
Copyright © 2014 ESP56.com All Rights Reserved
执行时间: 0.0087001323699951 seconds