Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 340 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 17

Combine DHT22 and SI114X.h com

It looks like iI cannot combine the Grove Sunlightsunlight sensor and the Grove DHT22 Temperaturetemperature and Humidityhumidity sensor. I can't figure out why.

I'veI have the following setup: Seeeduino CLOUD (Arduino YUN clone) Grove Shield Grove Sunlight sensor connected to a I2C port Grove DHT22 Temperature and Humidity sensor connected to port A0

I'm sending the data to Initialstate.com

  • Seeeduino Cloud (Arduino Yún clone)
  • Grove Shield Grove sunlight sensor connected to an I2C port
  • Grove DHT22 temperature and humidity sensor connected to port A0

I'm sending the data to Initialstate.com. This is my code:

// Process.h gives us access to the Process class, which lets
// us communicate with the shell
#include "DHT.h"        //Temp Hum sensor
#include <Bridge.h>
#include <Process.h>
#include <Wire.h>
#include "SI114X.h"     //Sunlight sensor

SI114X SI1145 = SI114X();

////////////////////////////////////////////

//Temperature and Humidity sensor data start
#define DHTPIN A0      
// what sensor is connected to, in this case A0

//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

 //TemparatureTemperature and Humidity sensor data end

////////////////////////////////////////////

 
////////////////////////////
// Initial State Streamer //
////////////////////////////
// URL to IS Bucket API
String ISBucketURL = "https://groker.initialstate.com/api/buckets";
// URL to IS Event API
String ISEventURL = "https://groker.initialstate.com/api/events";
// Access key (the one you find in your account settings):
String accessKey = "KRYLC3tvJUiyTVqTJr5nRqgkKQI2FiDh";
String bucketKey = "Test_Klimaat2";
// Bucket name (name your data will be associated with in Initial State):
String bucketName = "Test klimaat 2";
// Bucket key (hidden reference to your bucket that allows appending):
//String bucketKey = "arduino_stream";
// Bucket name (name your data will be associated with in Initial State):
//String bucketName = "Arduino Stream";
// How many signals are in your stream? You can have as few or as many as you want
const int NUM_SIGNALS = 5;
// What are the names of your signals (i.e. "Temperature", "Humidity", etc.)
String signalName[NUM_SIGNALS] = {"Humidity", "Temperatur", "Visable", "Infrared", "UV"};
// This array is to store our signal data later
String signalData[NUM_SIGNALS];

// This only runs once at the very beginning
void setup() 
 {
  Serial.begin(9600);
  Bridge.begin();
  Wire.begin(); 
  SI1145.Begin();
  dht.begin(); //Initialize temparature and humidity sensor
 
 
  while (!Serial);
    // Post Bucket
    Serial.println("Posting Bucket!");
    // The postBucket() function creates a bucket 
    // (unnecessary if the bucket already exists)
    postBucket();
}
 
