httpHeader statement not working on ESP8266 shield

I’m trying to integrate a working sketch that posts data to Sparkfun’s data site and another sketch that records data of which I want to send to Sparkfun’s site. I haven’t been able to integrate it however, for various reasons including not enough memory. I have dealt with that by temporarily commenting out those parts that contribute to the memory issue, however, it still doesn’t run albeit not because of memory issues. I have troubleshooted it down to a very simple few lines of code that seemingly should work according to the working sketch, but doesn’t.

I’m using a ESP8266 Shield from Sparkfun, an Arduino Uno, a Sparkfun microSD shield and a custom PCB to interface to wires. The project measures on/off conditions of my home heating system including temperature.

I’ll include all the code up to the point at which I have discovered an anomaly between the codes. Basically, the definition of my http post statement can be sent to the serial monitor on the working sketch but does not print on the new sketch. Therefore, the new sketch will not post to the data site, whereas the working one does. The issue is not that I can’t print it to the serial monitor - the issue is that it seems to be an indication something is wrong with the statement.

The statement in question is the “String httpHeader…” statement in both. They are identical, yet the " Serial.println(httpHeader);" statement yields different results. In the nonworking code, there is no evidence of the Serial.print statement on the serial monitor at all.

This is the working code:

// The SparkFunESP8266WiFi library uses SoftwareSerial
// to communicate with the ESP8266 module. Include that
// library first:
// SoftwareSerial is required (even you don't intend on
// using it).
//#include <SoftwareSerial.h>
// Include the ESP8266 AT library:
#include <SparkFunESP8266WiFi.h>

#define SENSORPIN 0

//////////////////////////////
// WiFi Network Definitions //
//////////////////////////////
const char mySSID[] = "WesternDigital 2.4GHz";
const char myPSK[] = "XXXXXX";


////////////////////////
// Sparkfun Data Keys //
////////////////////////
const String publicKey = "2Jz1ZNKmd2F2OYz1LjAg";
const String privateKey = "XXXXXXXXXXXXXXXXX";


// Phant detsination server:
const String phantServer = "data.sparkfun.com";
String httpHeader = "POST /input/" + publicKey + ".txt HTTP/1.1\n" +
                    "Host: " + phantServer + "\n" +
                    "Phant-Private-Key: " + privateKey + "\n" +
                    "Connection: close\n" + 
                    "Content-Type: application/x-www-form-urlencoded\n";

///////////////////
// Sensor Values //
///////////////////
int waitMinutes = 2;
float sensor_value;
float voltage;


//DBB data
float postdata;
int mytime = 12;
int date = 8;
int statusB = 0;
int status1 = 1;        //Current valueS
int status2 = 2;         
int status3 = 3;
int status4 = 4;
int status5 = 5;
float temp = 100;

