https://www.jianshu.com/p/cb0274d612b5

https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1572896567081&di=850e6d2014877a76396298eb9eef2b2b&imgtype=0&src=http%3A%2F%2Flearning.grobotronics.com%2Fwp-content%2Fuploads%2F2013%2F07%2Furl_uploaded_file_135884635050fe598fa6c4e.gif

其他内容再补充,太晚啦。

#include <Arduino.h>
#include <U8g2lib.h>
#include "DHT.h"
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h> #ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
#define SCL 5
#define SDA 4
#define DHTPIN 13
#define DHTTYPE DHT11 // DHT 11 #ifndef STASSID
#define STASSID "******"
#define STAPSK "******"
#endif const char* ssid = STASSID;
const char* password = STAPSK; const char* host = "192.168.31.203";
const int httpsPort = 5001; U8G2_SSD1306_128X32_UNIVISION_1_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
//U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display DHT dht(DHTPIN, DHTTYPE); void setup() {
// put your setup code here, to run once:
u8g2.begin();
u8g2.enableUTF8Print();
Serial.begin(115200);
Serial.println(F("DHTxx test!")); dht.begin(); Serial.print("connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
} uint8_t m = 24; void loop() { delay(2000); // Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true); // Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
} // Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false); Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F")); //u8g2.setFont(u8g2_font_unifont_t_chinese1); // use chinese2 for all the glyphs of "你好世界"
u8g2.setFont(u8g2_font_wqy16_t_gb2312b);
//u8g2.setFont(u8g2_font_6x13_tn);
u8g2.firstPage();
do {
u8g2.setFontDirection(0);
u8g2.clearBuffer();
u8g2.setCursor(10, 13);
u8g2.print("-温度"+(String)t+"C" );
u8g2.setCursor(10, 30);
u8g2.print("-湿度"+(String)h+"%"); // Chinese "Hello World"
u8g2.sendBuffer(); //u8g2.drawStr(0,15,"Hello World!");
}while(u8g2.nextPage());
delay(1000); WiFiClient client;
Serial.print("connecting to ");
Serial.println(host); if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
} // Wait a few seconds between measurements.
delay(1000); String url = "/";
Serial.print("requesting URL: ");
Serial.println(url); // 组拼HTTPS请求的Header
String jsonStr = String("") +
"{\"Humidity\":"+h+","+
"\"Temperature\":"+t+"}";
/*
"{'datastreams':[{" +
"'id':'" + dataId + "'" +
",'datapoints':[{" +
"'value':" + data +
"}]}]}";
*/
Serial.println(jsonStr);
String getStr = String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: arduino\r\n" +
"Connection: close\r\n"; client.print(getStr); // 发送Headers头
client.print(String("") + "Content-Length:" + jsonStr.length() + "\r\n\r\n"); // 发送Header头-数据内容长度(注意:\r\n\r\n是结尾)
client.print(jsonStr); // 发送json数据 Serial.println("request sent"); Serial.println("==========");
Serial.println("send was:");
Serial.println(jsonStr); // 打印发送的请求数据
Serial.println("reply was:");
String line = "";
while (client.connected() || client.available())
{
if (client.available())
{
line = client.readStringUntil('\n'); }
}
Serial.println(line);
Serial.println("=========="); }

  

