need help finding source of error

could someone help me find out why my sketch seems to only post to “one” feed on io.adafruit or none at all? each time the arduino is reset, it posts only to one feed, but then throws my “error writing to feed” condition, am i missing something? perhaps right in front of me, idk?
here is the code:

//sketch for io adafruit with temp/humidity/light sensors
//*****************************************************
//includes
//****************************************************
#include <DHT.h>
#include <WiFi101.h>
#include <WiFiClient.h>
#include <SPI.h>
#include "Adafruit_IO_Client.h"
//*******************************************************
//define's
//******************************************************
#define DHTPIN 12     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11
// Configure WiFi access point details.
#define WLAN_SSID  "WLAN_SSID"
#define WLAN_PASS  "WLAN_PASS"
// Configure Adafruit IO access.
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "AIO_USERNAME"
#define AIO_KEY    "AIO_KEY"
//**********************************************************
//init's
//*********************************************************
int photocellPin = A0;    // photocell sensor input
int photocellValue = 0;  // variable to store the value coming from the photocell val
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
//************************************************************
// Create a WiFiClient class to connect to the AIO server.
WiFiClient client;
//************************************************************
// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Finally create instances of Adafruit_IO_Feed objects, one per feed.  Do this
// by calling the getFeed function on the Adafruit_IO_FONA object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed TemperatureFeed = aio.getFeed("Temperature");
Adafruit_IO_Feed HumidityFeed = aio.getFeed("Humidity");
Adafruit_IO_Feed LightFeed = aio.getFeed("Light");

// Alternatively to access a feed with a specific key:
//Adafruit_IO_Feed testFeed = aio.getFeed("esptestfeed", "...esptestfeed key...");

//*********************************************************************
//sketch body

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
delay(10);
  Serial.println("Testing DHT And Light Sensors!");

  dht.begin();
    // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

 // Connect to WiFi access point.
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();

  Serial.println("WiFi connected");  
  Serial.println("IP address: "); Serial.println(WiFi.localIP());
  
  // Initialize the Adafruit IO client class (not strictly necessary with the
  // client class, but good practice).
  aio.begin();

  Serial.println(F("Ready!"));
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
  //--- READ AND SEND TEMPERATURE ---
  int f = dht.readTemperature(true);
  Serial.print(F("Temperature = ")); Serial.println(f, DEC);
  if (!TemperatureFeed.send(f)) Serial.println(F("*** Error writing value to temperatureFeed!"));

  //--- READ AND SEND HUMIDITY ---
  int h = dht.readHumidity();
  Serial.print(F("Humidity = ")); Serial.println(h, DEC);
  if (!HumidityFeed.send(h))Serial.println(F("*** Error writing value to humidityFeed!"));

  //--- READ AND SEND LIGHT ---
photocellValue = analogRead(photocellPin);  
photocellValue = constrain(photocellValue, 200, 800); //adjust depending on environment.   
Serial.print("incoming value from photocell sensor =");
  Serial.println( photocellValue);
  if (!LightFeed.send(photocellValue))Serial.println(F("*** Error writing value to LightFeed!"));
}

here is the hardware:
arduino Mega2560https://www.arduino.cc/en/Main/ArduinoBoardMega2560
arduino wifi101 shieldhttps://www.arduino.cc/en/Main/ArduinoWiFiShield101
osepp sensor shield http://osepp.com/products/shield-arduino-compatible/sensor-shield/
osepp light sensor http://osepp.com/products/sensors-arduino-compatible/light-sensor-module/
osepp temp/humidity sensor http://osepp.com/products/sensors-arduino-compatible/humidity-temperature-sensor/

i have verified that all the connections are correct and there doesn’t seem to be pin problem.

any ideas and help will be appreciated.

If it succeeds in getting one feed published, then a lot already works.

I’d try to rule out a problem with the sensors first, by publishing a simple number instead of the value returned by the sensor:

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
  //--- READ AND SEND TEMPERATURE ---
  //int f = dht.readTemperature(true);
    int f =  32 ;
  Serial.print(F("Temperature = ")); Serial.println(f, DEC);
  if (!TemperatureFeed.send(f)) Serial.println(F("*** Error writing value to temperatureFeed!"));

  //--- READ AND SEND HUMIDITY ---
  // int h = dht.readHumidity();
      int h = 33 ;

  Serial.print(F("Humidity = ")); Serial.println(h, DEC);
  if (!HumidityFeed.send(h))Serial.println(F("*** Error writing value to humidityFeed!"));

  //--- READ AND SEND LIGHT ---
  // photocellValue = analogRead(photocellPin);
  // photocellValue = constrain(photocellValue, 200, 800); //adjust depending on environment.
  photocellValue = 250 ;
  Serial.print("incoming value from photocell sensor =");
  Serial.println( photocellValue);
  if (!LightFeed.send(photocellValue))Serial.println(F("*** Error writing value to LightFeed!"));
}

From where did you get the example you followed and is it appropriate for the hardware you have selected ?

hey, thanks for the reply, i have looked at the code you provided and it works in the serial monitor and it posts the first value but not the others, it seems to be a connection issue with adafruit.io. but i can't be sure, removing each sensor and doing one at a time (using just the temperature feed, or just the humidity feed or just the light feed, one by one works each time the arduino is reset but even doing that still results in the "error writing to feed" after the first value is posted until the unit is restarted.

and to answer your question, these are the samples i refferenced in my code, but i have written it out on my own. :

"DHTtester" example from the "dht sensor library"

"esp8266" example from the "adafruit io arduino" library, though i am using the arduino wifi101 shield. so i modified it based on the "wifiwebclient" example in the "wifi101" library

