首页
大事记
友情链接
留言板
关于
Search
1
无界拷贝文件在线传输系统开始公测
846 阅读
2
宝塔BT面板PHP防CC
845 阅读
3
解决SSH登录卡在"Last login"问题
512 阅读
4
高考作文论证方法之“广深高铁”
368 阅读
5
智慧报考系统开始公测
337 阅读
默认分类
新鲜科技
时事热点
学无止境
Python
Arduino
作文素材
C语言
踩坑记录
机器学习
资源分享
站长杂谈
登录
Search
标签搜索
机器学习
Datawhale
C语言
git
python
组队学习
物联网
esp8266
PHP
云顶书院
Linux
建站
网站
宝塔
开学
清明节
VPS
Arduino
开源硬件
拟合
MoyiTech
累计撰写
54
篇文章
累计收到
33
条评论
首页
栏目
默认分类
新鲜科技
时事热点
学无止境
Python
Arduino
作文素材
C语言
踩坑记录
机器学习
资源分享
站长杂谈
页面
大事记
友情链接
留言板
关于
搜索到
37
篇与
的结果
2020-05-04
ESP8266实现智能家居
emmm…很早以前发过一个关于esp8266智能家居的视频,难得有时间整理一下。环境配置这里使用Arduino作为IDE,这里介绍两种使用方法。使用原生Arduino配置(推荐)如果你在国外可以使用 IDE进行安装ps:由于某些原因,在国内下载慢(高速方法自行探索),但这种方法以后用起来还是比较稳定的。直接下载Arduino版SDK(未测试)下载打包好的esp8266安装包,直接运行并解压即可。下载地址1:https://pan.baidu.com/s/19yEQ4UDF-bQCzt3BsdV6Yw下载地址2:https://share.weiyun.com/5CGEKJO如果安装过其他版本的esp8266sdk,请先删除,再使用本安装包解压完成后,再打开Arduino IDE,即可在 菜单栏>工具>开发板 中找到你使用的esp8266开发板ESP8266程序编写SDk为我们提供了丰富的拓展库,本文主要用到了以下库#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h>HTML页面建议新建一个文件进行编写,这里值得注意的是:当HTML代码复制到IDE里面时需要先对引号进行转码成",所有汉字也要进行转码,然后用一些在线小工具进行HTML压缩,最后先赋值到变量就行了。String html="<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>this is title</title></head><body><a href=\"./pin?light=1on\"><input type=\"button\" value=\"开1灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=1off\"><input type=\"button\" value=\"关1灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=2on\"><input type=\"button\" value=\"开2灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=2off\"><input type=\"button\" value=\"关2灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=3on\"><input type=\"button\" value=\"开热水器\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=3off\"><input type=\"button\" value=\"关热水器\"style=\"width: 300px; height: 200px;\"</a></body></html>";剩下的代码就不一一赘述了,附在下面了,大家自行参考叭#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> const char* ssid = "SSID"; const char* password = "password"; ESP8266WebServer server(80); String html="<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>this is title</title></head><body><a href=\"./pin?light=1on\"><input type=\"button\" value=\"开1灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=1off\"><input type=\"button\" value=\"关1灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=2on\"><input type=\"button\" value=\"开2灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=2off\"><input type=\"button\" value=\"关2灯\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=3on\"><input type=\"button\" value=\"开热水器\"style=\"width: 300px; height: 200px;\"</a><a href=\"./pin?light=3off\"><input type=\"button\" value=\"关热水器\"style=\"width: 300px; height: 200px;\"</a></body></html>"; const int led = 13; void pin(){ if(server.arg("light")=="1on"){ digitalWrite(D1, HIGH); server.send(200, "text/html",html); }else if(server.arg("light")=="1off"){ digitalWrite(D1, LOW); server.send(200, "text/html",html); }else if(server.arg("light")=="2on"){ digitalWrite(D2, HIGH); server.send(200, "text/html",html); }else if(server.arg("light")=="2off"){ digitalWrite(D2, LOW); server.send(200, "text/html",html); }else if(server.arg("light")=="3on"){ digitalWrite(D3, HIGH); server.send(200, "text/html",html); }else if(server.arg("light")=="3off"){ digitalWrite(D3, LOW); server.send(200, "text/html",html); } } void handleRoot() { digitalWrite(led, 1); server.send(200, "text/html", html); digitalWrite(led, 0); } void handleNotFound(){ digitalWrite(led, 1); String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i=0; i<server.args(); i++){ message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; } server.send(404, "text/plain", message); digitalWrite(led, 0); } void setup(void){ pinMode(D1, OUTPUT); pinMode(D2, OUTPUT); pinMode(D3, OUTPUT); pinMode(D4, OUTPUT); digitalWrite(led, 0); Serial.begin(115200); WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if (MDNS.begin("esp8266")) { Serial.println("MDNS responder started"); } server.on("/", handleRoot); server.on("/pin", HTTP_GET, pin); server.on("/inline", [](){ server.send(200, "text/plain", "this works as well"); }); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop(void){ server.handleClient(); }
2020年05月04日
157 阅读
0 评论
1 点赞
2020-04-13
Python粉丝数实时播报程序
源码:import requests import time import sys from playsound import _playsoundWin # 保证兼容python2以及python3 IS_PY3 = sys.version_info.major == 3 if IS_PY3: from urllib.request import urlopen from urllib.request import Request from urllib.error import URLError from urllib.parse import urlencode from urllib.parse import quote_plus else: import urllib2 from urllib import quote_plus from urllib2 import urlopen from urllib2 import Request from urllib2 import URLError from urllib import urlencode def hechng(res): # 替换你的 API_KEY(百度开放平台) API_KEY = '替换你的 API_KEY' # 替换你的 SECRET_KEY(百度开放平台) SECRET_KEY = '替换你的 API_KEY' # 大姚的订单信息内容文本 TEXT = res TTS_URL = 'http://tsn.baidu.com/text2audio' """ TOKEN start """ TOKEN_URL = 'http://openapi.baidu.com/oauth/2.0/token' """ 获取token """ def fetch_token(): params = {'grant_type': 'client_credentials', 'client_id': API_KEY, 'client_secret': SECRET_KEY} post_data = urlencode(params) if (IS_PY3): post_data = post_data.encode('utf-8') req = Request(TOKEN_URL, post_data) try: f = urlopen(req, timeout=5) result_str = f.read() except URLError as err: print('token http response http code : ' + str(err.code)) result_str = err.read() if (IS_PY3): result_str = result_str.decode() result = json.loads(result_str) if ('access_token' in result.keys() and 'scope' in result.keys()): if not 'audio_tts_post' in result['scope'].split(' '): print('please ensure has check the tts ability') exit() return result['access_token'] else: print('please overwrite the correct API_KEY and SECRET_KEY') exit() """ TOKEN end """ if __name__ == '__main__': token = fetch_token() tex = quote_plus(TEXT) # 此处TEXT需要两次urlencode params = {'tok': token, 'tex': tex, 'cuid': "quickstart", 'lan': 'zh', 'ctp': 1} # lan ctp 固定参数 data = urlencode(params) req = Request(TTS_URL, data.encode('utf-8')) has_error = False try: f = urlopen(req) result_str = f.read() headers = dict((name.lower(), value) for name, value in f.headers.items()) has_error = ('content-type' not in headers.keys() or headers['content-type'].find('audio/') < 0) except URLError as err: print('http response http code : ' + str(err.code)) result_str = err.read() has_error = True save_file = "error.txt" if has_error else u'tmp.mp3' with open(save_file, 'wb') as of: of.write(result_str) if has_error: if (IS_PY3): result_str = str(result_str, 'utf-8') print("tts api error:" + result_str) print("file saved as : " + save_file) _playsoundWin('tmp.mp3') # playsound('tmp.mp3') time.sleep(10) res = requests.get('https://api.bilibili.com/x/relation/stat?vmid=128723428&jsonp=jsonp') res = res.json() res = res['data']['follower'] print(res) while True: time.sleep(1) tmp = requests.get('https://api.bilibili.com/x/relation/stat?vmid=128723428&jsonp=jsonp') tmp = tmp.json() tmp = tmp['data']['follower'] print(tmp) # if os.path.exists('tmp.mp3'): # os.remove('tmp.mp3') if tmp > res: hechng('粉丝数增加了' + str(tmp - res) + ',目前粉丝数' + str(tmp)) res = tmp if tmp < res: hechng('粉丝数减少了' + str(res - tmp) + ',目前粉丝数' + str(tmp)) res = tmp
2020年04月13日
111 阅读
0 评论
0 点赞
1
...
7
8