void setup() 
{
  int status;
  Serial.begin(9600);
  Serial.println(httpHeader);
  Serial.println(publicKey);

This is the nonworking code:

// The SparkFunESP8266WiFi library uses SoftwareSerial
// to communicate with the ESP8266 module. Include that
// library first:
// SoftwareSerial is required (even you don't intend on
// using it).
//#include <SoftwareSerial.h>
// Include the ESP8266 AT library:
#include <SparkFunESP8266WiFi.h>
#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t
//Add the SdFat Libraries
//#include "SdFat.h"
//SdFat sd;
//SdFile myFile;

//#include <SdFatUtil.h> 
#include <ctype.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const int chipSelect = 8;  //for sdfat
// Temperature data wire is plugged into port 7 on the Arduino
#define ONE_WIRE_BUS 7

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

//Create the variables to be used by SdFat Library
  char name[] = "00-00-00.CSV";     //Create an array that contains the name of our file.
  char contents[256];           //This will be a data buffer for writing contents to the file.
  char in_char=0;
  int index=0;                  //Index will keep track of our position within the contents buffer.
  int var=100;
  
//////////////////////////////
// WiFi Network Definitions //
////////////////////////////////
const char mySSID[] = "WesternDigital 2.4GHz";
const char myPSK[] = "XXXXXX";

////////////////////////
// Sparkfun Data Keys //
////////////////////////
const String publicKey = "2Jz1ZNKmd2F2OYz1LjAg";
const String privateKey = "XXXXXXXXXXXXXXXXX";


// Phant detsination server:
const String phantServer = "data.sparkfun.com";
String httpHeader = "POST /input/" + publicKey + ".txt HTTP/1.1\n" +
                    "Host: " + phantServer + "\n" +
                    "Phant-Private-Key: " + privateKey + "\n" +
                    "Connection: close\n" + 
                    "Content-Type: application/x-www-form-urlencoded\n";
  


//Pin definitions
int zone1 = 6;    // cannot use pin 1 due to serial comm
int zone2 = 2;    // Zone 2 is Pin 2
int zone3 = 3;    // Zone 3 is Pin 3
int zone4 = 4;    // Zone 4 is Pin 4
int zone5 = 5;    // Zone 5 is Pin 5
int boiler = 1;   //Boiler on-off analog pin A1
int detect = 0; //Card detect analog in A0

int prev1 = 1;        //Previous value
int prev2 = 1; 
int prev3 = 1;
int prev4 = 1;
int prev5 = 1;
int prevB = 1;

int status1 = 1;        //Current valueS
int status2 = 1;         
int status3 = 1;
int status4 = 1;
int status5 = 1;
int statusB = 1;
int statussd = 1000;

int lastOffFlag = 0;   //all zones 
long lastOff = 0;      //records the last time all zones were off
unsigned long lastDataOut = 0;

//DBB data
//float postdata;

void setup()
{
  setTime(StartHr,StartMn,StartSe,StartDay,StartMth,StartYr);   // enter start time when Uno is ready to record
  Serial.begin(9600);
 Serial.println(httpHeader);
  Serial.println(publicKey);

The serial monitor for the first working code and the nonworking serial monitor output is attached.

Note that the post statement from Serial.println(httpHeader) is complete but the output of the same statement in the nonworking output is empty for that same statement.

I cannot figure out what is different that can be causing one to post and the other not. Can anyone help?

I thank you.

Working.jpg

Nonworking.jpg

So, it turns out that if I comment out the following lines and their associated statements, the nonworking code runs:

#include <Wire.h>
#include <DS1307RTC.h>

There seems to be a conflict with these two. What’s up with that? That problem seems to be well above my pay grade!

Thanks for any help!

DS1307 uses I2C, Wire.h starts up I2C. Does the rest of your sketch if you just use DS1307?

CrossRoads:
. Does the rest of your sketch if you just use DS1307?

Crossroads: Sorry, I don't understand what you are asking.

CrossRoads:
DS1307 uses I2C, Wire.h starts up I2C. Does the rest of your sketch if you just use DS1307?

If you are asking 'does the rest of your sketch work if you only use DS1307 and not wire.h?' the answer would be no, it doesn't work with either one by themselves or together.

I found I had to get rid of:
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include “SdFat.h”

Otherwise, the http header statement would get corrupted. This statement:

String httpHeader = “POST /input/” + publicKey + “.txt HTTP/1.1\n” +
"Host: " + phantServer + “\n” +
"Phant-Private-Key: " + privateKey + “\n” +
“Connection: close\n” +
“Content-Type: application/x-www-form-urlencoded\n”;

Would get corrupted to (when sent by Serial.print(httpHeader) to the monitor as a check of its validity):

String httpHeader = “POST /input/” + publicKey + “.txt HTTP/1.1\n” +
"Host: " + phantServer + “\n” +
"Phant-Private-Key: " + privateKey + “\n” +
“Connection: close\n” +
“Content-Type: application/XXXXXXXXXXXXXXX”;

Where “XXXX” are corrupted, nonsense characters.

All that isn’t so bad for me since Data.sparkfun automatically records time and I really didn’t need to record it to SD card anyway either. So, I don’t know what the problem was, but it is no longer a problem for me!

Thanks for your efforts.