Created
August 16, 2017 04:30
-
-
Save wildan3105/26822f64a67bf9c3e5d289d3b0ee48fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Ethernet.h> | |
#include <SPI.h> | |
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS | |
EthernetClient client; | |
long previousMillis = 0; | |
unsigned long currentMillis = 0; | |
long interval = 3000; // READING INTERVAL | |
float p = 0.00; | |
String data; | |
void setup() { | |
Serial.begin(9600); | |
if (Ethernet.begin(mac) == 0) { | |
Serial.println("Failed to configure Ethernet using DHCP"); | |
} | |
delay(10000); // GIVE THE SENSOR SOME TIME TO START | |
} | |
void loop(){ | |
currentMillis = millis(); | |
if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL | |
previousMillis = currentMillis; | |
p = (float) analogRead(A0) * (5.0 / 1023.0); // CONVERT TO ARDUINO READABLE VALUE; | |
p = (float) -7.58 * p + 27.309; // CALIBRATION RESULT | |
} | |
data = "potentio="; | |
data = data + p; | |
if (client.connect("167.205.43.205",3500)) { // REPLACE WITH YOUR SERVER ADDRESS | |
client.println("POST /results HTTP/1.1"); // HTTP POST TO /results | |
client.println("Host: 167.205.43.205:3500"); // SERVER ADDRESS HERE TOO | |
client.println("Content-Type: application/x-www-form-urlencoded"); // DATA TYPE | |
client.print("Content-Length: "); | |
client.println(data.length()); | |
client.println(); | |
client.print(data); | |
} | |
if (client.connected()) { | |
client.stop(); // DISCONNECT FROM THE SERVER | |
} | |
delay(5000); // 5 SECONDS DELAY | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment