ESP32局域网IP查询工具
操作控制
信息
刷新
原理说明
1.开发板连接wifi后把自身IP地址提交到云端
2.通过云端查询设备IP地址
功能代码
codes
import network import utime as time import urequests import time,json,machine import gc def do_connect(): wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') #打开手机热点设置wifi名称 和 密码并启用,然后开发板通电或者按键进行配网 wlan.connect('esp56.com', '12345678') i = 1 while not wlan.isconnected(): print("正在链接...{}".format(i)) i += 1 time.sleep(1) print('network config:', wlan.ifconfig()) print('ip:', wlan.ifconfig()[0]) if wlan.isconnected(): def sendlanip(): import urequests import network gateway = None station = network.WLAN(network.STA_IF) if station.status() == network.STAT_GOT_IP: lanip = station.ifconfig()[0] print("lanip"+lanip) result = urequests.get("http://www.esp56.com/tool/deviceip/deviceip.php?lanip="+lanip) if result.status_code == 200: # query success print('上传自身IP完成.') #return result.text else: # query failed, retry retry_delay ms later return "error" print("sendlanip error") do_connect()#连接wifi sendlanip()#上传自身IP
Copyright © 2018-