element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Tutorials
  • Products
  • Arduino
  • Arduino Tutorials
  • More
  • Cancel
Arduino Tutorials
Blog How to deliver data of sensor to the cloud platform(LinkNode D1)
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Tutorials to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: alvin_jin
  • Date Created: 12 Aug 2016 9:23 AM Date Created
  • Views 863 views
  • Likes 0 likes
  • Comments 0 comments
  • wifi
  • d1
  • esp8266
  • cloud
  • iot
  • arduino
Related
Recommended

How to deliver data of sensor to the cloud platform(LinkNode D1)

alvin_jin
alvin_jin
12 Aug 2016

linspriteio5

Summary

DHT22 module applies specific digital blocks collection technology and temperature and humidity sensing technology to ensure that products with high reliability and excellent long-term stability. Sensor comprises a capacitive humidity sensing element and a high-precision temperature component, and with a high-performance 8-bit microcontroller connected. Therefore, the product has excellent quality, fast response, anti-interference ability, high cost and so on.  Measurable temperature range of the module: -40-80 ℃ ± 0.5 ℃, humidity range: 20-90% RH ± 2% RH. The module is widely used in temperature and humidity regulator, weather station, and other relevant temperature and humidity detection control.

Material preparation

  • LinkNode D1 x 1
  • DHT22 x 1
  • DuPont line
  • Arduino IDE

Steps

1. Login linksprite.io ,record the “Device ID” and “API key” ( If there is no account, please sign up. )

  • 1. My Profile -> API key

linkspriteio5-1024x396

  • 2. My device->Create DIY Device

Enter Device Name,Device Type , Group Name , the device number is 03, device name and device grouping can be any.

linspriteio

Note: Device Type must be selected 03(Custom device type) .Click the device you created and record the “Device ID”.

linspriteio1

2. Edit and run the code

Modify the “apikey” and “deviceID”  with content acquired before

1

Compile the code and upload.

3.  Results

  1. Serial Monitor

 

linspriteio3    

2. LinkSprite IO

linspriteio4

 

Code

#include <ESP8266WiFi.h>
#include <WString.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>       
  
#include "DHT.h"
  
#define DHTPIN D0     // what pin we're connected to
  
#define DHTTYPE DHT22   // DHT 22  (AM2302)
  
char *tem="";
String apikey = "162d15b0-2c6d-4d44-b288-10f28a527f96";
const char* deviceID="030000000f";
const char* server = "www.linksprite.io";
WiFiClient client;
  
  
DHT dht(DHTPIN, DHTTYPE);
  
void setup() {
  Serial.begin(9600);
  WiFiManager wifiManager;
  wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  wifiManager.autoConnect("LinkNodeAP");
  Serial.print("WiFi Connected ...\n");
  Serial.println("WiFi connected");
  Serial.println("DHTxx test!");
    
  dht.begin();
}
  
void loop() {
  
  delay(2000);
  
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // Read temperature as Celsius (the default)
  float f = dht.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true)
  
   // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  float hif = dht.computeHeatIndex(f, h); // Compute heat index in Fahrenheit (the default)
  float hic = dht.computeHeatIndex(t, h, false);// Compute heat index in Celsius (isFahreheit = false)
  
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
    
  if (client.connect(server,80)) 
  {  
     String  postStr ="{";
           postStr +="\"action\":\"update\",";
           postStr +="\"apikey\":\"";
           postStr += apikey;
           postStr +="\",";
           postStr +="\"deviceid\":\"";
           postStr += deviceID;
           postStr +="\",";
           postStr +="\"params\":";
           postStr +="{";
             
           postStr +="\"temperature\":\"";
           itoa(t,tem,10); 
           postStr +=tem;
           postStr +="\",";
          
           postStr +="\"humidity\":\"";
           itoa(h,tem,10); 
           postStr +=tem;
           postStr +="\"\r\n";
           postStr +="}";
           postStr +="}";
        
    client.print("POST /api/http HTTP/1.1\n");
    client.print("Host: ");
    client.print(server);
    client.print("\nContent-Type: application/json\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr); 
      
    String request = "";
    delay(1000);  
    while (client.available()) 
   {
     char c = client.read();
     request +=c;
   } 
  
  if (request!= NULL)
  {
   int index1 = request.indexOf(":{");
   int index2 = request.indexOf("},");
   String param = request.substring(index1, index2 + 1);
   String data="\0" ;
   Serial.print("The param is ");
   Serial.println(param);
  
   
   client.stop();
   Serial.println("waiting ...");    
   delay(1000);  
  } 
}
  
}

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube