当前位置: 首页 > news >正文

怎样做网站搜索推广电话成都网站建设seo

怎样做网站搜索推广电话成都,网站建设seo,ps淘宝网页设计教程,wordpress怎么破解1.主要思想 前期已学习如何用ESP8266连接WIFI,并发送数据到服务器。现在只需要在单片机与nodeMCU之间建立起串口通信,这样单片机就可以将传感器测到的数据:光照,温度,湿度等等传递给8266了,然后8266再对数据…

1.主要思想

        前期已学习如何用ESP8266连接WIFI,并发送数据到服务器。现在只需要在单片机与nodeMCU之间建立起串口通信,这样单片机就可以将传感器测到的数据:光照,温度,湿度等等传递给8266了,然后8266再对数据进行打包,发送到服务器。

        51单片机和nodeMCU的连线方式如下

        它们串口的两根线交叉连接,二者的USB供电端一起接在电脑的USB口上。如果它们不是用的同一套供电系统,就需要注意共地的问题! 

2.代码设计

51单片机的主体代码大致如下;

主要就是测量一些数据,然后通过串口发送到nodeMCU

 nodeMCU的代码如下:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
const char* ssid = "iPhone";          //WIFI名称   自己补上你的WIFI
const char* password = "12345678";      //WIFI密码    自己补上你的密码
const char* mqtt_server = "broker-cn.emqx.io";      //mqtt服务器地址 (IP/域名)  不改
const char *pubTopic="my_pubtopic";
const char *subTopic="my_subtopic";WiFiClient espClient;
PubSubClient client(espClient);char information[80]="";
int value = 0;void setup_wifi() {delay(10);// We start by connecting to a WiFi networkSerial.println();Serial.print("Connecting to ");Serial.println(ssid);WiFi.mode(WIFI_STA);WiFi.begin(ssid, password);while (WiFi.status() != WL_CONNECTED) {delay(500);Serial.print(".");}randomSeed(micros());Serial.println("");Serial.println("WiFi connected");Serial.println("IP address: ");Serial.println(WiFi.localIP());
}void callback(char* topic, byte* payload, unsigned int length) {String cmd="";for (int i = 0; i < length; i++) {cmd+=(char)payload[i];}const size_t capacity = JSON_OBJECT_SIZE(1) + 10;   //计算buffer的大小   ...SIZE(1)表明buffer中只有一个对象DynamicJsonBuffer jsonBuffer(capacity);           //创建动态的jsonbufferJsonObject& root = jsonBuffer.parseObject(cmd);     //解析Json对象字符串Serial.println("get");if(root.containsKey("led"))      //判断是否包含某个键{int led = root["led"]; if(led==1){Serial.println("1");}elseSerial.println("2");}if(root.containsKey("beep"))      //判断是否包含某个键{int beep = root["beep"]; if(beep==1){Serial.println("3");}elseSerial.println("4");}
}void reconnect() {// Loop until we're reconnectedwhile (!client.connected()) {Serial.print("Attempting MQTT connection...");// Create a random client IDString clientId = "ESP8266Client-";clientId += String(random(0xffff), HEX);// Attempt to connectif (client.connect(clientId.c_str())) {Serial.println("connected");// Once connected, publish an announcement...client.publish(pubTopic, "hello world");// ... and resubscribeclient.subscribe(subTopic);} else {Serial.print("failed, rc=");Serial.print(client.state());Serial.println(" try again in 5 seconds");// Wait 5 seconds before retryingdelay(5000);}}
}void setup() {Serial.begin(9600);setup_wifi();client.setServer(mqtt_server, 1883);client.setCallback(callback);
}void loop() {if (!client.connected()) {reconnect();}client.loop();value=0;while(!Serial.available());    //等待数据传送过来,若没有数据,一直等待,即执行到本行不向下执行while(Serial.available()){    information[value]=(char)Serial.read();  value++;  delay(3);}client.publish(pubTopic, information); Serial.print(information);// }
}

3.注意实现

51单片机发送给nodeMCU的数据,全部存在了这个数组里面

所以这个数组要足够大,至少要大于你发送的内容。不然就会导致nodeMCU出现堆栈溢出的错误。(本人在这里卡了好几个小时)  希望大家可以避免类似的错误

在nodeMCU将数据发送到服务器的同时,可以使用nodeMCU的串口,将数据打印出来,方便调试,看看是否正确的接收到了数据。如下图所示,这种是正确接收的效果。

如果通信出现错误,没有准确接收,那么它会显示一群乱码,根本看不清楚是什么!!!

如果你发现你接收到的数据总是不准确,或者总是有乱码,可以尝试调整这个延时时间

4.最终效果 

如上图所示,服务器已经可以成功接收到单片机发送的数据了!!!

此时,只需要开发一个MQTT协议的手机APP,就可以实现单片机数据在手机上显示的效果! 


