[vc_row][vc_column][vc_column_text]
Ethernet Shield instantly enables internet connectivity for Arduino projects. An on-board Wiz5100 ethernet controller handles up to four TCP and UDP connections, just stack it onto an Arduino to create your own networked devices. Easily check connection status with on board indicator lights. Extend your design further with two extra rows of pin header that connect to shields and prototyping boards. Progressive development in the digital world has reached the home. Therefore more and more devices will have the basic ability to communicate with each other. Thus the degree of networking will reach a new level. In this project ,we will use Ethernet shield with Arduino to talk to yeelink server to achieve web remote control.
[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Parts List” tab_id=”1394686456-1-1″][vc_column_text]1. 1 x Arduino Uno
2. 1 x Ethernet Shield
3. 1 x 5mm LED
4. Jumper wires[/vc_column_text][/vc_tab][vc_tab title=”Register a yeelink account” tab_id=”1394686456-2-47″][vc_column_text][/vc_column_text][vc_column_text]First, go to the yeelink home page click sign up
After making registration, click Personal information
View your account information, remember our code back the APIKEY ,we will use it
Then click the “add a new device”
Then click “Manage Device” add a sensor
Click “add a Sensor”
After adding it , we can see state URL ***/deice/7931/sensor/12568/datapoints as shown in the below figure, 12568 is the sensor number, we will use it in the code, so you’d better write down the numbers.
[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1394688869573-2-2″][vc_column_text]1. Install Ethernet shield onto Arduion board
2.Plug in the Ethernet cable to Ethernet shield.
3. ” +” of ‘Led -> D7 of Arduino, “-” connected to GND through a resistor.[/vc_column_text][/vc_tab][vc_tab title=”Configure Port” tab_id=”1394688870892-3-2″][vc_column_text]Map a port to WAN”
Log into the router, then open: Port Settings -> DHCP settings.
Defined by the code to determine the MAC address of the Arduino IP.
Then configure arduino ip as a virtual host.
Click the Add button, the default is set to WEB and FTP (2 new), internal server IP is Arduino IP.
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1394688872843-4-4″][vc_column_text]
/* Yeelink sensor client power switch example */ #include <SPI.h> #include <Ethernet.h> #include <Wire.h> #include <math.h> byte buff[2]; // for yeelink api #define APIKEY “537ef1cef1b8726b39347abb8c0c809a” // replace your yeelink api key here #define DEVICEID 7931 // replace your device ID #define SENSORID 12568 // replace your sensor ID // assign a MAC address for the ethernet controller. byte mac[] = { 0×00, 0x1D, 0×72, 0×82, 0×35, 0x9D}; // initialize the library instance: EthernetClient client; char server[] = “api.yeelink.net”; // name address for yeelink API unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds boolean lastConnected = false; // state of the connection last time through the main loop const unsigned long postingInterval = 3*1000; // delay between 2 datapoints, 30s String returnValue = “”; boolean ResponseBegin = false; void setup() { pinMode(7, OUTPUT); Wire.begin(); // start serial port: Serial.begin(57600); // start the Ethernet connection with DHCP: if (Ethernet.begin(mac) == 0) { Serial.println(“Failed to configure Ethernet using DHCP”); for(;;) ; } else { Serial.println(“Ethernet configuration OK”); } } void loop() { // if there’s incoming data from the net connection. // send it out the serial port. This is for debugging // purposes only: if (client.available()) { char c = client.read(); // Serial.print(c); if (c == ‘{‘) ResponseBegin = true; else if (c == ‘}’) ResponseBegin = false; if (ResponseBegin) returnValue += c; } if (returnValue.length() !=0 && (ResponseBegin == false)) { Serial.println(returnValue); if (returnValue.charAt(returnValue.length() – 1) == ’1′) { Serial.println(“turn on the LED”); digitalWrite(7, HIGH); } else if(returnValue.charAt(returnValue.length() – 1) == ’0′) { Serial.println(“turn off the LED”); digitalWrite(7, LOW); } returnValue = “”; } // if there’s no net connection, but there was one last time // through the loop, then stop the client: if (!client.connected() && lastConnected) { Serial.println(); Serial.println(“disconnecting.”); client.stop(); } // if you’re not connected, and ten seconds have passed since // your last connection, then connect again and send data: if(!client.connected() && (millis() – lastConnectionTime > postingInterval)) { // read sensor data, replace with your code //int sensorReading = readLightSensor(); Serial.print(“yeelink:”); //get data from server getData(); } // store the state of the connection for next time through // the loop: lastConnected = client.connected(); } // this method makes a HTTP connection to the server and get data back void getData(void) { // if there’s a successful connection: if (client.connect(server, 80)) { Serial.println(“connecting…”); // send the HTTP GET request: client.print(“GET /v1.0/device/”); client.print(DEVICEID); client.print(“/sensor/”); client.print(SENSORID); client.print(“/datapoints”); client.println(” HTTP/1.1″); client.println(“Host: api.yeelink.net”); client.print(“Accept: *”); client.print(“/”); client.println(“*”); client.print(“U-ApiKey: “); client.println(APIKEY); client.println(“Content-Length: 0″); client.println(“Connection: close”); client.println(); Serial.println(“print get done.”); } else { // if you couldn’t make a connection: Serial.println(“connection failed”); Serial.println(); Serial.println(“disconnecting.”); client.stop(); } // note the time that the connection was made or attempted: lastConnectionTime = millis(); }
[/vc_column_text][/vc_tab][vc_tab title=”Results” tab_id=”1394688874105-5-5″][vc_column_text]When the analog LED on yeelink state is OFF , the LED on Arduino is OFF.
When yeelink LED is on , LED arduino is on.
Leave a Reply
You must be logged in to post a comment.