Uploading Multiple 1 wire sensors to ThingSpeak

Anyone actually done this at all ....
This code compiles OK .... but appears not to upload anything to ThingSpeak ...

What I am getting cofused with is whilst I am able to get Serial output, I do not then seem to be able to use the defined Temp1 and Temp2 as variables to update the fields in ThingSpeak .... am I asking to much from the Arduino?.

[color=green][i]Usual Ethernet Setup, and Thingspeak setup above this [/i][/color]


// 1 Wire Data wire is plugged into Digital pin 12 on the Arduino
#define ONE_WIRE_BUS 12

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

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

// Assign the addresses of the 1-Wire temp sensors.


DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

[color=green][i]Would rerally like to do it this way, as I have about 10-15 sensors longterm that I want to keep data on. This is a test bed program only. [/i][/color]

void setup(void) 


{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(Temp1, 10);
  sensors.setResolution(Temp2, 10);


 ThingSpeak.begin(client);
}

/*void printTemperature(DeviceAddress deviceAddress)
{
    
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}*/

void loop (void)
{ 
  //delay(10000);
  Serial.print("Getting temperatures...\n\r");
 /* sensors.requestTemperatures();
  
  Serial.print("Temp 1 is: ");
  printTemperature(Temp1);
  Serial.print("\n\r");
  Serial.print("Temp 2 is: ");
  printTemperature(Temp2);
  Serial.print("\n\r");
  
  Serial.print("\n\r");

  delay(200);
}
*/

//Update the ThingSpeak Channel
  
  float pinVoltage = digitalRead(12) ;
  ThingSpeak.setField(1,pinVoltage);
  
  pinVoltage = digitalRead(12) ;
  ThingSpeak.setField(2,pinVoltage);
  

  // Write the fields that you've set all at once.
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);  
  
   Serial.print("Temperatures Uploaded to Cloud...\n\r");
  delay(80000); // ThingSpeak will only accept updates every 15 seconds. 
}
[ENDCODE]

Does your code really look like that?

We do NOT want to see useless comments. We want to see ALL of your code. You can, of course, redact things like personal keys, but not whole functions.

Sorry Cut and paste from Linux not the best ...
Sketch below

/* Arduino Mega 2560 Ethernet Weather Station

  • To Upload to ThingsSpeak
  • July 2016 By John D Smith
  • */

#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ThingSpeak.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(---------------);

// Initialize Arduino Ethernet Client
EthernetClient client;

// ThingSpeak Settings
unsigned long myChannelNumber = ---------;
const char * myWriteAPIKey = "-----------------";

// There are currently 2 x Trial DS18B20 "1-Wire" digital Temperature sensors.

// 1 Wire Data wire is plugged into Digital pin 10 on the Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

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

// Assign the addresses of the 1-Wire temp sensors.

DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

void setup(void)

{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Temp1, 10);
sensors.setResolution(Temp2, 10);

ThingSpeak.begin(client);
}

void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}

void loop (void)
{
//delay(10000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();

Serial.print("Temp 1 is: ");
printTemperature(Temp1);
Serial.print("\n\r");
Serial.print("Temp 2 is: ");
printTemperature(Temp2);
Serial.print("\n\r");

Serial.print("\n\r");

delay(2000);
}

/*
//Update the ThingSpeak Channel

ThingSpeak.setField(1,Temp1);

ThingSpeak.setField(2,Temp2);

// Write the fields that you've set all at once.
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

Serial.print("Temperatures Uploaded to Cloud...\n\r");
delay(90000); // ThingSpeak will only accept updates every 15 seconds.
}
*/

Your sketch, cut & pasted from Linux:

/* Arduino Mega 2560 Ethernet Weather Station
 *  To Upload to ThingsSpeak
 *  July 2016 By John D Smith
 *  */



#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ThingSpeak.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(---------------);

// Initialize Arduino Ethernet Client
EthernetClient client;


// ThingSpeak Settings
unsigned long myChannelNumber = ---------;
const char * myWriteAPIKey = "-----------------";

// There are currently 2 x Trial DS18B20 "1-Wire" digital Temperature sensors.


// 1 Wire Data wire is plugged into Digital pin 10 on the Arduino
#define ONE_WIRE_BUS 10

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

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

// Assign the addresses of the 1-Wire temp sensors.


DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

void setup(void)


{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(Temp1, 10);
  sensors.setResolution(Temp2, 10);


 ThingSpeak.begin(client);
}

