diff options
Diffstat (limited to 'datasources/arduino/arduinoAnalogHTTP/analogethernet.ino')
-rwxr-xr-x | datasources/arduino/arduinoAnalogHTTP/analogethernet.ino | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino b/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino deleted file mode 100755 index 5a0b241..0000000 --- a/datasources/arduino/arduinoAnalogHTTP/analogethernet.ino +++ /dev/null @@ -1,99 +0,0 @@ -// 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); -} - |