Unable to get Thermistor Data

I'm trying to get Thermistor data to upload into ThingSpeak but so far I get only nulls from the Thermistor. Here's my code:

#include <SPI.h>
#include <Ethernet.h>

#include <Thermistor.h>
Thermistor temp(0);

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "XXXXXXXX";
const int updateThingSpeakInterval = 16 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)

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

// Initialize Arduino Ethernet Client
EthernetClient client;

void setup()
{

// Start Serial for debugging on the Serial Monitor
Serial.begin(9600);

// Start Ethernet on Arduino
startEthernet();
}

void loop()
{

int temperature = temp.getTemp();

// Read value from Analog Input Pin 0
//String analogValue0 = String(analogRead(A0), DEC);

// 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="+temperature);
}

// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {startEthernet();}

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: "+writeAPIKey+"\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();
failedCounter = 0;
}
else
{
failedCounter++;

Serial.println("Connection to ThingSpeak failed ("+String(failedCounter, DEC)+")");
Serial.println();
}

}
else
{
failedCounter++;

Serial.println("Connection to ThingSpeak Failed ("+String(failedCounter, DEC)+")");
Serial.println();

lastConnectionTime = millis();
}
}

void startEthernet()
{

client.stop();

Serial.println("Connecting Arduino to network...");
Serial.println();

delay(1000);

// Connect to network amd obtain an IP address using DHCP
if (Ethernet.begin(mac) == 0)
{
Serial.println("DHCP Failed, reset Arduino to try again");
Serial.println();
}
else
{
Serial.println("Arduino connected to network using DHCP");
Serial.println();
}

delay(1000);
}

But if I run this by itself

#include <Thermistor.h>
Thermistor temp(0);
void setup() {
Serial.begin(9600);
}
void loop() {
int temperature = temp.getTemp();
Serial.print("The sensor temperature is: ");
Serial.print(temperature);
Serial.println("*C");
delay(1000);
}

I've no issue getting the Temperature readings...

Any advice is greatly appreciated.

Thank you!

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the "Code" button above the posting area (It looks like a scroll with < > inside it).

How to use this forum

void updateThingSpeak(String tsData)

This function takes a String as a parameter, but when you call it like this

updateThingSpeak("field1="+temperature);

You try to concatenate some text with an integer which will not produce a String.

You try to concatenate some text with an integer which will not produce a String.

There is no concatenation going on. + is the addition operator. So, he is trying to ADD a value to the address where the string literal is stored. Then, that offset address is treated as a String. No wonder it's garbage.

Hi,
Can you go back and edit your post with.

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom...... :slight_smile:

he is trying to ADD a value to the address where the string literal is stored.

I bet he is trying to concatenate them rather than add them. Either way, it's rubbish.

I bet he is trying to concatenate them

Wishing won't make it so.