void printTemperature(DeviceAddress deviceAddress)
{
   
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop (void)
{
  //delay(10000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
 
  Serial.print("Temp 1 is: ");
  printTemperature(Temp1);
  Serial.print("\n\r");
  Serial.print("Temp 2 is: ");
  printTemperature(Temp2);
  Serial.print("\n\r");
 
  Serial.print("\n\r");

  delay(2000);
}

/*
//Update the ThingSpeak Channel
 
  ThingSpeak.setField(1,Temp1);
 
  ThingSpeak.setField(2,Temp2);
 

  // Write the fields that you've set all at once.
  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 
 
   Serial.print("Temperatures Uploaded to Cloud...\n\r");
  delay(90000); // ThingSpeak will only accept updates every 15 seconds.
}
*/

OK that is cool .... I will have to find out how that is done .....
What I want to know is probably better asked in the ThingSpeak forums ....
UNLESS there is someone that has already sorted it out here in this forum.

I am puzzled as to what I have missed from the code that causes it not to compile .... when I uncomment the Things Speak Void ...

I am puzzled as to what I have missed from the code that causes it not to compile .... when I uncomment the Things Speak Void ...

What error messages do you get?

  ThingSpeak.setField(1,Temp1);
  ThingSpeak.setField(2,Temp2);

It seems highly unlikely that setField() expects the address of a DeviceAddress object.

Your printTemperature() function needs to be deleted. You need to create another function that gets the temperature and returns a value, so loop() can pass that value to setField, so ThingSpeak can do something useful.

The below compiles without errors ... as you can see I have moved along and will come back to the 1 Wire readings ...

Code:

/* Arduino Mega 2560 Ethernet Weather Station

  • To Upload to ThingsSpeak
  • July 2016 By John D Smith
  • */

#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <ThingSpeak.h>
#include <dht.h>

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// assign an IP address for the controller:
IPAddress ip(192,168,1,180);

// Initialize Arduino Ethernet Client
EthernetClient client;

// ThingSpeak API Connection Keys
unsigned long myChannelNumber = 129223;
const char * myWriteAPIKey = "NQ93IQKXXLJTWKTW";

/* There are currently 2 x Trial DS18B20 "1-Wire" digital Temperature sensors. on Pin 10
And a DHT11 on Pin 7
*/

#define ONE_WIRE_BUS 10

dht DHT;

#define DHT11_PIN 7

// Setup a oneWire instance to communicate with any OneWire devices

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.

DallasTemperature sensors(&oneWire);

// Assign the addresses of the 1-Wire temp sensors.

DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

void setup(){
Serial.begin(9600);

sensors.begin();
sensors.setResolution(Temp1, 10);
sensors.setResolution(Temp2, 10);

ThingSpeak.begin(client);

}
void printTemperature(DeviceAddress deviceAddress)
{

float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);

}
}

void loop()
{
sensors.requestTemperatures();
// delay(100);
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temp 1 is: C: ");
Serial.println(DHT.temperature);
Serial.print("Temp 2 is: ");
printTemperature(Temp1);
Serial.print("\n\r");
Serial.print("Temp 3 is: ");
printTemperature(Temp2);
Serial.print("\n\r");
Serial.print("Humidity : %: ");
Serial.println(DHT.humidity);
Serial.print("Light : wM2: ");
int sensorValue;
sensorValue = analogRead(0);//connect UV sensors to Analog 0
Serial.println(sensorValue);//print the value to serial
Serial.print("\n\r");

//And Update the ThingSpeak Channel
int sensor1Value = (DHT.temperature);
int sensor2Value = (DHT.humidity);
long timeRead = millis();
ThingSpeak.setField(1, sensor1Value);
ThingSpeak.setField(2, sensor2Value);
ThingSpeak.setField(6, timeRead);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);

Serial.print("Data Uploaded to Cloud...\n\r");
Serial.print("\n\r");
delay(60000);
}

Yet another iteration of the same project .... which is now an Arduino acting as a an RF broadcaster .... But I still have an issue with the 1 wire side of things ....
This compiles and runs BUT...

/* Arduino Uno Weather Station
 *  433 mHz Data feed
 *   *  July 2016 By John D Smith ZL4CO
 *  */
#include <Adafruit_BMP085.h>
#include <Wire.h>
#include <DHT.h>
#include <OneWire.h>
#include <DallasTemperature.h>

/* There are currently 2 x Trial DS18B20 "1-Wire" digital Temperature sensors. on Pin 10
   And a DHT22 on Pin 7 and a UVM30A on A0
   */


#define ONE_WIRE_BUS 10

#define DHTPIN 7 
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);


// Setup a oneWire instance to communicate with any OneWire devices

OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 

DallasTemperature sensors(&oneWire);

// Assign the addresses of the 1-Wire temp sensors.


DeviceAddress Temp1 = { 0x28, 0xFF, 0x7F, 0x71, 0x2C, 0x04, 0x00, 0x79 };
DeviceAddress Temp2 = { 0x28, 0xEC, 0xAB, 0x1E, 0x00, 0x00, 0x80, 0xA8 };

void setup(){
  
  
  
  sensors.begin();
  sensors.setResolution(Temp1, 10);
  sensors.setResolution(Temp2, 10);
  
  
  dht.begin();
  delay(1000);
  Serial.begin(9600);
  
  }
void printTemperature(DeviceAddress deviceAddress)
{
    
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    

  }

 
}


 
  
void loop() 
  
{
  
  
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  delay(1000);
  float t = dht.readTemperature();
  

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
  
  Serial.print("Temp 1 is: C: ");
  Serial.println(t);
  Serial.print("Gnd Temp is: ");
  printTemperature(Temp1);
  Serial.print("\n\r");
  Serial.print("Soil Temp is: ");
  printTemperature(Temp2);
  Serial.print("\n\r");
  Serial.print("Humidity is: ");
  Serial.println(h);
  Serial.print("HeatIndex C is: ");
  Serial.println(hic);
  Serial.print("PresentUV is: ");
  int sensorValue;
  sensorValue = analogRead(0);//connect UV sensors to Analog 0    
  Serial.println(sensorValue);//print the value to serial  
  Serial.print("\n\r");
  delay(60000);

}

BUT

the 1 wire temps are ridiculous .... I can hash out the dht and the 1 wire operates all good .... what am I missing ....

the serial output is showing silly numbers for the 2 x 1 wire sensors ....

DO
I need to add delays in the bus read ....

  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  delay(1000);
  float t = dht.readTemperature();

Which of the 2 sensors are you reading from?