Hi,
i am doing this project on Home Sensing Station from Dummies's Arduino Projects. After i have finished everything stated there, it only shows the reading for light sensor on the serial monitor and it did not continue reading afterwards. What's worse is that it did not send the data to Xively. Here's the coding:
#include <b64.h> #include <HttpClient.h> #include <CountingStream.h> #include <Xively.h> #include <XivelyClient.h> #include <XivelyDatastream.h> #include <XivelyFeed.h> #include <SPI.h> #include <Ethernet.h> #include <HttpClient.h> #include <Xively.h> #define API_KEY "zuivpbOAGm6DnvmbWzKifFhcAaLwxozmw9GRu4saiFfjNHsT" #define FEED_ID 388783128 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; const int lightSensorPin=2; const int tempPin1=3; const int tempPin2=4; unsigned long lastConnectionTime = 0; const unsigned long connectionInterval = 15000; char sensorId1[] = "light"; char sensorId2[] = "temp1"; char sensorId3[] = "temp2"; XivelyDatastream datastreams[] = { XivelyDatastream(sensorId1, strlen(sensorId1), DATASTREAM_FLOAT), XivelyDatastream(sensorId2, strlen(sensorId2), DATASTREAM_FLOAT), XivelyDatastream(sensorId3, strlen(sensorId3), DATASTREAM_FLOAT), }; XivelyFeed feed(FEED_ID, datastreams, 3 ); EthernetClient client; XivelyClient xivelyclient(client); void setup() { Serial.begin(9600); Serial.println("Initializing network"); while (Ethernet.begin(mac) != 1) { Serial.println("Error getting IP address via DHCP, trying again..."); delay(15000); } Serial.println("Network initialized"); Serial.println("Ready."); } void loop() { if (millis() - lastConnectionTime > connectionInterval) { float lightLevel = map(analogRead(lightSensorPin),0,1023,0,100); sendData(0, lightLevel); getData(0); float temperature1 = ((getVoltage(tempPin1) -.5) * 100L); sendData(1, temperature1); getData(1); float temperature2 = ((getVoltage(tempPin2) -.5) * 100L); sendData(2, temperature2); getData(2); lastConnectionTime = millis(); Serial.println("Waiting for next reading"); Serial.println("========================"); } } void sendData(int streamIndexNumber, float sensorValue) { datastreams[streamIndexNumber].setFloat(sensorValue);~~~~ Serial.print("Sensor value is: "); Serial.println(datastreams[streamIndexNumber].getFloat()); Serial.println("Uploading to Xively"); int ret = xivelyclient.put(feed, API_KEY); } void getData(int stream) { Serial.println("Reading the data back from Xively"); int request = xivelyclient.get(feed, API_KEY); if (request > 0) { Serial.print("Datastream: "); Serial.println(feed[stream]); Serial.print("Sensor value: "); Serial.println(feed[stream].getFloat()); Serial.println("========================"); } } float getVoltage(int pin){ return (analogRead(pin) * .004882814); }
i tried to verify the code and it does not have any problems and i can't find any solutions for it...
I also post this question on another forum: Sending data from Ethernet Shield to Xively - Arduino Forum