and then used the same format for my sensors as this example on the web: https://hackaday.io/post/29590

so anyway, would i potentially be better off using mqtt for connection issues? i don't know how the mqtt connection would work any differently, but i do know that the code seems to work as long as the unit is restarted after each value and only one value is being used, but once it's published, it can't publish the next recorded value, no mater how many sensors im using.

Edit : this also is something that I'm trying to get working before I add two motors(peristaltic pumps) to the mix.

Hmmm... https://learn.adafruit.com/adafruit-io "Please keep in mind that Adafruit IO is still in the beta testing stage. There will be bugs!" "The client libraries are a work in progress. Please check back often for updates."

Have you updated your library lately?

hey, thanks wasser, yeah, i know about the beta stage, lol, i'm all about the betas and alphas. i'm sure that these libraries are sufficient even in the beta stage and such for my needs, i think it's just a matter of what protocol to use, feed.send or mqtt and what one is more reliable for posting more than one value and to more than one feed per connection. and yes, i updated just before this project.

by the way, with more time to diag some of the problems i'm seeing, it seems more like a client connect/disconnect problem, the wifi opens the connection to adafruit.io and sends the first value for the first sensor, but then doesn't send the rest of the values to the other feeds, and doesn't close the connection after trying either, therefor it seems to keep the connection alive but stops sending values until the unit is reset and the connection is re-opened and synced, sending the first feed's value over again but once again missing the other values and not closing the connection., maybe i'm wrong but hopefully someone else out there could verify. thank you all for your continued help.

I don’t have this installation so I can’t test it, but I would next look at the WiFi specific libraries you are using for the WiFi shield.
You are using:

#include <WiFi101.h>
#include <WiFiClient.h>

The example for a web client using the WiFi shield at https://www.arduino.cc/en/Tutorial/WiFiWebClient
uses only:

#include <WiFi.h>

okay, so i decided to go with thingspeak, the api seems a bit more reliable at the current state. i have it reading all of the sensors right now at channel id: 98646 for informational interest.
and here is the sketch for anyone interested in using it.

//sketch for Thingspeak with temp/humidity/light sensors
//****************************************************
//includes
//****************************************************
#include <DHT.h>
#include <WiFi101.h>
#include <SPI.h>
//******************************************************
//define's
//******************************************************
#define DHTPIN 12     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11
// Local Network Settings
char ssid[] = "ssid";  // your network SSID (name)
char pass[] = "pass";    // your network password
int keyIndex = 0;             // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String APIKey = "APIKey";             // enter your channel's Write API Key
const int updateThingSpeakInterval = 20 * 1000; // 20 second interval at which to update ThingSpeak

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;

// Initialize Arduino Ethernet Client
WiFiClient client;
//*********************************************************
//init's
//*********************************************************
int photocellPin = A0;    // photocell sensor input
int photocellValue = 0;  // variable to store the value coming from the photocell val
// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
//************************************************************

//************************************************************
//sketch body

void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
delay(10);
  Serial.println("Testing DHT And Light Sensors!");

  dht.begin();
   // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  // you're connected now, so print out the status:
  printWifiStatus();

  Serial.println(F("Ready!"));
}

void loop() {
  // read values from pins and store as strings
  String light = String(analogRead(A0), DEC); // read light value
  // find temp value
char t_buffer[10];
char h_buffer[10];
float t = dht.readTemperature(true);
String temp=dtostrf(t,0,5,t_buffer);
//Serial.print(temp);
//Serial.print(" ");
float h = dht.readHumidity();
String humid=dtostrf(h,0,5,h_buffer);
//Serial.println(humid);
  // Print Update Response to Serial Monitor
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  // Disconnect from ThingSpeak
  if (!client.connected() && lastConnected) {
    Serial.println("...disconnected");
    Serial.println();
    client.stop();
  }
  // Update ThingSpeak
  if (!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval)) {
    updateThingSpeak("field1=" + light + "&field2=" + temp + "&field3=" + humid);
    Serial.println(light);
    Serial.println(temp);
    Serial.println(humid);
  }
  lastConnected = client.connected();
}
void updateThingSpeak(String tsData) {
  if (client.connect(thingSpeakAddress, 80)) {
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + APIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData);
    lastConnectionTime = millis();
    if (client.connected()) {
      Serial.println("Connecting to ThingSpeak...");
      Serial.println();
    }
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

so now, it comes to using the DCMotors. ill be using the adafruit 12VDC peristaltic pumps " Peristaltic Liquid Pump with Silicone Tubing - 12V DC Power : ID 1150 : $24.95 : Adafruit Industries, Unique & fun DIY electronics and kits ". and i would like to know if anyone has any sample code for monitoring the rotations on a motor?
the peristaltic pump has a 100 mL/min flow rate so im trying to find out if there is a way that i can regulate the time on/off based on “rotations” or would it have to be “time”?
i will be adding those pumps and the Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.3
https://www.adafruit.com/products/1438
to connect the motors and use a seperate 12v power.

this is the concept i’m trying to acomplish:
if light sensor reaches this level for X time = run motor for x rotations or x time
if light sensor goes below this level for x time = stop motor
if temp sensor reaches this level for X time = run motor for x rotations or x time
if temp sensor goes below this level for x time = stop motor
if humidity sensor reaches this level for X time = run motor for x rotations or x time
if humidity sensor goes below this level for x time = stop motor
if all sensors are omitted or conditions don’t apply, run motor for x time 3 times a day
calculate water usage based on rotations or time and send to thingspeak

edit: and yes, i have been going through the tutorials and example sketches in the adafruit library for the shield.