Skip navigation

Arduino

3 Posts authored by: alvin_jin

11

Material preparation

  • LinkNode D1 x 1
  • Arduino IDE

Step

1. Login  linksprite.io ,and record the “Device ID” and “API key”

 

  • 3. My device->Create DIY Device

1-1

Enter Device Name,Device Type , Group Name , the device number is 00, device name and device grouping can be any.Note: Device Type must be selected 00(Custom device type) .Now you can see “test” in My Devices, Click “test” and record the Device ID.

2-1

2. Download and run the code

  • 1. Download the source files
git clone https://github.com/delongqilinksprite/LinkSpriteIO.git
  • 2. Put the code in the following directory(examples under Arduino installation directory )

QQ截图20160722144648

  • 3. Open the Arduino IDE, File -> Example -> LinkSpriteIO-> LinkSpriteIO.ino
  • 4. Modify the “deviceID” and “apikey” with your own

1

  • 5. Configure LinkNode D1 Engineering Environment

5-1

  • 6. compile and run the code

Results

Here we can see communication of LinkNode D1 and linksprite.io.

Note:

The first use of LinkNode D1 need to connect the WiFi, the specific operation, please refer to the linksprite wiki Tutorial 4 .

61

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);  
  } 
}
  
}

LinkNode R4 is an open source 4-Channel relay controller which is powered by the ESP8266 WiFi SoC.

linspriteio5-300x226.jpg

The following will introduce how to use Android APP to control the LinkNode R4.

Steps

1. Install Android APP

  • Download the APK file from the github and install it.

2. Login LinkSpriteIO

  • If you never register an account on LinkSpriteIO, please enter Email and your password, then click the SIGN IN button
  • If you have an account on LinkSpriteIO, please enter Email and your password, then click the REGISTER button

3. Go to Relay device list

  • Click the plus icon on the upper right quarter to add a new LinkNode R4.

4. Scan the QRcode

  • Get the device information and register it to your account.

5. Configure to accece WiFi AP

  • Supply the power for LinkNodeR4, the LinkNode R4 will create a AP called LinkNodeAP
  • Use your mobile phone to connect this AP
  • Open a browser and enter the ip address 10.0.1.1 and you will see the following website:

  • Click the button configure WiFi
  • Select your WiFi AP which you want to connect and enter your wifi password.
  • If connecting failed, you can go to the same website to configure it again.
  • After that, LinkNode R4 will connect to Linksprite IO via the internet.

6. Control your 4-channel relay

  • control the button on the right side to turn on or off the relays, and you can click the relay’s name to change it.

 

for more details ,please refer to original post

https://github.com/delongqilinksprite/LinkNodeR4-app

Filter Blog

By date: By tag: