Hi
I need help.
I try to feed my data to vively and i can’t.
Here my sketch. Can someone have a look to it and tell me what is wrong.
/*
Interface to Shinyei Model PPD42NS Particle Sensor
Program by Christopher Nafis
Written April 2012
http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
http://www.sca-shinyei.com/pdf/PPD42NS.pdf
JST Pin 1 (Black Wire) => Arduino GND
JST Pin 3 (Red wire) => Arduino 5VDC
JST Pin 4 (Yellow wire) => Arduino Digital Pin 8
*/
#include <SPI.h>
#include <Ethernet.h>
#include <stdlib.h>
byte mac = {
0x90, 0xA2, 0xDA, 0x0D, 0xA2, 0x94};
IPAddress ip(192,168,1,89);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
// initialize the library instance:
EthernetClient client;
long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
boolean lastConnected = false; // state of the connection last time through the main loop
const int postingInterval = 10000; //delay between updates to Pachube.com
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
char s[32];
void setup(){
Serial.begin(9600);
// give the ethernet module time to boot up:
delay(1000);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// Configure manually:
Ethernet.begin(mac, ip);
}
pinMode(8,INPUT);
starttime = millis();
}
void loop(){
duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;
if ((millis()-starttime) > sampletime_ms)
{
ratio = lowpulseoccupancy/(sampletime_ms10.0); // Integer percentage 0=>100
concentration = 1.1pow(ratio,3)-3.8pow(ratio,2)+520ratio+0.62;
Serial.print(lowpulseoccupancy);
Serial.print(",");
Serial.print(ratio);
Serial.print(",");
Serial.println(concentration);
lowpulseoccupancy = 0;
starttime = millis();
}
// if there’s incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
if (client.available()) {
char c = client.read();
//Serial.print(c);
}
// if there’s no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected) {
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
}
// if you’re not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
String dataString = “”;
dataString += dtostrf(concentration, 9, 4, s);
dataString += “,”;
dataString += dtostrf(ratio, 9, 4, s);
sendData(dataString);
Serial.println(dataString);
delay(1000);
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
}
// this method makes a HTTP connection to the server:
void sendData(String thisData) {
// if there’s a successful connection:
if (client.connect(“www.xively.com”, 80)) {
Serial.println(“connecting…”);
// send the HTTP PUT request.
// fill in your feed address here:
client.print(“https://xively.com/feeds/195755639\n”);
client.print(“Host: www.xively.com\n”);
// fill in your Pachube API key here:
client.print(“8JAehJVJFRCZ1ktM774bJuZRkmaINNh1aD1oU39ftijIvvDJ\n”);
client.print("Content-Length: ");
client.println(thisData.length(), DEC);
// last pieces of the HTTP PUT request:
client.print(“Content-Type: text/csv\n”);
client.println(“Connection: close\n”);
// here’s the actual content of the PUT request:
client.println(thisData);
// note the time that the connection was made:
lastConnectionTime = millis();
}
else {
// if you couldn’t make a connection:
Serial.println(“connection failed”);
}
}
Thanks