Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
View: 2630|Reply: 3

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

[Copy link]

17

Threads

17

Posts

91

Credits

Registered member

Rank: 2

Credits
91
Post time 2016-11-1 17:14:19 | Show all posts |Read mode
                                        SummaryDHT22 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
Steps1. Login linksprite.io ,record the “Device ID” and “API key”( If there is no account, please sign up. )
  • 1. My Profile -> API key

  • 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.

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

2. Edit and run the codeModify the “apikey” and “deviceID”  with content acquired before

Compile the code and upload.
3.  Results
  • Serial Monitor

     2. LinkSprite IO




  1. #include <ESP8266WiFi.h>
  2. #include <WString.h>
  3. #include <DNSServer.h>
  4. #include <ESP8266WebServer.h>
  5. #include <WiFiManager.h>      
  6.   
  7. #include "DHT.h"
  8.   
  9. #define DHTPIN D0     // what pin we're connected to
  10.   
  11. #define DHTTYPE DHT22   // DHT 22  (AM2302)
  12.   
  13. char *tem="";
  14. String apikey = "162d15b0-2c6d-4d44-b288-10f28a527f96";
  15. const char* deviceID="030000000f";
  16. const char* server = "www.linksprite.io";
  17. WiFiClient client;
  18.   
  19.   
  20. DHT dht(DHTPIN, DHTTYPE);
  21.   
  22. void setup() {
  23.   Serial.begin(9600);
  24.   WiFiManager wifiManager;
  25.   wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
  26.   wifiManager.autoConnect("LinkNodeAP");
  27.   Serial.print("WiFi Connected ...\n");
  28.   Serial.println("WiFi connected");
  29.   Serial.println("DHTxx test!");
  30.    
  31.   dht.begin();
  32. }
  33.   
  34. void loop() {
  35.   
  36.   delay(2000);
  37.   
  38.   float h = dht.readHumidity();
  39.   float t = dht.readTemperature(); // Read temperature as Celsius (the default)
  40.   float f = dht.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true)
  41.   
  42.    // Check if any reads failed and exit early (to try again).
  43.   if (isnan(h) || isnan(t) || isnan(f)) {
  44.     Serial.println("Failed to read from DHT sensor!");
  45.     return;
  46.   }
  47.   
  48.   float hif = dht.computeHeatIndex(f, h); // Compute heat index in Fahrenheit (the default)
  49.   float hic = dht.computeHeatIndex(t, h, false);// Compute heat index in Celsius (isFahreheit = false)
  50.   
  51.   Serial.print("Humidity: ");
  52.   Serial.print(h);
  53.   Serial.print(" %\t");
  54.   Serial.print("Temperature: ");
  55.   Serial.print(t);
  56.   Serial.print(" *C ");
  57.   Serial.print(f);
  58.   Serial.print(" *F\t");
  59.   Serial.print("Heat index: ");
  60.   Serial.print(hic);
  61.   Serial.print(" *C ");
  62.   Serial.print(hif);
  63.   Serial.println(" *F");
  64.    
  65.   if (client.connect(server,80))
  66.   {  
  67.      String  postStr ="{";
  68.            postStr +="\"action\":\"update\",";
  69.            postStr +="\"apikey\":\"";
  70.            postStr += apikey;
  71.            postStr +="\",";
  72.            postStr +="\"deviceid\":\"";
  73.            postStr += deviceID;
  74.            postStr +="\",";
  75.            postStr +="\"params\":";
  76.            postStr +="{";
  77.             
  78.            postStr +="\"temperature\":\"";
  79.            itoa(t,tem,10);
  80.            postStr +=tem;
  81.            postStr +="\",";
  82.          
  83.            postStr +="\"humidity\":\"";
  84.            itoa(h,tem,10);
  85.            postStr +=tem;
  86.            postStr +="\"\r\n";
  87.            postStr +="}";
  88.            postStr +="}";
  89.         
  90.     client.print("POST /api/http HTTP/1.1\n");
  91.     client.print("Host: ");
  92.     client.print(server);
  93.     client.print("\nContent-Type: application/json\n");
  94.     client.print("Content-Length: ");
  95.     client.print(postStr.length());
  96.     client.print("\n\n");
  97.     client.print(postStr);
  98.       
  99.     String request = "";
  100.     delay(1000);  
  101.     while (client.available())
  102.    {
  103.      char c = client.read();
  104.      request +=c;
  105.    }
  106.   
  107.   if (request!= NULL)
  108.   {
  109.    int index1 = request.indexOf(":{");
  110.    int index2 = request.indexOf("},");
  111.    String param = request.substring(index1, index2 + 1);
  112.    String data="\0" ;
  113.    Serial.print("The param is ");
  114.    Serial.println(param);
  115.   
  116.    
  117.    client.stop();
  118.    Serial.println("waiting ...");   
  119.    delay(1000);  
  120.   }
  121. }
  122.   
  123. }
Copy the Code



61

Threads

666

Posts

4131

Credits

Administrator

Rank: 9Rank: 9Rank: 9

Credits
4131
Post time 2016-11-2 10:42:04 | Show all posts
Hi friend, thanks for your share!

10

Threads

221

Posts

2040

Credits

Gold member

Rank: 6Rank: 6

Credits
2040
Post time 2016-11-2 17:39:07 | Show all posts
LinkNode D1 is really similar to WeMos D1 R2.
There are other boards of the same concept as LinkNode D1.
WeMos Mini
WeMos D1 R2
NodeMCU(AMICA)
NodeMCU(LoLin)
The same sketch work by all boards.

4

Threads

33

Posts

139

Credits

Registered member

Rank: 2

Credits
139
Post time 2020-11-11 16:48:05 | Show all posts
Thank you for this information right there. You know, I really want to talk with you about this website  https://qawerk.com/process/cloud-testing/ as they have already helped me with cloud testing once and I just thought that it can be also useful for you as well so go there and check the information there.
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2021-3-7 10:21 GMT+8 , Processed in 0.031468 second(s), 22 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list