Difference between revisions of "LinkNode D1"

From LinkSprite Playgound
Jump to: navigation, search
(d. Download binary tools (you need Python 2.7))
m (Schematic)
 
(26 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
Thanks for the contribution from open source community who have developed Arduino core for ESP8266, this let Aduino IDE program LinkNode D1 without any change. At the same time, LinkNode D1 has Arduino-compatible pin out which make it very easy to connect to Arduino shield.
 
Thanks for the contribution from open source community who have developed Arduino core for ESP8266, this let Aduino IDE program LinkNode D1 without any change. At the same time, LinkNode D1 has Arduino-compatible pin out which make it very easy to connect to Arduino shield.
  
[[File:1-108.png]]
+
[[File:LinkNode D1 A-4.jpg|600px]]
 +
 
 +
[[File:LinkNode D1 A-6.jpg|600px]]
 +
 
 +
[[File:LinkNode D1 A-7.jpg|600px]]
 +
 
 +
[[File:LinkNode D1 A-8.jpg|600px]]
 +
 
 +
[[File:LinkNode D1 A-9.jpg|600px]]
 +
 
 +
[[File:LinkNode D1 A-10.jpg|600px]]
 +
 
 +
[[File:LinkNode D1 A-11.jpg|600px]]
  
 
== Features ==
 
== Features ==
Line 35: Line 47:
 
* The [https://github.com/pcduino/LinkNodeD1 Arduino core] for LinkNode D1
 
* The [https://github.com/pcduino/LinkNodeD1 Arduino core] for LinkNode D1
  
==== b. Manually install hardware package(Option 1) ====
+
==== b. Install hardware package for LinkNode D1 ====
 
 
* Install Arduino IDE
 
* Manually download hardware package from [https://github.com/pcduino/LinkNodeD1 github]
 
* Click the button '''Download ZIP''' to download
 
* Go to installation directory of Arduino IDE, and create a '''esp8266com''' directory
 
* Move the unzipped LinkNodeD1 file to '''ESP8266com'''
 
  
==== c. Use git to install (Option 2) ====
 
  
* You can use git command to download the hardware package like:  
+
*Install Arduino 1.6.8 from the [http://www.arduino.cc/en/main/software Arduino website].
  cd <ArduinoIDE path>/hardware
+
*Start Arduino and go to File --> Preferences .
  mkdir esp8266com
+
*Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas.
  cd esp8266com
 
  git clone https://github.com/pcduino/LinkNodeD1
 
  
==== d. Download binary tools (you need Python 2.7) ====
+
[[File:1-175.png]]
  cd esp8266/tools
 
  python get.py
 
  
==== e. Check the configuration of Board ====
+
*Open Boards Manager from Tools --> Board menu --> Boards Manager.  
  
* Open Arduino IDE and go to '''Tools --> Board --> LinkNode D1'''
+
[[File:1-176.png]]
* Choose your own configuration
 
  
'''Upload Using''' * Serial – Use USB port on board to upload flash * OTA – Use OTA to upload flash
+
*Search and install esp8266 platform (and don't forget to select your ESP8266 board from Tools --> Board menu after installation).
  
'''CPU Frequency''' * 80MHz * 160MHz
+
[[File:1-177.png]]
  
'''Flash Size''' * 4M (3M SPIFFS) – 3M File system size * 4M (1M SPIFFS) – 1M File system size
+
c. Check the configuration of Board
  
'''Upload Speed''' * '''921600 bps''' – recommend
+
Because the LinkNode D1 has not been added into the offcial ESP8266 Arduino core repository yet, so you can't find LinkNode D1 board on the boards list, but you can use the WeMos D1(Retired), this board is fully compotiable with LinkNode D1.
  
==== f. Create a Arduino Project ====
+
[[File:1-178.png]]
  
* Connect LinkNode D1 to your PC
+
d. Create a Arduino Project
* Check your serial port which your PC recognize
 
  
[[File:1-107.png]]
+
*Connect LinkNode D1 to your PC
 
+
*Check your serial port which your PC recognize
* Enter the following source code and click the '''Upload''' button
+
*Enter the following source code and click the Upload button
  
 
   void setup() {
 
   void setup() {
    // initialize digital pin GPIO2/D9 as an output.
+
  // initialize digital pin GPIO2/D9 as an output.
    pinMode(BUILTIN_LED, OUTPUT);
+
  pinMode(BUILTIN_LED, OUTPUT);
 
   }
 
   }
 
 
   // the loop function runs over and over again forever
 
   // the loop function runs over and over again forever
 
   void loop() {
 
   void loop() {
    digitalWrite(BUILTIN_LED, HIGH);  // turn the LED on (HIGH is the voltage level)
+
  digitalWrite(BUILTIN_LED, HIGH);  // turn the LED on (HIGH is the voltage level)
    delay(1000);              // wait for a second
+
  delay(1000);              // wait for a second
    digitalWrite(BUILTIN_LED, LOW);    // turn the LED off by making the voltage LOW
+
  digitalWrite(BUILTIN_LED, LOW);    // turn the LED off by making the voltage LOW
    delay(1000);              // wait for a second
+
  delay(1000);              // wait for a second
 
   }
 
   }
* After finish uploading, please check the BLUE LED on the ESP-8266EX chip, is it blinking?
+
 
 +
*After finish uploading, please check the BLUE LED on the ESP-8266EX chip, is it blinking?
  
 
=== 2. Hello World ===
 
=== 2. Hello World ===
  
* Take the steps above and run the following code:
+
* Take the steps above and run the following code :
  
```c void setup() { Serial.begin(115200); }
+
  void setup() {
 +
    Serial.begin(115200);
 +
  }
 +
  // the loop function runs over and over again forever
 +
  void loop() {
 +
    Serial.println("Hello world!");
 +
    delay(1000);              // wait for a second
 +
  }
  
// the loop function runs over and over again forever void loop() { Serial.println("Hello world!"); delay(1000); // wait for a second } ``` * After finish uploading, and open the '''Serial Monitor''' in Arduino IDE * The serial will print '''Hello world!''' in every second.
+
* After finish uploading, and open the '''Serial Monitor''' in Arduino IDE  
 +
* The serial will print '''Hello world!''' in every second.
  
 
=== 3. Use I/O expander shield with LinkNode D1 ===
 
=== 3. Use I/O expander shield with LinkNode D1 ===
  
[[Image:../images/io.png|frame|none]]
+
[[File:1-110.png]]
  
 
I/O Expander shield is a shield used to expand the number of I/Os of Arduino. It is based on the chipset MCP23017. The chipset MCP23017 communicates with Arduino Uno through I2C interface. It adds GPIOA and GPIOB, a total of 16 I/Os.
 
I/O Expander shield is a shield used to expand the number of I/Os of Arduino. It is based on the chipset MCP23017. The chipset MCP23017 communicates with Arduino Uno through I2C interface. It adds GPIOA and GPIOB, a total of 16 I/Os.
Line 108: Line 115:
 
* Program the source code to the board
 
* Program the source code to the board
  
```C #include <Wire.h>
+
  #include <Wire.h>
 
+
  const byte mcp_address=0x20;     // I2C Address of MCP23017 Chip
const byte mcp_address=0x20; // I2C Address of MCP23017 Chip const byte GPIOA=0x12; // Register Address of Port A const byte GPIOB=0x13; // Register Address of Port B const byte IODIRA=0x00; // IODIRA register const byte IODIRB=0x01; // IODIRB register
+
  const byte GPIOA=0x12;           // Register Address of Port A
 
+
  const byte GPIOB=0x13;           // Register Address of Port B
void setup() { //Send settings to MCP device Wire.begin(); // join i2c bus (address optional for master) Wire.beginTransmission(mcp_address); Wire.write((byte)IODIRA); // IODIRA register Wire.write((byte)0x03); // set GPIOA-0/GPIOA-1 to inputs Wire.endTransmission(); }
+
  const byte IODIRA=0x00;           // IODIRA register
 
+
  const byte IODIRB=0x01;           // IODIRB register
void loop() { Wire.beginTransmission(mcp_address); Wire.write((byte)GPIOA); // set MCP23017 memory pointer to GPIOB address Wire.endTransmission(); Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317 int inputs=Wire.read(); // store the incoming byte into "inputs"
+
  void setup()
 +
  {
 +
    //Send settings to MCP device
 +
    Wire.begin();             // join i2c bus (address optional for master)
 +
    Wire.beginTransmission(mcp_address);
 +
    Wire.write((byte)IODIRA); // IODIRA register
 +
    Wire.write((byte)0x03); // set GPIOA-0/GPIOA-1 to inputs
 +
    Wire.endTransmission();
 +
  }
 +
  void loop()
 +
  {
 +
    Wire.beginTransmission(mcp_address);
 +
    Wire.write((byte)GPIOA); // set MCP23017 memory pointer to GPIOB address
 +
    Wire.endTransmission();
 +
    Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317
 +
    int inputs=Wire.read(); // store the incoming byte into "inputs"
 +
    if((inputs&0x01)==0)
 +
    {
 +
      Wire.beginTransmission(mcp_address);
 +
      Wire.write(GPIOA);    // address bank A
 +
      Wire.write((byte)0x04);  // value to send GPIOA-2 HIGH
 +
      Wire.endTransmission();
 +
    }
 +
    if((inputs&0x02)==0)
 +
    {
 +
      Wire.beginTransmission(mcp_address);
 +
      Wire.write(GPIOA);    // address bank A
 +
      Wire.write((byte)0x08);  // value to send GPIOA-3 HIGH
 +
      Wire.endTransmission();
 +
    }
 +
    else
 +
    {
 +
      Wire.beginTransmission(mcp_address);
 +
      Wire.write(GPIOA);    // address bank A
 +
      Wire.write((byte)0x00);  // value to send GPIOA LOW
 +
      Wire.endTransmission();
 +
    }
 +
  }
  
if((inputs&0x01)==0) { Wire.beginTransmission(mcp_address); Wire.write(GPIOA); // address bank A Wire.write((byte)0x04); // value to send GPIOA-2 HIGH Wire.endTransmission(); } if((inputs&0x02)==0) { Wire.beginTransmission(mcp_address); Wire.write(GPIOA); // address bank A Wire.write((byte)0x08); // value to send GPIOA-3 HIGH Wire.endTransmission(); } else { Wire.beginTransmission(mcp_address); Wire.write(GPIOA); // address bank A Wire.write((byte)0x00); // value to send GPIOA LOW Wire.endTransmission(); } } ``` * Set all 4-bit DIP jumpers to ON * Press the button S1 and S2 respectively. * Press S1, L1 (RED) will turn on. * Press S2, L2 (GREEN) will turn on.
+
* Set all 4-bit DIP jumpers to ON  
 +
* Press the button S1 and S2 respectively.
 +
* Press S1, L1 (RED) will turn on.  
 +
* Press S2, L2 (GREEN) will turn on.
  
 
=== 4. WiFi Manager ===
 
=== 4. WiFi Manager ===
Line 125: Line 172:
 
* Search the '''wifimanager''' and install it
 
* Search the '''wifimanager''' and install it
  
[[Image:../images/wifimanager.png|frame|none]]
+
[[File:1-111.png|600px]]
  
 
* Program the following source code:
 
* Program the following source code:
Line 169: Line 216:
 
* Open a browser and enter the ip address '''10.0.1.1''' and you will see the following website:
 
* Open a browser and enter the ip address '''10.0.1.1''' and you will see the following website:
  
<img src="../images/linknodeap.jpg" width=200> * 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. * Also, you can use Serial Monitor in Arduino IDE to check the status.
+
[[File:1-112.jpg|300px]]
 +
 
 +
* 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.  
 +
* Also, you can use Serial Monitor in Arduino IDE to check the status.
  
 
=== 5. Connect to LinkSprite IO ===
 
=== 5. Connect to LinkSprite IO ===
Line 181: Line 233:
 
* Go to '''My Account''' to get your own API Key. The API Key is fatal because only add the Key in your codes, can the data sync to your IoTgo account.
 
* Go to '''My Account''' to get your own API Key. The API Key is fatal because only add the Key in your codes, can the data sync to your IoTgo account.
  
<img src="../images/apikey.png" width="600">
+
[[File:1-113.png|300px]]
 
* Click '''My Device''', and choose '''Create DIY Device'''.
 
* Click '''My Device''', and choose '''Create DIY Device'''.
  
<img src="../images/newdevice.png" title="IoTgo" width="300">
+
[[File:1-114.png]]
 
* Click the created device icon and get the DeviceID.
 
* Click the created device icon and get the DeviceID.
  
<img src="../images/deviceid.png" title="IoTgo" width="300">
+
[[File:1-115.png|300px]]
 +
 
 
==== b. Update the source code using your own apikey and device ID ====
 
==== b. Update the source code using your own apikey and device ID ====
  
Device API which the LinkSprite IO support is JSON-based, which means all request and response data is enclosed in JSON format. Currently it supports 3 kind of request. * '''Update''': Update device status to LinkSprite IO * '''Query''': Get device status from LinkSprite IO
+
Device API which the LinkSprite IO support is JSON-based, which means all request and response data is enclosed in JSON format. Currently it supports 3 kind of request.  
 +
* '''Update''': Update device status to LinkSprite IO  
 +
* '''Query''': Get device status from LinkSprite IO
  
 
This demo will send http POST request to query the param--light on linksprite.io, if the '''light''' is on, then turn the LED, if off, then turn off the LED.
 
This demo will send http POST request to query the param--light on linksprite.io, if the '''light''' is on, then turn the LED, if off, then turn off the LED.
  
```c #include <ESP8266WiFi.h> #include <WString.h>
+
  #include <ESP8266WiFi.h>
 
+
  #include <WString.h>
//the library are needed for autoconfig WiFi #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h>
+
  //the library are needed for autoconfig WiFi
 
+
  #include <DNSServer.h>
// replace with your own API key and device ID, String apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; const char* deviceID="xxxxxxxxxxxxx";
+
  #include <ESP8266WebServer.h>
 
+
  #include <WiFiManager.h>      
const char* server = "www.linksprite.io";
+
  // replace with your own API key and device ID,
 
+
  String apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
WiFiClient client;
+
  const char* deviceID="xxxxxxxxxxxxx";
 
+
  const char* server = "www.linksprite.io";
void setup() {<br />
+
  WiFiClient client;
Serial.begin(115200); pinMode(BUILTIN_LED, OUTPUT);
+
  void setup() {              
 
+
    Serial.begin(115200);
WiFiManager wifiManager;
+
    pinMode(BUILTIN_LED, OUTPUT);
 
+
    WiFiManager wifiManager;
wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); wifiManager.autoConnect("LinkNodeAP");
+
    wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
 
+
    wifiManager.autoConnect("LinkNodeAP");
Serial.print("WiFi Connected ..."); Serial.println("WiFi connected"); }
+
    Serial.print("WiFi Connected ...\n");
 
+
    Serial.println("WiFi connected");
void loop() {
+
  }
 
+
  void loop() {
if (client.connect(server,80)) {<br />
+
    if (client.connect(server,80)) {
  String postStr ="{"; postStr +=""action":"query","; postStr +=""apikey":""; postStr += apikey; postStr +="","; postStr +=""deviceid":""; postStr += deviceID; postStr +="","; postStr += ""params":"; postStr += "["; postStr += ""light""; postStr +="]"; postStr +="}";
+
    String postStr ="{";
 +
          postStr +="\"action\":\"query\",";
 +
          postStr +="\"apikey\":\"";
 +
          postStr += apikey;
 +
          postStr +="\",";
 +
          postStr +="\"deviceid\":\"";
 +
          postStr += deviceID;
 +
          postStr +="\",";
 +
          postStr += "\"params\":";
 +
          postStr += "[";
 +
          postStr += "\"light\"";
 +
          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);   
 +
  }
 +
  delay(1000);
 +
  Serial.println("Store response...");
 +
  String request = "";
 +
  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);
 +
    Serial.print("The param is ");
 +
    Serial.println(param);
 +
    if(param.indexOf("off")>0){
 +
        digitalWrite(BUILTIN_LED, HIGH);   
 +
        Serial.println("OFF");
 +
    } else if(param.indexOf("on")>0){
 +
        digitalWrite(BUILTIN_LED, LOW);   
 +
        Serial.println("ON");
 +
    }
 +
  client.stop();
 +
  Serial.println("Waiting...");   
 +
  delay(2000); 
 +
  }
 +
}
  
<pre> 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);    </pre>
 
} delay(1000);
 
  
Serial.println("Store response..."); String request = ""; while (client.available()) { char c = client.read(); request +=c; }
+
``` #### c. Test
 +
* Program the source code and open the Serial monitor to check the status
  
if (request!= NULL) { int index1 = request.indexOf(":{"); int index2 = request.indexOf("},"); String param = request.substring(index1, index2 + 1); Serial.print("The param is "); Serial.println(param);
+
[[File:1-116.png|300px]]
 +
* Open your light device which is create on linksprite.io
 +
* Click the button '''ON''' and '''OFF'''
 +
* Check the status of LED on LinkNode D1, is it following your control?
  
<pre>if(param.indexOf("off")>0){
 
    digitalWrite(BUILTIN_LED, HIGH);   
 
    Serial.println("OFF");
 
} else if(param.indexOf("on")>0){
 
    digitalWrite(BUILTIN_LED, LOW);   
 
    Serial.println("ON");
 
}</pre>
 
client.stop(); Serial.println("Waiting...");<br />
 
delay(2000);<br />
 
} }
 
  
``` #### c. Test * Program the source code and open the Serial monitor to check the status
+
== Schematic ==
 +
[https://s3.amazonaws.com/linksprite/Linknode+D1/LinkNode-D1-sch.pdf Schematic]
  
<img src="../images/deviceid.png" title="IoTgo" width="300"> * Open your light device which is create on linksprite.io * Click the button '''ON''' and '''OFF''' * Check the status of LED on LinkNode D1, is it following your control?
+
[http://learn.linksprite.com/linksprite-io/making-linksprite-linknode-d1-as-micropython-node-pyboard-now-with-nodemcu-v1-0-esp-12e/ Making LinkSprite LinkNode D1 as MicroPython node, pyboard ==> Now with NodeMCU v1.0 (ESP-12E)]

Latest revision as of 10:50, 19 February 2019

LinkNode D1

Introduction

LinkNode D1 is Arduino-compatible WiFi development board which is powered by the high integrated WiFi chip ESP-8266EX.

Thanks for the contribution from open source community who have developed Arduino core for ESP8266, this let Aduino IDE program LinkNode D1 without any change. At the same time, LinkNode D1 has Arduino-compatible pin out which make it very easy to connect to Arduino shield.

LinkNode D1 A-4.jpg

LinkNode D1 A-6.jpg

LinkNode D1 A-7.jpg

LinkNode D1 A-8.jpg

LinkNode D1 A-9.jpg

LinkNode D1 A-10.jpg

LinkNode D1 A-11.jpg

Features

  • Powered by ESP-8266EX
  • 11 Digital I/O pins
  • 1 Analog Input pin
  • 1 micro USB port for power/configure
  • Power jack for 9-24V power input
  • Compatible with Arduino programming
  • Compatible with NodeMCU
  • OTA -- Wireless Upload(Program)

Pin Mapping

1-109.jpg

Tutorials

1. Get started in Arduino

If you have used Arduino before, you will feel that the LinkNode D1 is as same as Arduino, and there is no difference between their programming. The only limitation of LinkNode D1 is that it only has 11 digital ports and 1 analog input port.

a. Requirements

b. Install hardware package for LinkNode D1

1-175.png

  • Open Boards Manager from Tools --> Board menu --> Boards Manager.

1-176.png

  • Search and install esp8266 platform (and don't forget to select your ESP8266 board from Tools --> Board menu after installation).

1-177.png

c. Check the configuration of Board

Because the LinkNode D1 has not been added into the offcial ESP8266 Arduino core repository yet, so you can't find LinkNode D1 board on the boards list, but you can use the WeMos D1(Retired), this board is fully compotiable with LinkNode D1.

1-178.png

d. Create a Arduino Project

  • Connect LinkNode D1 to your PC
  • Check your serial port which your PC recognize
  • Enter the following source code and click the Upload button
 void setup() {
 // initialize digital pin GPIO2/D9 as an output.
 pinMode(BUILTIN_LED, OUTPUT);
 }
 // the loop function runs over and over again forever
 void loop() {
 digitalWrite(BUILTIN_LED, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(1000);              // wait for a second
 digitalWrite(BUILTIN_LED, LOW);    // turn the LED off by making the voltage LOW
 delay(1000);              // wait for a second
 }
  • After finish uploading, please check the BLUE LED on the ESP-8266EX chip, is it blinking?

2. Hello World

  • Take the steps above and run the following code :
 void setup() {
   Serial.begin(115200);
 }
 // the loop function runs over and over again forever
 void loop() {
   Serial.println("Hello world!");
   delay(1000);              // wait for a second
 }
  • After finish uploading, and open the Serial Monitor in Arduino IDE
  • The serial will print Hello world! in every second.

3. Use I/O expander shield with LinkNode D1

1-110.png

I/O Expander shield is a shield used to expand the number of I/Os of Arduino. It is based on the chipset MCP23017. The chipset MCP23017 communicates with Arduino Uno through I2C interface. It adds GPIOA and GPIOB, a total of 16 I/Os.

  • Mount the expander shield to LinkNode D1
  • Program the source code to the board
 #include <Wire.h>
 const byte  mcp_address=0x20;      // I2C Address of MCP23017 Chip
 const byte  GPIOA=0x12;            // Register Address of Port A
 const byte  GPIOB=0x13;            // Register Address of Port B
 const byte  IODIRA=0x00;            // IODIRA register
 const byte  IODIRB=0x01;            // IODIRB register
 void setup()
 {
   //Send settings to MCP device
   Wire.begin();              // join i2c bus (address optional for master)
   Wire.beginTransmission(mcp_address);
   Wire.write((byte)IODIRA); // IODIRA register
   Wire.write((byte)0x03); // set GPIOA-0/GPIOA-1 to inputs
   Wire.endTransmission();
 }
 void loop()
 {
   Wire.beginTransmission(mcp_address);
   Wire.write((byte)GPIOA); // set MCP23017 memory pointer to GPIOB address
   Wire.endTransmission();
   Wire.requestFrom(0x20, 1); // request one byte of data from MCP20317
   int inputs=Wire.read(); // store the incoming byte into "inputs"
   if((inputs&0x01)==0)
   {
     Wire.beginTransmission(mcp_address);
     Wire.write(GPIOA);    // address bank A
     Wire.write((byte)0x04);  // value to send GPIOA-2 HIGH
     Wire.endTransmission();
   }
   if((inputs&0x02)==0)
   {
     Wire.beginTransmission(mcp_address);
     Wire.write(GPIOA);    // address bank A
     Wire.write((byte)0x08);  // value to send GPIOA-3 HIGH
     Wire.endTransmission();
   }
   else
   {
     Wire.beginTransmission(mcp_address);
     Wire.write(GPIOA);     // address bank A
     Wire.write((byte)0x00);  // value to send GPIOA LOW
     Wire.endTransmission();
   }
 }
  • Set all 4-bit DIP jumpers to ON
  • Press the button S1 and S2 respectively.
  • Press S1, L1 (RED) will turn on.
  • Press S2, L2 (GREEN) will turn on.

4. WiFi Manager

The ESP8266 WiFi Connection manager with web captive portal, this Arduino library can make configure AP's SSID and password via web page when you want LinkNode D1 to connect to AP.

  • Open Arduino IDE and go to Sketch --> Include Library --> Manage Libraries
  • Search the wifimanager and install it

1-111.png

  • Program the following source code:

<source lang="c">#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino

//needed for library

  1. include <DNSServer.h>
  2. include <ESP8266WebServer.h>
  3. include <WiFiManager.h> //https://github.com/tzapu/WiFiManager


void setup() {

   // put your setup code here, to run once:
   Serial.begin(115200);
   //WiFiManager
   //Local intialization. Once its business is done, there is no need to keep it around
   WiFiManager wifiManager;
   //reset saved settings
   //wifiManager.resetSettings();
   //set custom ip for portal
   wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));
   //fetches ssid and pass from eeprom and tries to connect
   //if it does not connect it starts an access point with the specified name
   //here  "AutoConnectAP"
   //and goes into a blocking loop awaiting configuration
   wifiManager.autoConnect("LinkNodeAP");
   //or use this for auto generated name ESP + ChipID
   //wifiManager.autoConnect();
   //if you get here you have connected to the WiFi
   Serial.println("connected... :)");

}

void loop() {

   // put your main code here, to run repeatedly:

}</source>

  • After upload the program, the LinkNode D1 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:

1-112.jpg

  • 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.
  • Also, you can use Serial Monitor in Arduino IDE to check the status.

5. Connect to LinkSprite IO

LinkSprite IO is an IoT platform which supports RESTful API and WebSocket. These make the mobile APP, website application or device connect it very easily. The following I will introduce is about how to use LinkNode D1 to communicate with LinkSprite IO platform.

a. Create a new account and device on LinkSprite.io

  • Go to www.linksprite.io and sign up
  • Enter your Email and password to create a new account
  • Go to My Account to get your own API Key. The API Key is fatal because only add the Key in your codes, can the data sync to your IoTgo account.

1-113.png

  • Click My Device, and choose Create DIY Device.

1-114.png

  • Click the created device icon and get the DeviceID.

1-115.png

b. Update the source code using your own apikey and device ID

Device API which the LinkSprite IO support is JSON-based, which means all request and response data is enclosed in JSON format. Currently it supports 3 kind of request.

  • Update: Update device status to LinkSprite IO
  • Query: Get device status from LinkSprite IO

This demo will send http POST request to query the param--light on linksprite.io, if the light is on, then turn the LED, if off, then turn off the LED.

 #include <ESP8266WiFi.h>
 #include <WString.h>
 //the library are needed for autoconfig WiFi
 #include <DNSServer.h>
 #include <ESP8266WebServer.h>
 #include <WiFiManager.h>       
 // replace with your own API key and device ID,
 String apikey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 const char* deviceID="xxxxxxxxxxxxx";
 const char* server = "www.linksprite.io";
 WiFiClient client;
 void setup() {                
   Serial.begin(115200);
   pinMode(BUILTIN_LED, OUTPUT);
   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");
 }
 void loop() {
   if (client.connect(server,80)) {  
   String  postStr ="{";
         postStr +="\"action\":\"query\",";
         postStr +="\"apikey\":\"";
         postStr += apikey;
         postStr +="\",";
         postStr +="\"deviceid\":\"";
         postStr += deviceID;
         postStr +="\",";
         postStr += "\"params\":";
         postStr += "[";
         postStr += "\"light\"";
         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);     
 }
 delay(1000);
 Serial.println("Store response...");
 String request = "";
 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);
   Serial.print("The param is ");
   Serial.println(param);
   if(param.indexOf("off")>0){
       digitalWrite(BUILTIN_LED, HIGH);    
       Serial.println("OFF");
   } else if(param.indexOf("on")>0){
       digitalWrite(BUILTIN_LED, LOW);    
       Serial.println("ON");
   }
 client.stop();
 Serial.println("Waiting...");    
 delay(2000);  
 }
}


``` #### c. Test

  • Program the source code and open the Serial monitor to check the status

1-116.png

  • Open your light device which is create on linksprite.io
  • Click the button ON and OFF
  • Check the status of LED on LinkNode D1, is it following your control?


Schematic

Schematic

Making LinkSprite LinkNode D1 as MicroPython node, pyboard ==> Now with NodeMCU v1.0 (ESP-12E)