极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17497|回复: 5

用esp8266和dht11利用计算双精度上传温湿度到酱菜创客物联网

[复制链接]
发表于 2016-12-24 10:31:18 | 显示全部楼层 |阅读模式
本帖最后由 504835618 于 2016-12-24 11:03 编辑

首先去酱菜创客(jcck.online)注册申请apikey和添加设备

硬件:
        1、ESP8266           一块
        2、DHT11      一个
        3、导线若干
      当然上面三个是最主要的,除了这两个大家还需要准备3.3V电源,因为8266和DHT11的工作电压是3.3V,电源问题应该对大家来说不是难事吧

烧写模式接线方法:(用USB转TTL串口连接模块与PC)
esp8266-01         u转串
VCC-------------3.3
GND------------GND
GPIO0----------GND
CH_PD---------3.3
RX---------------TX
TX---------------Rx
运行模式ESP8266接线:
VCC---------------3.3
CH_PD-----------3.3
GND-------------GND
GPIO2----------DHT11 data脚
软件要求:arduino1.6.5版本以上,可以编译esp8266的就可以了.esp-01选择烧写设备如图




esp-12模块烧写选择如图:



这样基本就可以了

上传到酱菜创客的温湿度如下:








代码来了
///---------------------------------------------
double Fahrenheit(double celsius)
{
        return 1.8 * celsius + 32;
}    //摄氏温度度转化为华氏温度

double Kelvin(double celsius)
{
        return celsius + 273.15;
}     //摄氏温度转化为开氏温度

// 露点(点在此温度时,空气饱和并产生露珠)
// 参考: http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
        double A0= 373.15/(273.15 + celsius);
        double SUM = -7.90298 * (A0-1);
        SUM += 5.02808 * log10(A0);
        SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
        SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
        SUM += log10(1013.246);
        double VP = pow(10, SUM-3) * humidity;
        double T = log(VP/0.61078);   // temp var
        return (241.88 * T) / (17.558-T);
}

// 快速计算露点,速度是5倍dewPoint()
// 参考: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
        double a = 17.271;
        double b = 237.7;
        double temp = (a * celsius) / (b + celsius) + log(humidity/100);
        double Td = (b * temp) / (a - temp);
        return Td;
}

#include <dht11.h>
dht11 DHT11;
//-----------
#include <ESP8266WiFi.h>
WiFiClient client;
const char *ssid     = "*****";//这里是我的wifi,你使用时修改为你要连接的wifi ssid
const char *password = "****";//你要连接的wifi密码
const char *host = "jcck.online";
const int httpPort =8266;
String line ="";
int m=0;

#define DHT11PIN 2   //温湿度输入

//------------
void setup()
{
  Serial.begin(115200);
  Serial.println();
//---------------

pinMode(DHT11PIN,INPUT);
Serial.print("Connecting to ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
    delay(500);
     //smartConfig();
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  
  while (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    //return;
  }
  Serial.print("connecting to ");
  Serial.println(host);

  delay(150);
  client.write("mode=bind&apikey=xxx&data={ck001000bind}\r\n"); //修改成自己的apikey
  delay(100);


  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
delay(60000);//1分钟上传一次
  
}

void loop()
{
  
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
                Serial.println("OK");
                break;
    case DHTLIB_ERROR_CHECKSUM:
                Serial.println("Checksum error");
                break;
    case DHTLIB_ERROR_TIMEOUT:
                Serial.println("Time out error");
                break;
    default:
                Serial.println("Unknown error");
                break;
  }

  Serial.print("Humidity (%): ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (oC): ");
  Serial.println((float)DHT11.temperature, 2);

  /*Serial.print("Temperature (oF): ");
  Serial.println(Fahrenheit(DHT11.temperature), 2);

  Serial.print("Temperature (K): ");
  Serial.println(Kelvin(DHT11.temperature), 2);

  Serial.print("Dew Point (oC): ");
  Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

  Serial.print("Dew PointFast (oC): ");
  Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));/*/


String str1="mode=up&apikey=f5a4a83d00b08870&data={ck001002";
  str1+=DHT11.humidity;      //湿度
  str1+=".";
  str1+=DHT11.temperature;   //温度
  str1+="}\r\n";
  client.print(str1);
  Serial.print(str1);
  
String line ="";
  m++;
  if(m%40==0)
  {
    client.write("mode=up&apikey=xxx &data={ck002001life}\r\n");//发送心跳消息,xxx修改成你自己的apikey
    m=0;
   }
  delay(2000);
}




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2017-2-8 23:45:59 | 显示全部楼层
LZ 能具体说下模块烧写的方法么,我找了半天都没有找到图上的界面
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-2-13 15:37:54 | 显示全部楼层
托米 发表于 2017-2-8 23:45
LZ 能具体说下模块烧写的方法么,我找了半天都没有找到图上的界面

http://jcck.online/phpwind/index.php?m=bbs
回复 支持 反对

使用道具 举报

发表于 2017-7-19 19:49:51 | 显示全部楼层
酱菜创客网址已经改变了,原域名已访问不了,新域名:www.jcckiot.com
回复 支持 反对

使用道具 举报

发表于 2018-3-8 20:44:11 | 显示全部楼层
chenyuechi 发表于 2017-7-19 19:49
酱菜创客网址已经改变了,原域名已访问不了,新域名:www.jcckiot.com

const char *host = "jcck.online";
域名变了,代码这个位置是不是也要变
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-10 08:58:39 | 显示全部楼层
lijiaming 发表于 2018-3-8 20:44
const char *host = "jcck.online";
域名变了,代码这个位置是不是也要变

当然要变,这里是酱菜服务器地址
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 03:37 , Processed in 0.044499 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表