// This repeats
void loop()
{  {
  // Gather Data
  // Read from a port for input or output or generate your own values/messages
  // These signals are random numbers for the sake of example
  
  String VIS;
  String IR;
  String UV;
  String TEMP;
  String HUM;
  
  //Code reading DHT22
  HUM = String((float)dht.readHumidity());
  TEMP = String((float)dht.readTemperature());
  
  //code reading Sunlight data
  VIS = String(SI1145.ReadVisible());
  IR = String(SI1145.ReadIR());
  UV = String((float)SI1145.ReadUV()/100);
        
  signalData[0] = HUM;
  signalData[1] = TEMP;
  signalData[2] = VIS;
  signalData[3] = IR;
  signalData[4] = UV;

 
  // Post Data
  Serial.println("Posting Data!");
  // The postData() function streams our events
  postData(); 
  // Wait for 5 seconds before collecting and sending the next batch
  delay(5000);
}
 
 
 
// Here are the data bucket creation and posting functions
// They do not need to be edited - everything you would need to change for 
// your situation can be found above
 
void postBucket()
  {
  // Initialize the process
  Process isbucket;
 
  isbucket.begin("curl");
  isbucket.addParameter("-k");
  isbucket.addParameter("-v");
  isbucket.addParameter("-X");
  isbucket.addParameter("POST");
  isbucket.addParameter("-H");
  isbucket.addParameter("Content-Type:application/json");
  isbucket.addParameter("-H");
  isbucket.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isbucket.addParameter("-H");
  isbucket.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  isbucket.addParameter("-d");
  isbucket.addParameter("{\"bucketKey\": \"" + bucketKey + "\", \"bucketName\": \"" + bucketName + "\"}");
  
  isbucket.addParameter("https://groker.initialstate.com/api/buckets");
  
  // Run the process
  isbucket.run();
 
  Serial.flush();
}
 
void postData()
  {
  // Initialize the process
  Process isstreamer;
 
  isstreamer.begin("curl");
  isstreamer.addParameter("-k");
  isstreamer.addParameter("-v");
  isstreamer.addParameter("-X");
  isstreamer.addParameter("POST");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Content-Type:application/json");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  // Note that bucketName is not needed here
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-BucketKey:" + bucketKey);
 
  isstreamer.addParameter("-d");
 
  // Initialize a string to hold our signal data
  String jsonData;
 
  jsonData = "[";
 
  for (int i=0; i<NUM_SIGNALS; i++)
  {
    jsonData += "{\"key\": \"" + signalName[i] + "\", \"value\": \"" + signalData[i] + "\"}";
 
    if (i != NUM_SIGNALS - 1)
    {
      jsonData += ",";
    }
  }
 
  jsonData += "]";
 
  isstreamer.addParameter(jsonData);
 
  isstreamer.addParameter("https://groker.initialstate.com/api/events");
 
  // Print posted data for debug
  Serial.print("Sending data: ");
  Serial.println(jsonData);
 
  // Run the process
  isstreamer.run();
 
  Serial.flush();
}

This is my code:

When I run this code, the Serial monitor will correctly display the data string I want to send with all values. However the data is NOT sendsent. Only when I comment out one of these lines in the Looploop() declaration the data is sendsent to Initial stateInitialstate successfully. Obviously without the data commented out:

DHT22 and SI114X.h com

It looks like i cannot combine the Grove Sunlight sensor and the Grove DHT22 Temperature and Humidity sensor. I can't figure out why.

I've the following setup: Seeeduino CLOUD (Arduino YUN clone) Grove Shield Grove Sunlight sensor connected to a I2C port Grove DHT22 Temperature and Humidity sensor connected to port A0

I'm sending the data to Initialstate.com

// Process.h gives us access to the Process class, which lets
// us communicate with the shell
#include "DHT.h"        //Temp Hum sensor
#include <Bridge.h>
#include <Process.h>
#include <Wire.h>
#include "SI114X.h"     //Sunlight sensor

SI114X SI1145 = SI114X();

////////////////////////////////////////////

//Temperature and Humidity sensor data start
#define DHTPIN A0     // what sensor is connected to, in this case A0

//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

 //Temparature and Humidity sensor data end

////////////////////////////////////////////

 
////////////////////////////
// Initial State Streamer //
////////////////////////////
// URL to IS Bucket API
String ISBucketURL = "https://groker.initialstate.com/api/buckets";
// URL to IS Event API
String ISEventURL = "https://groker.initialstate.com/api/events";
// Access key (the one you find in your account settings):
String accessKey = "KRYLC3tvJUiyTVqTJr5nRqgkKQI2FiDh";
String bucketKey = "Test_Klimaat2";
// Bucket name (name your data will be associated with in Initial State):
String bucketName = "Test klimaat 2";
// Bucket key (hidden reference to your bucket that allows appending):
//String bucketKey = "arduino_stream";
// Bucket name (name your data will be associated with in Initial State):
//String bucketName = "Arduino Stream";
// How many signals are in your stream? You can have as few or as many as you want
const int NUM_SIGNALS = 5;
// What are the names of your signals (i.e. "Temperature", "Humidity", etc.)
String signalName[NUM_SIGNALS] = {"Humidity", "Temperatur", "Visable", "Infrared", "UV"};
// This array is to store our signal data later
String signalData[NUM_SIGNALS];

// This only runs once at the very beginning
void setup() 
 {
  Serial.begin(9600);
  Bridge.begin();
  Wire.begin(); 
  SI1145.Begin();
  dht.begin(); //Initialize temparature and humidity sensor
 
 
  while (!Serial);
    // Post Bucket
    Serial.println("Posting Bucket!");
    // The postBucket() function creates a bucket 
    // (unnecessary if the bucket already exists)
    postBucket();
}
 
// This repeats
void loop()
{  
  // Gather Data
  // Read from a port for input or output or generate your own values/messages
  // These signals are random numbers for the sake of example
  
  String VIS;
  String IR;
  String UV;
  String TEMP;
  String HUM;
  
  //Code reading DHT22
  HUM = String((float)dht.readHumidity());
  TEMP = String((float)dht.readTemperature());
  
  //code reading Sunlight data
  VIS = String(SI1145.ReadVisible());
  IR = String(SI1145.ReadIR());
  UV = String((float)SI1145.ReadUV()/100);
        
  signalData[0] = HUM;
  signalData[1] = TEMP;
  signalData[2] = VIS;
  signalData[3] = IR;
  signalData[4] = UV;

 
  // Post Data
  Serial.println("Posting Data!");
  // The postData() function streams our events
  postData(); 
  // Wait for 5 seconds before collecting and sending the next batch
  delay(5000);
}
 
 
 
// Here are the data bucket creation and posting functions
// They do not need to be edited - everything you would need to change for 
// your situation can be found above
 
void postBucket()
 {
  // Initialize the process
  Process isbucket;
 
  isbucket.begin("curl");
  isbucket.addParameter("-k");
  isbucket.addParameter("-v");
  isbucket.addParameter("-X");
  isbucket.addParameter("POST");
  isbucket.addParameter("-H");
  isbucket.addParameter("Content-Type:application/json");
  isbucket.addParameter("-H");
  isbucket.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isbucket.addParameter("-H");
  isbucket.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  isbucket.addParameter("-d");
  isbucket.addParameter("{\"bucketKey\": \"" + bucketKey + "\", \"bucketName\": \"" + bucketName + "\"}");
  
  isbucket.addParameter("https://groker.initialstate.com/api/buckets");
  
  // Run the process
  isbucket.run();
 
  Serial.flush();
}
 
void postData()
 {
  // Initialize the process
  Process isstreamer;
 
  isstreamer.begin("curl");
  isstreamer.addParameter("-k");
  isstreamer.addParameter("-v");
  isstreamer.addParameter("-X");
  isstreamer.addParameter("POST");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Content-Type:application/json");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  // Note that bucketName is not needed here
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-BucketKey:" + bucketKey);
 
  isstreamer.addParameter("-d");
 
  // Initialize a string to hold our signal data
  String jsonData;
 
  jsonData = "[";
 
  for (int i=0; i<NUM_SIGNALS; i++)
  {
    jsonData += "{\"key\": \"" + signalName[i] + "\", \"value\": \"" + signalData[i] + "\"}";
 
    if (i != NUM_SIGNALS - 1)
    {
      jsonData += ",";
    }
  }
 
  jsonData += "]";
 
  isstreamer.addParameter(jsonData);
 
  isstreamer.addParameter("https://groker.initialstate.com/api/events");
 
  // Print posted data for debug
  Serial.print("Sending data: ");
  Serial.println(jsonData);
 
  // Run the process
  isstreamer.run();
 
  Serial.flush();
}

This is my code:

When I run this code the Serial monitor will correctly display the data string I want to send with all values. However the data is NOT send. Only when I comment out one of these lines in the Loop declaration the data is send to Initial state successfully. Obviously without the data commented out:

Combine DHT22 and SI114X.h

It looks like I cannot combine the Grove sunlight sensor and the Grove DHT22 temperature and humidity sensor. I can't figure out why.

I have the following setup:

  • Seeeduino Cloud (Arduino Yún clone)
  • Grove Shield Grove sunlight sensor connected to an I2C port
  • Grove DHT22 temperature and humidity sensor connected to port A0

I'm sending the data to Initialstate.com. This is my code:

// Process.h gives us access to the Process class, which lets
// us communicate with the shell
#include "DHT.h" //Temp Hum sensor
#include <Bridge.h>
#include <Process.h>
#include <Wire.h>
#include "SI114X.h" //Sunlight sensor

SI114X SI1145 = SI114X();

////////////////////////////////////////////

//Temperature and Humidity sensor data start
#define DHTPIN A0 
// what sensor is connected to, in this case A0    
#define DHTTYPE DHT22   // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE);
//Temperature and Humidity sensor data end

////////////////////////////
// Initial State Streamer //
////////////////////////////
// URL to IS Bucket API
String ISBucketURL = "https://groker.initialstate.com/api/buckets";
// URL to IS Event API
String ISEventURL = "https://groker.initialstate.com/api/events";
// Access key (the one you find in your account settings):
String accessKey = "KRYLC3tvJUiyTVqTJr5nRqgkKQI2FiDh";
String bucketKey = "Test_Klimaat2";
// Bucket name (name your data will be associated with in Initial State):
String bucketName = "Test klimaat 2";
// Bucket key (hidden reference to your bucket that allows appending):
//String bucketKey = "arduino_stream";
// Bucket name (name your data will be associated with in Initial State):
//String bucketName = "Arduino Stream";
// How many signals are in your stream? You can have as few or as many as you want
const int NUM_SIGNALS = 5;
// What are the names of your signals (i.e. "Temperature", "Humidity", etc.)
String signalName[NUM_SIGNALS] = {"Humidity", "Temperatur", "Visable", "Infrared", "UV"};
// This array is to store our signal data later
String signalData[NUM_SIGNALS];

// This only runs once at the very beginning
void setup() {
  Serial.begin(9600);
  Bridge.begin();
  Wire.begin(); 
  SI1145.Begin();
  dht.begin(); //Initialize temparature and humidity sensor

  while (!Serial);
    // Post Bucket
    Serial.println("Posting Bucket!");
    // The postBucket() function creates a bucket 
    // (unnecessary if the bucket already exists)
    postBucket();
}
 
// This repeats
void loop() {
  // Gather Data
  // Read from a port for input or output or generate your own values/messages
  // These signals are random numbers for the sake of example
  
  String VIS;
  String IR;
  String UV;
  String TEMP;
  String HUM;
  
  //Code reading DHT22
  HUM = String((float)dht.readHumidity());
  TEMP = String((float)dht.readTemperature());
  
  //code reading Sunlight data
  VIS = String(SI1145.ReadVisible());
  IR = String(SI1145.ReadIR());
  UV = String((float)SI1145.ReadUV()/100);
        
  signalData[0] = HUM;
  signalData[1] = TEMP;
  signalData[2] = VIS;
  signalData[3] = IR;
  signalData[4] = UV;

  // Post Data
  Serial.println("Posting Data!");
  // The postData() function streams our events
  postData(); 
  // Wait for 5 seconds before collecting and sending the next batch
  delay(5000);
}

// Here are the data bucket creation and posting functions
// They do not need to be edited - everything you would need to change for 
// your situation can be found above
 
void postBucket() {
  // Initialize the process
  Process isbucket;
 
  isbucket.begin("curl");
  isbucket.addParameter("-k");
  isbucket.addParameter("-v");
  isbucket.addParameter("-X");
  isbucket.addParameter("POST");
  isbucket.addParameter("-H");
  isbucket.addParameter("Content-Type:application/json");
  isbucket.addParameter("-H");
  isbucket.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isbucket.addParameter("-H");
  isbucket.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  isbucket.addParameter("-d");
  isbucket.addParameter("{\"bucketKey\": \"" + bucketKey + "\", \"bucketName\": \"" + bucketName + "\"}");
  isbucket.addParameter("https://groker.initialstate.com/api/buckets");
  // Run the process
  isbucket.run();
  Serial.flush();
}
 
void postData() {
  // Initialize the process
  Process isstreamer;
  isstreamer.begin("curl");
  isstreamer.addParameter("-k");
  isstreamer.addParameter("-v");
  isstreamer.addParameter("-X");
  isstreamer.addParameter("POST");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Content-Type:application/json");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  // Note that bucketName is not needed here
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-BucketKey:" + bucketKey);
 
  isstreamer.addParameter("-d");
 
  // Initialize a string to hold our signal data
  String jsonData;
  jsonData = "[";
  for (int i=0; i<NUM_SIGNALS; i++) {
    jsonData += "{\"key\": \"" + signalName[i] + "\", \"value\": \"" + signalData[i] + "\"}";
    if (i != NUM_SIGNALS - 1) {
      jsonData += ",";
    }
  }
  jsonData += "]";
  isstreamer.addParameter(jsonData);
  isstreamer.addParameter("https://groker.initialstate.com/api/events");
  // Print posted data for debug
  Serial.print("Sending data: ");
  Serial.println(jsonData);
  // Run the process
  isstreamer.run();
  Serial.flush();
}

When I run this code, the Serial monitor will correctly display the data string I want to send with all values. However the data is NOT sent. Only when I comment out one of these lines in the loop() declaration the data is sent to Initialstate successfully. Obviously without the data commented out:

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 1 character in body
Source Link

I'm sending the data to Initial stateInitialstate.com

I'm sending the data to Initial state.

I'm sending the data to Initialstate.com

deleted 1 character in body
Source Link
// Process.h gives us access to the Process class, which lets
// us communicate with the shell
#include "DHT.h"        //Temp Hum sensor
#include <Bridge.h>
#include <Process.h>
#include <Wire.h>
#include "SI114X.h"     //Sunlight sensor

SI114X SI1145 = SI114X();

////////////////////////////////////////////

//Temperature and Humidity sensor data start
#define DHTPIN 2A0     // what sensor is connected to, in this case A3A0

//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

//Temparature and Humidity sensor data startend

////////////////////////////////////////////

 
////////////////////////////
// Initial State Streamer //
////////////////////////////
// URL to IS Bucket API
String ISBucketURL = "https://groker.initialstate.com/api/buckets";
// URL to IS Event API
String ISEventURL = "https://groker.initialstate.com/api/events";
// Access key (the one you find in your account settings):
String accessKey = "KRYLC3tvJUiyTVqTJr5nRqgkKQI2FiDh";
String bucketKey = "Test_Klimaat2";
// Bucket name (name your data will be associated with in Initial State):
String bucketName = "Test klimaat 2";
// Bucket key (hidden reference to your bucket that allows appending):
//String bucketKey = "arduino_stream";
// Bucket name (name your data will be associated with in Initial State):
//String bucketName = "Arduino Stream";
// How many signals are in your stream? You can have as few or as many as you want
const int NUM_SIGNALS = 5;
// What are the names of your signals (i.e. "Temperature", "Humidity", etc.)
String signalName[NUM_SIGNALS] = {"Humidity", "Temperatur", "Visable", "Infrared", "UV"};
// This array is to store our signal data later
String signalData[NUM_SIGNALS];

// This only runs once at the very beginning
void setup() 
{
  Serial.begin(9600);
  Bridge.begin();
  Wire.begin(); 
  SI1145.Begin();
  dht.begin(); //Initialize temparature and humidity sensor
 
 
  while (!Serial);
    // Post Bucket
    Serial.println("Posting Bucket!");
    // The postBucket() function creates a bucket 
    // (unnecessary if the bucket already exists)
    postBucket();
}
 
// This repeats
void loop()
{  
  // Gather Data
  // Read from a port for input or output or generate your own values/messages
  // These signals are random numbers for the sake of example
  
  String VIS;
  String IR;
  String UV;
  String TEMP;
  String HUM;
  
  //Code reading DHT22
  HUM = String((float)dht.readHumidity());
  TEMP = String((float)dht.readTemperature());
  
  //code reading Sunlight data
  VIS = String(SI1145.ReadVisible());
  IR = String(SI1145.ReadIR());
  UV = String((float)SI1145.ReadUV()/100);
        
  signalData[0] = HUM;
  signalData[1] = TEMP;
  signalData[2] = VIS;
  signalData[3] = IR;
  signalData[4] = UV;

 
  // Post Data
  Serial.println("Posting Data!");
  // The postData() function streams our events
  postData(); 
  // Wait for 5 seconds before collecting and sending the next batch
  delay(5000);
}
 
 
 
// Here are the data bucket creation and posting functions
// They do not need to be edited - everything you would need to change for 
// your situation can be found above
 
void postBucket()
{
  // Initialize the process
  Process isbucket;
 
  isbucket.begin("curl");
  isbucket.addParameter("-k");
  isbucket.addParameter("-v");
  isbucket.addParameter("-X");
  isbucket.addParameter("POST");
  isbucket.addParameter("-H");
  isbucket.addParameter("Content-Type:application/json");
  isbucket.addParameter("-H");
  isbucket.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isbucket.addParameter("-H");
  isbucket.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  isbucket.addParameter("-d");
  isbucket.addParameter("{\"bucketKey\": \"" + bucketKey + "\", \"bucketName\": \"" + bucketName + "\"}");
  
  isbucket.addParameter("https://groker.initialstate.com/api/buckets");
  
  // Run the process
  isbucket.run();
 
  Serial.flush();
}
 
void postData()
{
  // Initialize the process
  Process isstreamer;
 
  isstreamer.begin("curl");
  isstreamer.addParameter("-k");
  isstreamer.addParameter("-v");
  isstreamer.addParameter("-X");
  isstreamer.addParameter("POST");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Content-Type:application/json");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  // Note that bucketName is not needed here
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-BucketKey:" + bucketKey);
 
  isstreamer.addParameter("-d");
 
  // Initialize a string to hold our signal data
  String jsonData;
 
  jsonData = "[";
 
  for (int i=0; i<NUM_SIGNALS; i++)
  {
    jsonData += "{\"key\": \"" + signalName[i] + "\", \"value\": \"" + signalData[i] + "\"}";
 
    if (i != NUM_SIGNALS - 1)
    {
      jsonData += ",";
    }
  }
 
  jsonData += "]";
 
  isstreamer.addParameter(jsonData);
 
  isstreamer.addParameter("https://groker.initialstate.com/api/events");
 
  // Print posted data for debug
  Serial.print("Sending data: ");
  Serial.println(jsonData);
 
  // Run the process
  isstreamer.run();
 
  Serial.flush();
}

This is my code:
// Process.h gives us access to the Process class, which lets
// us communicate with the shell
#include "DHT.h"        //Temp Hum sensor
#include <Bridge.h>
#include <Process.h>
#include <Wire.h>
#include "SI114X.h"     //Sunlight sensor

SI114X SI1145 = SI114X();

////////////////////////////////////////////

//Temperature and Humidity sensor data start
#define DHTPIN 2     // what sensor is connected to, in this case A3

//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

//Temparature and Humidity sensor data start

////////////////////////////////////////////

 
////////////////////////////
// Initial State Streamer //
////////////////////////////
// URL to IS Bucket API
String ISBucketURL = "https://groker.initialstate.com/api/buckets";
// URL to IS Event API
String ISEventURL = "https://groker.initialstate.com/api/events";
// Access key (the one you find in your account settings):
String accessKey = "KRYLC3tvJUiyTVqTJr5nRqgkKQI2FiDh";
String bucketKey = "Test_Klimaat2";
// Bucket name (name your data will be associated with in Initial State):
String bucketName = "Test klimaat 2";
// Bucket key (hidden reference to your bucket that allows appending):
//String bucketKey = "arduino_stream";
// Bucket name (name your data will be associated with in Initial State):
//String bucketName = "Arduino Stream";
// How many signals are in your stream? You can have as few or as many as you want
const int NUM_SIGNALS = 5;
// What are the names of your signals (i.e. "Temperature", "Humidity", etc.)
String signalName[NUM_SIGNALS] = {"Humidity", "Temperatur", "Visable", "Infrared", "UV"};
// This array is to store our signal data later
String signalData[NUM_SIGNALS];

// This only runs once at the very beginning
void setup() 
{
  Serial.begin(9600);
  Bridge.begin();
  Wire.begin(); 
  SI1145.Begin();
  dht.begin(); //Initialize temparature and humidity sensor
 
 
  while (!Serial);
    // Post Bucket
    Serial.println("Posting Bucket!");
    // The postBucket() function creates a bucket 
    // (unnecessary if the bucket already exists)
    postBucket();
}
 
// This repeats
void loop()
{  
  // Gather Data
  // Read from a port for input or output or generate your own values/messages
  // These signals are random numbers for the sake of example
  
  String VIS;
  String IR;
  String UV;
  String TEMP;
  String HUM;
  
  //Code reading DHT22
  HUM = String((float)dht.readHumidity());
  TEMP = String((float)dht.readTemperature());
  
  //code reading Sunlight data
  VIS = String(SI1145.ReadVisible());
  IR = String(SI1145.ReadIR());
  UV = String((float)SI1145.ReadUV()/100);
        
  signalData[0] = HUM;
  signalData[1] = TEMP;
  signalData[2] = VIS;
  signalData[3] = IR;
  signalData[4] = UV;

 
  // Post Data
  Serial.println("Posting Data!");
  // The postData() function streams our events
  postData(); 
  // Wait for 5 seconds before collecting and sending the next batch
  delay(5000);
}
 
 
 
// Here are the data bucket creation and posting functions
// They do not need to be edited - everything you would need to change for 
// your situation can be found above
 
void postBucket()
{
  // Initialize the process
  Process isbucket;
 
  isbucket.begin("curl");
  isbucket.addParameter("-k");
  isbucket.addParameter("-v");
  isbucket.addParameter("-X");
  isbucket.addParameter("POST");
  isbucket.addParameter("-H");
  isbucket.addParameter("Content-Type:application/json");
  isbucket.addParameter("-H");
  isbucket.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isbucket.addParameter("-H");
  isbucket.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  isbucket.addParameter("-d");
  isbucket.addParameter("{\"bucketKey\": \"" + bucketKey + "\", \"bucketName\": \"" + bucketName + "\"}");
  
  isbucket.addParameter("https://groker.initialstate.com/api/buckets");
  
  // Run the process
  isbucket.run();
 
  Serial.flush();
}
 
void postData()
{
  // Initialize the process
  Process isstreamer;
 
  isstreamer.begin("curl");
  isstreamer.addParameter("-k");
  isstreamer.addParameter("-v");
  isstreamer.addParameter("-X");
  isstreamer.addParameter("POST");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Content-Type:application/json");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  // Note that bucketName is not needed here
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-BucketKey:" + bucketKey);
 
  isstreamer.addParameter("-d");
 
  // Initialize a string to hold our signal data
  String jsonData;
 
  jsonData = "[";
 
  for (int i=0; i<NUM_SIGNALS; i++)
  {
    jsonData += "{\"key\": \"" + signalName[i] + "\", \"value\": \"" + signalData[i] + "\"}";
 
    if (i != NUM_SIGNALS - 1)
    {
      jsonData += ",";
    }
  }
 
  jsonData += "]";
 
  isstreamer.addParameter(jsonData);
 
  isstreamer.addParameter("https://groker.initialstate.com/api/events");
 
  // Print posted data for debug
  Serial.print("Sending data: ");
  Serial.println(jsonData);
 
  // Run the process
  isstreamer.run();
 
  Serial.flush();
}

This is my code:
// Process.h gives us access to the Process class, which lets
// us communicate with the shell
#include "DHT.h"        //Temp Hum sensor
#include <Bridge.h>
#include <Process.h>
#include <Wire.h>
#include "SI114X.h"     //Sunlight sensor

SI114X SI1145 = SI114X();

////////////////////////////////////////////

//Temperature and Humidity sensor data start
#define DHTPIN A0     // what sensor is connected to, in this case A0

//#define DHTTYPE DHT11   // DHT 11 
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

//Temparature and Humidity sensor data end

////////////////////////////////////////////

 
////////////////////////////
// Initial State Streamer //
////////////////////////////
// URL to IS Bucket API
String ISBucketURL = "https://groker.initialstate.com/api/buckets";
// URL to IS Event API
String ISEventURL = "https://groker.initialstate.com/api/events";
// Access key (the one you find in your account settings):
String accessKey = "KRYLC3tvJUiyTVqTJr5nRqgkKQI2FiDh";
String bucketKey = "Test_Klimaat2";
// Bucket name (name your data will be associated with in Initial State):
String bucketName = "Test klimaat 2";
// Bucket key (hidden reference to your bucket that allows appending):
//String bucketKey = "arduino_stream";
// Bucket name (name your data will be associated with in Initial State):
//String bucketName = "Arduino Stream";
// How many signals are in your stream? You can have as few or as many as you want
const int NUM_SIGNALS = 5;
// What are the names of your signals (i.e. "Temperature", "Humidity", etc.)
String signalName[NUM_SIGNALS] = {"Humidity", "Temperatur", "Visable", "Infrared", "UV"};
// This array is to store our signal data later
String signalData[NUM_SIGNALS];

// This only runs once at the very beginning
void setup() 
{
  Serial.begin(9600);
  Bridge.begin();
  Wire.begin(); 
  SI1145.Begin();
  dht.begin(); //Initialize temparature and humidity sensor
 
 
  while (!Serial);
    // Post Bucket
    Serial.println("Posting Bucket!");
    // The postBucket() function creates a bucket 
    // (unnecessary if the bucket already exists)
    postBucket();
}
 
// This repeats
void loop()
{  
  // Gather Data
  // Read from a port for input or output or generate your own values/messages
  // These signals are random numbers for the sake of example
  
  String VIS;
  String IR;
  String UV;
  String TEMP;
  String HUM;
  
  //Code reading DHT22
  HUM = String((float)dht.readHumidity());
  TEMP = String((float)dht.readTemperature());
  
  //code reading Sunlight data
  VIS = String(SI1145.ReadVisible());
  IR = String(SI1145.ReadIR());
  UV = String((float)SI1145.ReadUV()/100);
        
  signalData[0] = HUM;
  signalData[1] = TEMP;
  signalData[2] = VIS;
  signalData[3] = IR;
  signalData[4] = UV;

 
  // Post Data
  Serial.println("Posting Data!");
  // The postData() function streams our events
  postData(); 
  // Wait for 5 seconds before collecting and sending the next batch
  delay(5000);
}
 
 
 
// Here are the data bucket creation and posting functions
// They do not need to be edited - everything you would need to change for 
// your situation can be found above
 
void postBucket()
{
  // Initialize the process
  Process isbucket;
 
  isbucket.begin("curl");
  isbucket.addParameter("-k");
  isbucket.addParameter("-v");
  isbucket.addParameter("-X");
  isbucket.addParameter("POST");
  isbucket.addParameter("-H");
  isbucket.addParameter("Content-Type:application/json");
  isbucket.addParameter("-H");
  isbucket.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isbucket.addParameter("-H");
  isbucket.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  isbucket.addParameter("-d");
  isbucket.addParameter("{\"bucketKey\": \"" + bucketKey + "\", \"bucketName\": \"" + bucketName + "\"}");
  
  isbucket.addParameter("https://groker.initialstate.com/api/buckets");
  
  // Run the process
  isbucket.run();
 
  Serial.flush();
}
 
void postData()
{
  // Initialize the process
  Process isstreamer;
 
  isstreamer.begin("curl");
  isstreamer.addParameter("-k");
  isstreamer.addParameter("-v");
  isstreamer.addParameter("-X");
  isstreamer.addParameter("POST");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Content-Type:application/json");
  isstreamer.addParameter("-H");
  isstreamer.addParameter("Accept-Version:0.0.1");
 
  // IS Access Key Header
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-AccessKey:" + accessKey);
 
  // IS Bucket Key Header
  // Note that bucketName is not needed here
  isstreamer.addParameter("-H");
  isstreamer.addParameter("X-IS-BucketKey:" + bucketKey);
 
  isstreamer.addParameter("-d");
 
  // Initialize a string to hold our signal data
  String jsonData;
 
  jsonData = "[";
 
  for (int i=0; i<NUM_SIGNALS; i++)
  {
    jsonData += "{\"key\": \"" + signalName[i] + "\", \"value\": \"" + signalData[i] + "\"}";
 
    if (i != NUM_SIGNALS - 1)
    {
      jsonData += ",";
    }
  }
 
  jsonData += "]";
 
  isstreamer.addParameter(jsonData);
 
  isstreamer.addParameter("https://groker.initialstate.com/api/events");
 
  // Print posted data for debug
  Serial.print("Sending data: ");
  Serial.println(jsonData);
 
  // Run the process
  isstreamer.run();
 
  Serial.flush();
}

This is my code:
Source Link
Loading
1
2