summaryrefslogtreecommitdiff
path: root/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino
diff options
context:
space:
mode:
authorEbus-at-dockstar <ebus@dockstar>2014-07-26 19:55:43 +0200
committerEbus-at-dockstar <ebus@dockstar>2014-07-26 19:55:43 +0200
commita8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb (patch)
tree524672c3237be2552379f9d752184bd3cbf1d554 /datasources/arduino/arduinoAnalogHTTP/analogethernet.ino
parent3f5b5ff5e71cf078c2c04906bffa06f3a1050085 (diff)
downloadebus-alt-a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb.tar.gz
ebus-alt-a8cd2ecf7387d7bbe16808ca0c7acdb04a4909cb.zip
Revert "embed xexpr-path" restore datastore-leveldb and other stuff
This reverts commit f6675ccdd7a5997def3c4656f0e2c5dbbbed1fc8.
Diffstat (limited to 'datasources/arduino/arduinoAnalogHTTP/analogethernet.ino')
-rwxr-xr-xdatasources/arduino/arduinoAnalogHTTP/analogethernet.ino99
1 files changed, 99 insertions, 0 deletions
diff --git a/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino b/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino
new file mode 100755
index 0000000..5a0b241
--- /dev/null
+++ b/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino
@@ -0,0 +1,99 @@
+// vim: filetype=cpp
+#include <SPI.h>
+#include <Ethernet.h>
+
+byte mac[] = { 0x02, 0xEE, 0x00, 0xEF, 0xFE, 0xED };
+const int ledPin = 13; // select the pin for the LED
+
+const long ADC_REF_MV = 3300;
+const long ADC_MAX_STEP = 1024;
+const long OV_FACTOR = 4; // Op. Verstärker Faktor = 4; 10mV = 1dB
+
+EthernetClient client;
+
+void sendKeyValue(const char *key, const char *value) {
+ char hdrbuf[512];
+ snprintf(hdrbuf, 512, "Content-Length: %d\r\n", strlen(value));
+
+ if ( ! client.connect("10.1.0.1", 8080)) {
+ Serial.println("Failed to connect");
+ delay(500);
+ return;
+ }
+ Serial.print("Send ");
+ Serial.print(key);
+ Serial.print("=");
+ Serial.println(value);
+
+ client.write("PUT /api/value/");
+ client.write(key);
+ client.write(" HTTP/1.1\r\n");
+ client.write(hdrbuf);
+ client.write("\r\n");
+ client.write(value);
+
+ client.stop();
+}
+
+void sendPinValue() {
+ long sensorValue,
+ sensorValueMV,
+ sensorValueDBA,
+ pinnr;
+ char buf[12];
+ char *sensorKey = "arduino.aX",
+ *sensorKeyMV = "arduino.aX.mv",
+ *sensorKeyDBA = "arduino.aX.dba";
+ for (int i = A0; i <= A5; i++) {
+ pinnr = i - A0;
+
+ sensorValue = analogRead(i);
+ sensorKey[9] = '0' + pinnr;
+ snprintf(buf, 8, "%u", sensorValue);
+ sendKeyValue(sensorKey, buf);
+
+ sensorValueMV = sensorValue * (ADC_REF_MV*100/ADC_MAX_STEP);
+ sensorKeyMV[9] = '0' + pinnr;
+ snprintf(buf, 8, "%ld.%03ld", sensorValueMV/100, sensorValue%100);
+ sendKeyValue(sensorKeyMV, buf);
+
+ sensorValueDBA = sensorValueMV / OV_FACTOR;
+ sensorKeyDBA[9] = '0' + pinnr;
+ snprintf(buf, 12, "%ld.%04ld", sensorValueDBA/1000, sensorValueDBA%1000);
+ sendKeyValue(sensorKeyDBA, buf);
+ }
+}
+
+
+void setup() {
+ Serial.begin(9600);
+ Serial.println("Begin init");
+
+ // declare the ledPin as an OUTPUT:
+ pinMode(ledPin, OUTPUT);
+
+ // start the Ethernet and UDP: Use DHCP for IP-Configuration
+ Ethernet.begin(mac);
+ Serial.println("Ethernet init done");
+
+ analogReference(EXTERNAL);
+ delay(1000);
+ Serial.println("Start loop()");
+}
+
+
+
+char buf[512];
+
+void loop() {
+ unsigned long dt = millis();
+ digitalWrite(ledPin, HIGH);
+
+ sendPinValue();
+
+ digitalWrite(ledPin, LOW);
+
+ dt = (millis() - dt);
+ if (dt < 1000) delay(1000 - dt);
+}
+