Load CDS sensor type values into DB by calling server API [P001]


 



 

https://www.youtube.com/watch?v=KGXxDDacQb4


*GitHubhttps://github.com/rdiot/rdiot-p001.git

 

* Contents

- API Call and Save the CDS Values to the API Server.

 

- Result
2391 S001       ArduinoUno   W5100         Ethernet     MiniPhotocell       2015-10-08 00:22:34 F01                  513 0~1023           
2392 S002       ArduinoUno   W5100         Ethernet     PhotoResistorModule 2015-10-08 00:22:36 F01                  343 0~1023           
2393 S003       ArduinoUno   W5100         Ethernet     CDS5MM               2015-10-08 00:22:37 F01                 829 0~1023           
2394 S004       ArduinoUno   W5100         Ethernet     CDS10MM             2015-10-08 00:22:38 F01                  702 0~1023           
2395 S005       ArduinoUno   W5100         Ethernet     CDS15MM             2015-10-08 00:22:39 F01                  957 0~1023           
2396 S006       ArduinoUno   W5100         Ethernet     CDS20MM             2015-10-08 00:22:41 F01                  959 0~1023           

 

- Key Code
#include <SPI.h>
#include <Ethernet.h>

/* --------------------------------------------------------------------
*  Ethernet Config
* -------------------------------------------------------------------*/
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 }; //MAC Address
char server[] = "54.65.30.222"; //API Server
String s_data1 = ""; // Request Data
int led_green = 6; // Connect LED ON
int led_red = 7; // DisConnect LED ON


EthernetClient client;

connect_server();

 s_data1 = "sensor_id=S001&";
 s_data1 += "sensor_board=ArduinoUno&";
 s_data1 += "sensor_shield=W5100&";
 s_data1 += "sensor_comm=Ethernet&";
 s_data1 += "sensor_name=MiniPhotocell&";
 s_data1 += "sensor_func=F01&";
 s_data1 += "sensor_value=" + (String)analogRead(A0) + "&";
 s_data1 += "sensor_value_desc=0~1023";
 Serial.println("S001-"+ (String)analogRead(A0));


if (client.connected())
 {
  Serial.println("c1");
  client.println("POST /iotHome-api/v1/sensor/post-form2xml-mysqldb HTTP/1.0");
  client.println("Host: 54.65.30.222");
  client.println("User-Agent: Arduino");
  client.println("Connection: close");
  client.println("Content-Type: application/x-www-form-urlencoded");
  client.print("Content-Length: ");
  client.println(s_data1.length());
  client.println();
  client.println(s_data1);

  digitalWrite(led_green, HIGH);
  delay(100);
  digitalWrite(led_green, LOW);
 }
 else
 {
  digitalWrite(led_red, HIGH);
  delay(1000);
  digitalWrite(led_red, LOW);
 }
 delay(1000);

Posted by RDIoT
|