【物联网】传感器+wifi传输+回复+显示的更多相关文章

  1. 高度集成智能家居物联网网关WiFi通信应用的无线路由模块:模小块成长记

    大家好,我叫模小块,代号L107模块,出生在BOJINGnet大家庭里,我在物联网网关里不可或缺,或许业内专业人士和物联网工程师知道我的存在.别看我体积小(40mm25mm3mm),贴片式邮票孔接口( ...

  2. 2-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(数据库简单说明)

    1-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(视频总揽) 这里有个教程   http://www.cnblogs.com/best/p/6517755.h ...

  3. 1-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案升级篇(方案总揽)

    我的这个升级篇的代码适用于自己所有的带WIFI和GPRS模块的开发板,升级功能实质上是通过MQTT把数据发给WIFI和GPRS模块,然后模块进行保存和运行. 这个升级程序是当时自己花了两个星期的时间写 ...

  4. 7 无线wifi传输视频开发

    转载,侵删 7 无线wifi传输视频开发 MT7601的驱动源码提供了两种:AP模式和STA模式源码.此时我使用USB作为AP热点,电脑作为STA模式,并使用ORTP实现无线传输视频 7.1.AP模式 ...

  5. 4-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(为域名申请SSl证书)

    3-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(购买域名,域名绑定IP) 然后就是等着..... 假设可以了 咱呢是配置MQTT实现SSL安全加密通信,所以 ...

  6. 3-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(购买域名,域名绑定IP)

    2-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(监听Wi-Fi和APP的数据) 因为安全连接是和域名绑在一块的,所以需要申请域名 有没有不知道域名是什么的, ...

  7. 2-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(监听Wi-Fi和APP的数据)

    1-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(来看一下怎么样监听网络数据,监听电脑上位机软件的数据) 因为那个软件只能监听咱自己电脑上的数据,所以咱就用电 ...

  8. 1-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案安全篇(来看一下怎么样监听网络数据,监听电脑上位机软件的数据)

    首先安装网络监听软件 运行这个软件 这个软件安装到电脑上,默认是监听咱电脑上的网络通信 咱们先监听电脑的软件的网络通信数据,然后再说怎么监听Wi-Fi和APP的软件的网络通信数据 咱就监听咱基础篇的 ...

  9. 4-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(云端电脑(Windows)安装配置数据库,使用本地Navicat for MySQL和手机APP 远程连接测试)

    3-STM32物联网开发WIFI(ESP8266)+GPRS(Air202)系统方案数据篇(安装配置数据库,使用Navicat for MySQL和手机APP 连接测试) 根据前面的教程把软件复制到云 ...

随机推荐

  1. python的isinstance()函数

    以下是使用isinstance()函数的实例: a = isinstance(a,int) # 结果返回 True isinstance(a,str) # 结果返回 False 即:第1个参数是第2个 ...

  2. Python如何实现doc文件转换为docx文件?

    Python如何实现doc文件转换为docx文件? 在开发过程中遇到一个关于读写doc和docx的问题: 一个文件夹中有两种文件, 一种为doc结尾, 一种为docx结尾, 需要将这些文件全部重命名. ...

  3. if语句:若边长小于等于0,则不进行计算;否则,计算正方形的面积

    #include<stdio.h>void main(){ float a; printf("Input the value:"); scanf("%f&qu ...

  4. nginx 故障转移

    当我们的服务器某台出现问题的时候,怎么办.... nginx在反向代理到真实服务器(上游服务器)的时候,如果真实服务器出现了宕机,或延迟卡顿的情况下,直接轮询下一个节点. 其中主要配置如下: ###n ...

  5. CSS3中的display:grid网格布局介绍

    1.网格布局(grid): 它将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局; 2.基本概念: 容器和项目,如图所示: <div class="content&qu ...

  6. pyy整队 线段树

    pyy整队 线段树 问题描述: 众所周知pyy当了班长,服务于民.一天体育课,趁体育老师还没来,pyy让班里n个同学先排好 队.老师不在,同学们开始玩起了手机.站在队伍前端玩手机,前面的人少了,谁都顶 ...

  7. 10分钟手把手教你运用Python实现简单的人脸识别

    欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 前言:让我的电脑认识我 我的电脑只有认识我,才配称之为我的电脑! 今天,我们用Python实现高大上的人脸识别技术! Python里,简单的 ...

  8. Transformer 比较好的博客

    1. https://www.jianshu.com/p/0c196df57323 细节理解: 2. https://zhuanlan.zhihu.com/p/44121378 3. https:// ...

  9. 像素迷踪,当Unity的Frame Debugger力不从心时

    http://www.manew.com/thread-92382-1-1.html 从版本5开始,Unity包含了一个全新的可视化帧调试工具,Frame Debugger.该工具能帮你解决很多图形方 ...

  10. 微信小程序微信登录

    开发接口 登录 wx.login wx.checkSession 签名加密 小程序登录 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识,快速建立小程序内的用户体系. 登录流程时序 ...