1

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:

  //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);

Any ideas are appreciated.

2
  • Just a little question, are you getting accurate readings using the DHT22? What resistor value are you using? Commented Aug 29, 2016 at 15:22
  • The readings are accurate. I'm using the grove sensor so not resistor required (I assume) : seeedstudio.com/….
    – Sander
    Commented Aug 29, 2016 at 17:36

1 Answer 1

1

I found the solution. Based on this post: http://forum.arduino.cc/index.php?topic=198433.0 I concluded that my strings are too long or my board runs out of memory. I removed the posting of the bucket and created abbreviations in my signal names. This solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.