optical dust sensor data to xively

Hello.
Recently I bought myself an optical dust sensor and I hooked it up with my Arduino and then I tested the code. It was satisfactory after consulting it’s wiki page:
Here is the link:
http://www.seeedstudio.com/wiki/Grove_-_Dust_sensor
Code is there in the wiki page to read the data in serial monitor.

Now I wanted to upload the data to xively and so I used xively’s Arduino Library.

Looking at one of the “data-stream upload example”, I modified my code in this way:

[code]Code:
//for OLED********
#include <Wire.h>
#include <SeeedOLED.h>
#include <avr/pgmspace.h>
//*****************
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>

//Assigning parameters for the dust sensor//same as the previous code
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
int concentration = 0;

//Xively parameters**************

// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char xivelyKey[] = “neZYOTXMfiqD9OJD3sYiasJdmX1X5DxzyzH2IuHmhk4SLFAH”; //this is my xively API Key

char sensorId[] = “Particle_Conc:”;
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};

// Finally, wrap the datastreams into a feed
XivelyFeed feed(1803940077, datastreams, 1); // my FEED ID is 1803940077 and single datastream

EthernetClient client;
XivelyClient xivelyclient(client);

void setup()
{
Serial.begin(9600);

Serial.println(“Starting single datastream upload to Xively…”);
Serial.println();
while (Ethernet.begin(mac) != 1)
{
Serial.println(“Error getting IP address via DHCP, trying again…”);
delay(15000);
}

// OLED stuff****************************
//pinMode(CS_pin, OUTPUT);
Wire.begin();
SeeedOled.init(); //initialze SEEED OLED display
DDRB|=0x21;
PORTB |= 0x21;
SeeedOled.clearDisplay(); //clear the screen and set start position to top left corner
SeeedOled.setNormalDisplay(); //Set display to normal mode (i.e non-inverse mode)
SeeedOled.setPageMode();
SeeedOled.drawBitmap(url,1024); // 1024 = 128 Pixels * 64 Pixels / 8 //Set addressing mode to Page Mode
SeeedOled.setTextXY(4, 10); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“Hello”); //Print the String
SeeedOled.setTextXY(6, 10); //Set the cursor to Xth Page, Yth Column
SeeedOled.putString(“Folks”); //Print the String
delay(5000);
SeeedOled.clearDisplay();
SeeedOled.setTextXY(2, 4);
SeeedOled.putString(“Pollution”);
SeeedOled.setTextXY(4, 4);
SeeedOled.putString(“Recorder”);
delay(2000);
SeeedOled.clearDisplay();
SeeedOled.setTextXY(3, 0);
SeeedOled.putString(“Measuring…”);
// SeeedOled.setHorizontalScrollProperties(Scroll_Right,3,0,Scroll_5Frames); //Set Scrolling properties to Scroll Right
// SeeedOled.deactivateScroll(); // Activate Scrolling

//OLED stuff finished**********************

// Dust sensor parameters*****************
pinMode(8,INPUT);
starttime = millis();//get the current time;
//////******************
}

void loop()
{
//Dust sensor calculation thing********************

duration = pulseIn(pin, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;

if ((millis()-starttime) > sampletime_ms)//if the sampel time == 30s
{
ratio = lowpulseoccupancy/(sampletime_ms10.0); // Integer percentage 0=>100
concentration = 1.1
pow(ratio,3)-3.8pow(ratio,2)+520ratio+0.62; // using spec sheet curve

Serial.print("Lowpulseoccupancy: ");
Serial.print(lowpulseoccupancy);
Serial.println("Ratio: ");
Serial.print(ratio);
Serial.println("Conc.: ");
Serial.print(concentration);
Serial.println();

lowpulseoccupancy = 0;
starttime = millis();

//Xivly upload stuff happening here
datastreams[0].setFloat(concentration);
int ret = xivelyclient.put(feed, xivelyKey);
Serial.println(ret);
Serial.println();
// problem is here some where

SeeedOled.clearDisplay();
//SeeedOled.deactivateScroll();
SeeedOled.setTextXY(0, 0);
SeeedOled.putString("Dust Conc.");
SeeedOled.setTextXY(2, 0);
SeeedOled.putString("in pcs/283ml:");
SeeedOled.setTextXY(4, 1);
SeeedOled.putFloat(concentration);

}
delay(500);
}[/code]
Now It’s uploading data as expected after it’s 30s sampling time, but the data’s do not match. It’s almost much lesser than the data I get using the previous code(Not implementing xively alterations).

I’m confused if it has to do with delay or something?
It would be kind if any body out there can scan the code and tell me what’s going wrong.

Hi.

It’s a little difficult to determine what might be going wrong with your code. I don’t see anything obviously wrong, but from your problem description, it would seem the post to xively is having some trouble.

If you could attach or show a before and after sample and the output from xively, we might be able to determine what’s going on. For example, if you could show the serial output without the calls to xively, the with the calls to xively, and then show what xively claims it received, that might be helpful.

Also, if you could print the values in “feed” just before you call the client, it might be helpful in figuring out what xively is doing.

Thanks!

I haven’t taken the screen shots but on an average when I generally upload the simple dust monitoring program with out internet script, I get value above 1800 - 3000 in my environment. Then when I upload the xively part too with that and view that in xively feed and the display the value generally falls to 700-2000.

OK. Can you post the values in the “frame” structure just before you call xively? If those are correct, then there may be an issue on the xively side.

Thanks.

Hey thanks for responses. I’ve been able to fix on that temporarily I guess with approximate delay fixation.
But now I’m faced with a different problem. Though I guess it’s not a perfect platform to ask this but its like bugging me for a long time now.
When I upload data everything seems fine. I get a return value of 200 and the data no seems nicely uploaded in real time to xively using “Xively Datastream example”. But when I need to read the feed in the serial monitor with a different Arduino, not necessarily on the same network and wifi shield on it, using “data-stream download with wifi example” from the library.

You actually have to run a small demo to understand what’s happening here.

You can make a small circuit with Arduino and Ethernet shield and a simple sensor to upload data to xively with xively library. Then with another Arduino having either an ethernet or an wifi shield on it, you try to read the data from the xively fed using the example provided.

Tell me if it works or how to fix if it does not?
Any help would be appreciated… :slight_smile: :frowning:

From my readings around the net and the terms and conditions at xively, it seems like they are rate-limiting developer accounts these days. That may account for some of the strange behavior you report.

I Also had a look at github and found some sample code for xively and arduino here:https://github.com/xively/xively_arduino

I guess that must be what you are referring to. It seems to be under active development. I looked at the Download Datastream example. It seems very simple and likely to work. I don’t havea setup to verify that for myself,but it doesn’t do anything complex. All the work and worry is in the call
int ret = xivelyclient.get(feed, xivelyKey);

i’ll be interested to heat how any efforts work out. I have been considering xively or something like it for one of my projects.

Best of luck.

Okay cool I’ll keep you posted.

Can you suggest some of the bugs that you have found out, so that we can get an idea or may be can help it out.

It’s all up there