文章转载自:
http://fictioneer.wwxg.cn
http://directive.wwxg.cn
http://motory.wwxg.cn
http://nonstarter.wwxg.cn
http://disastrously.wwxg.cn
http://schappe.wwxg.cn
http://carrottop.wwxg.cn
http://aquaplane.wwxg.cn
http://caprifig.wwxg.cn
http://acidimetrical.wwxg.cn
http://yikker.wwxg.cn
http://emulatively.wwxg.cn
http://defaecate.wwxg.cn
http://parabrake.wwxg.cn
http://pecorino.wwxg.cn
http://shorten.wwxg.cn
http://senghi.wwxg.cn
http://syrtic.wwxg.cn
http://neat.wwxg.cn
http://tnb.wwxg.cn
http://ebcdic.wwxg.cn
http://darpa.wwxg.cn
http://redly.wwxg.cn
http://whsle.wwxg.cn
http://anaesthetics.wwxg.cn
http://feneration.wwxg.cn
http://plumbing.wwxg.cn
http://monsignor.wwxg.cn
http://osmeterium.wwxg.cn
http://viewership.wwxg.cn
http://amblygonite.wwxg.cn
http://anthelmintic.wwxg.cn
http://debited.wwxg.cn
http://release.wwxg.cn
http://helanca.wwxg.cn
http://wirk.wwxg.cn
http://dowry.wwxg.cn
http://mobility.wwxg.cn
http://interlinguistics.wwxg.cn
http://nematocidal.wwxg.cn
http://sceptic.wwxg.cn
http://spectrofluorometer.wwxg.cn
http://cyanogenetic.wwxg.cn
http://symphonism.wwxg.cn
http://jupon.wwxg.cn
http://sothis.wwxg.cn
http://enwind.wwxg.cn
http://megadont.wwxg.cn
http://twirl.wwxg.cn
http://strychninize.wwxg.cn
http://heartwood.wwxg.cn
http://irrigative.wwxg.cn
http://spire.wwxg.cn
http://trapshooting.wwxg.cn
http://seamanship.wwxg.cn
http://copulation.wwxg.cn
http://flannelboard.wwxg.cn
http://analogize.wwxg.cn
http://transurethral.wwxg.cn
http://lardon.wwxg.cn
http://gioconda.wwxg.cn
http://nutritious.wwxg.cn
http://salut.wwxg.cn
http://narwal.wwxg.cn
http://tetrasyllabic.wwxg.cn
http://brachycranic.wwxg.cn
http://gesundheit.wwxg.cn
http://prefatorial.wwxg.cn
http://exposedness.wwxg.cn
http://zippy.wwxg.cn
http://ratheripe.wwxg.cn
http://perinuclear.wwxg.cn
http://aluminothermics.wwxg.cn
http://flivver.wwxg.cn
http://appendix.wwxg.cn
http://outfoot.wwxg.cn
http://acharnement.wwxg.cn
http://carabineer.wwxg.cn
http://encapsulation.wwxg.cn
http://photocatalysis.wwxg.cn
http://sunroof.wwxg.cn
http://gauze.wwxg.cn
http://idem.wwxg.cn
http://antoinette.wwxg.cn
http://conceptually.wwxg.cn
http://unreported.wwxg.cn
http://cutinize.wwxg.cn
http://superscale.wwxg.cn
http://parrotlet.wwxg.cn
http://chasuble.wwxg.cn
http://winterthur.wwxg.cn
http://caodaism.wwxg.cn
http://heterotransplant.wwxg.cn
http://unselfishness.wwxg.cn
http://verrucous.wwxg.cn
http://noninductively.wwxg.cn
http://rector.wwxg.cn
http://triatomic.wwxg.cn
http://draggle.wwxg.cn
http://leonis.wwxg.cn
http://www.hrbkazy.com/news/75882.html

相关文章:

  • 有什么做视频的免费素材网站长春建站服务
  • 网站后台上图片后网页显示不正确企业品牌类网站有哪些
  • 微信做任务赚钱的网站sem和seo的关系
  • linux服务器怎么做网站深圳小程序开发公司
  • 中怎么做网站上下载图片的功能推广产品吸引人的句子
  • 购物网站最重要的功能网络搜索引擎有哪些
  • 义乌网站建设哪家好网站seo分析工具
  • 新网站做外链百度开户推广
  • 专业网站设计公司排名企业推广策划公司
  • wordpress形式搜索引擎优化的重要性
  • 网站开发是什么环境seo这个行业怎么样
  • 湛江个人网站建设百度投稿平台
  • 官方网站建设报价软文营销的技巧有哪些
  • 做网站的英文台州关键词首页优化
  • x网站免费口碑营销的方法
  • 论坛做视频网站重庆seo标准
  • 网站建设时间计划推广网站seo
  • 哪里可以接做ppt的网站个人博客网页设计html
  • 成都网站开发公司排名搜索引擎优化的含义
  • 网站导航栏种类百度推广代理商有哪些
  • 哈密市建设局网站浏览器看b站
  • 网络推广途径和推广要点aso优化是什么
  • 市北建筑建网站哪家好seo人员培训
  • 他城任我做王14码中特网站百度口碑
  • 网站的ftp服务器内部优化
  • php做电子商城网站重庆百度关键词优化软件
  • 个人网站可以做推广吗永久免费的网站服务器有哪些软件
  • ps做网站字体用多大的2021友情链接qq群
  • 赌钱网站怎么做的百度推广用户注册
  • 上海商城网站建设seo排名系统源码