Yes, it does! But I'm still not understanding some of the basics for getting the data from the Xenon to the Argon.
After trying so many things, my code got a bit messy. I went back to each device, cleaned the code up, and then added code to print and make sure the Xenon was still collecting and outputting the correct data. It is.
Things are not so great on the Argon side. On the Particle Console I get "null" for Room Environment. If I comment out the print associated with the json parser and let it try to print to the monitor, I get nothing except carriage returns every 5 seconds. If I uncomment the json print and comment out the serial monitor print I only get the "failed to get..." comments. So it appears I'm not getting the data from the Xenon to the Argon.
At the risk of continued public embarrassment
, my current code on the Xenon:
// This #include statement was automatically added by the Particle IDE.
#include <JsonParserGeneratorRK.h>
#include <Seeed_DHT11.h>
#define DHTPIN D4//set pin for DHT
DHT dht(DHTPIN);
int tempF = 0;
int humidity = 0;
int lasttempF = 0;//I'll use these to get rid of spikes in the data
int tempFdelta;
int lasthumidity = 0;
int humiditydelta;
unsigned long lastPubMillis = 0;
unsigned long pubInterval = 5000;
//Global variables to store messages.
char *message = "Xenon1";
char msg[128];
// This creates a buffer to hold up to 256 bytes of JSON data (good for Particle.publish)
JsonWriterStatic<256> jw;
void setup()
{
Particle.variable("tempF", tempF);
Particle.variable("humidity", humidity);
dht.begin(); //initialize the sensor
Serial.begin(9600);
}
void loop()
{
//Use a millis timer for non-blocking code design.
if (millis() - lastPubMillis > pubInterval)
{
humidity = dht.getHumidity();
tempF = dht.getTempFarenheit();
tempFdelta = tempF-lasttempF;
tempFdelta = abs(tempFdelta);
humiditydelta = humidity-lasthumidity;
humiditydelta = abs(humiditydelta);
if(tempFdelta <2 && humiditydelta <2)
{
//print to make sure data is actually there
Serial.print("tempF: ");
Serial.println(tempF);
Serial.print("humidity: ");
Serial.println(humidity);
Serial.println();
{
JsonWriterAutoObject obj(&jw);
// Add various types of data
jw.insertKeyValue("tempF", tempF);
jw.insertKeyValue("humidity", humidity);
}
//Send the data.
Mesh.publish("Xenon1",msg);
}
//Update the pub millis timer.
lastPubMillis = millis();
lasttempF = tempF;
lasthumidity = humidity;
}
}
My current code on the Argon:
// This #include statement was automatically added by the Particle IDE.
#include <JsonParserGeneratorRK.h>
// This #include statement was automatically added by the Particle IDE.
#include "TM1637.h""
#define CLK D2//pins definitions for TM1637
#define DIO D3
TM1637 tm1637(CLK,DIO);
unsigned long lastPubMillis = 0;
unsigned long pubInterval = 5000;
int tempF;
int humidity;
//Global variables to store messages.
char *message = "Room Environment";
char msg[128];
void printJson(JsonParser &jp);
// Create a parser to handle 2K of data and 100 tokens
JsonParserStatic<2048, 100> jsonParser;
// this will be called whenever an event arrives we subscribed to
void myHandler(const char *event, const char *data){
Serial.println(data); // print out the data as it comes in for debugging
jsonParser.clear(); // make sure the parser buffer is fresh and empty
jsonParser.addString(data); // copy the received data into the parser buffer for it to work with
if (jsonParser.parse()) { // let the parser do its job and split up the data internally
// first ask the parser for the value connected with the key 'Temperature'
// if this is successful pop that value into the provided variable tempF
// if not, the function will return false which - in turn - triggers the error output
if (jsonParser.getOuterValueByKey("tempF", tempF) == false) {
Serial.println("failed to get Temperature");
}
// do the same for 'Humidity'
// if(!someBoolean) is short hand for if(someBoolean == false)
if (!jsonParser.getOuterValueByKey("humidity", humidity)) {
Serial.println("failed to get Humidity");
}
}
}
void setup()
{
tm1637.init();
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
tm1637.point(POINT_ON);
Serial.begin(9600);
delay(1500);
Mesh.subscribe("Xenon1",myHandler);
}
void loop()
{
//Use a millis timer for non-blocking code design.
if (millis() - lastPubMillis > pubInterval)
{
/*Serial.print("tempF: ");
Serial.println(tempF);
Serial.print("humidity: ");
Serial.println(humidity);
Serial.println();*/
//Send your data.
Particle.publish("Room Environment",msg);
int digit1 = tempF/10;
int digit2 = tempF % 10;
int digit3 = humidity/10;
int digit4 = humidity % 10;
tm1637.display(0,digit1);
tm1637.display(1,digit2);
tm1637.display(2,digit3);
tm1637.display(3,digit4);
}
//Update your pub millis timer.
lastPubMillis = millis();
}