本站改版新增arduino频道
urequest post提交文件数据
from time import sleep
import network
####################
# wifi类
####################
class Sta:
WIFI_SSID = "300king"
WIFI_PWD = "13704677369"
wlan = None
def __init__(self, wifi_ssid='', wifi_pwd=''):
network.WLAN(network.AP_IF).active(False) # disable access point
self.wlan = network.WLAN(network.STA_IF)
self.wlan.active(True)
if wifi_ssid == '':
self.wifi_ssid = Sta.WIFI_SSID
self.wifi_pwd = Sta.WIFI_PWD
else:
self.wifi_ssid = wifi_ssid
self.wifi_pwd = wifi_pwd
def connect(self, wifi_ssid='', wifi_pwd=''):
if wifi_ssid != '':
self.wifi_ssid = wifi_ssid
self.wifi_pwd = wifi_pwd
if not self.wlan.isconnected():
self.wlan.connect(self.wifi_ssid, self.wifi_pwd)
def status(self):
if self.wlan.isconnected():
return self.wlan.ifconfig()
else:
return ()
def wait(self):
cnt = 30
while cnt > 0:
print("Waiting ..." )
# con(self.wifi_ssid, self.wifi_pwd) # Connect to an WIFI_SSID
if self.wlan.isconnected():
print("Connected to %s" % self.wifi_ssid)
print('network config:', self.wlan.ifconfig())
cnt = 0
else:
sleep(5)
cnt -= 5
return
def scan(self):
return self.wlan.scan() # Scan for available access points
if __name__=='__main__':
a=Sta()
a.connect()
a.wait()
##############
# 上面是联网,下面才是发送
#############
import urequests as requests
import binascii,json
url = 'http://192.168.3.190:5000/updata' #服务器地址直接指向POST接收位置
with open('3333.jpg','rb') as f: #已经有的图片发送
img=f.read()
r = requests.post(url, data=img)
#CAM自己没有requests库,粘贴过来的库要求直接发送二进制,这里不排除别的库可以发送字典但是没有测试
print(r.text) #接收服务器数据
r.close()
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0094459056854248 seconds