0

I'm a beginer, did some tests with uno and now have a Wemos D1R2 on my hands... I'm building a sort of weather station that will send data to thingspeak.com and log this data there. I managed to merge 2 examples together (1 to send data to thingspeak) and (1 to read 1 DS18B20 with onewire) I now need to connect 2 or more DS18B20 sensors on the same Onewire BUS (I also managed to do this using this tutorial http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#mult ), the readings come alright on serial monitor but when I try to send the readings to thingspeak a get a error:

temp_logger_multime_sensors_2:174: error: statement cannot resolve address of overloaded function

Serial.print printTemperature(Probe01);

My piece of code:

/* References
    DHT11 sensor data to Thingspeak using a Wemos D1
    http://www.esp8266learning.com/dht11-sensor-data-to-thingspeak-using-a-wemos-d1.php#codesyntax_3

   Rui Santos - Complete project details at http://randomnerdtutorials.com

   YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
   http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#mult
   V1.01  01/17/2013 ...based on examples from Rik Kretzinger
*/

#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// replace with your channel’s thingspeak API key and your SSID and password
String apiKey = "THINGSPEAKKEY"; 
const char* ssid = "WIFINAME";
const char* password = "WIFIPASSWORD";
const char* server = "api.thingspeak.com";

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 5

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

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

DeviceAddress Probe01 = { 0x28, 0xFF, 0x51, 0xA5, 0x61, 0x16, 0x03, 0x92 }; // probe 1
DeviceAddress Probe02 = { 0x28, 0xFF, 0xF8, 0x99, 0x52, 0x16, 0x04, 0xB1 }; // probe 2

WiFiClient client;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
    Serial.begin(115200);
  delay(10);

/*  Serial.begin(9600);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  */
  // Initialize the Temperature measurement library
  sensors.begin();

 WiFi.begin(ssid, password);

  // Connecting to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected on IP ...");
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());
}  

/*-----( Declare User-written Functions )-----*/
  void printTemperature(DeviceAddress deviceAddress)
  {
  float tempC = sensors.getTempC(deviceAddress);
     if (tempC == -127.00) 
     {
     Serial.print("Error getting temperature  ");
     } 
     else
     {
     Serial.print(tempC);
     }
  }// End printTemperature

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(1000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   

  // Command all devices on bus to read temperature  

  sensors.requestTemperatures();  

float StrProbe01 = printTemperature(Probe01); //THINK PROBLEM IS HERE
float StrProbe02 = printTemperature(Probe02); //AND HERE

  Serial.print("Probe 01 temperature is:   ");
    printTemperature(Probe01);  //<-- THIS PART WORKS
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
    printTemperature(Probe02);

  Serial.println();

if (client.connect(server,80)) {
  String postStr = apiKey;
  postStr +="&field1=";
  postStr += float(StrProbe01);
  postStr +="&field2=";
   postStr += float(StrProbe02);
  postStr += "\r\n\r\n";

  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(postStr.length());
  client.print("\n\n");
  client.print(postStr);

  Serial.print("Temperature: ");
  Serial.print printTemperature(Probe01);
  Serial.print(" degrees Celsius Humidity: ");
  Serial.print printTemperature(Probe02);
  Serial.println("Sending data to Thingspeak");
  }
  client.stop();

  Serial.println("Waiting 20 secs");
  // thingspeak needs at least a 15 sec delay be een updates
  // 20 seconds to be safe
  delay(20000);

}//--(end main loop )---

I suspect I have to transform printTemperature(Probe01); into a variable first (as you can see on the code) and use this variable on postStr += StrProbe01; as but I tried as you can see on the code and it didnt work either.

* UPDATE * The code below works sending data to thingspeak and serial monitor fine with 1 DS18B20

#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// replace with your channel’s thingspeak API key and your SSID and password
String apiKey = "THINGSPEAKKEY"; 
const char* ssid = "WIFINAME";
const char* password = "WIFIPASSWORD";
const char* server = "api.thingspeak.com";

const char* t2 = "5";
const char* h2 = "12.34";

//START DS18B20 Stuff
// Data wire is plugged into pin D1 on the ESP8266 12-E - GPIO 5
#define ONE_WIRE_BUS 5  // DS18B20 pin

// 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 DS18B20(&oneWire);
char temperatureCString[6];
char temperatureFString[6];

//END DS18B20 stuff

WiFiClient client;

void setup() 
{
Serial.begin(115200);
delay(10);

// dht.begin();
DS18B20.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement

WiFi.begin(ssid, password);

// Connecting to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) 
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected on IP ...");
// Printing the ESP IP address
Serial.println(WiFi.localIP());
}

void getTemperature() {
  float tempC;
  float tempF;
  do {
    DS18B20.requestTemperatures(); 
    tempC = DS18B20.getTempCByIndex(0);
    dtostrf(tempC, 2, 2, temperatureCString);
    tempF = DS18B20.getTempFByIndex(0);
    dtostrf(tempF, 3, 2, temperatureFString);
    delay(100);
  } while (tempC == 85.0 || tempC == (-127.0));
}

// runs over and over again
void loop() 
{

 getTemperature();

if (client.connect(server,80)) {
String postStr = apiKey;
postStr +="&field1=";
postStr += String(temperatureCString);
postStr +="&field2=";
postStr += String(temperatureFString);
postStr += "\r\n\r\n";

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(postStr.length());
client.print("\n\n");
client.print(postStr);

Serial.print("Temp in C: ");
Serial.print(temperatureCString);
Serial.print(" and Temp in F: ");
Serial.print(temperatureFString);
Serial.println("Sending data to Thingspeak");
}
client.stop();

Serial.println("Waiting 20 secs");
// thingspeak needs at least a 15 sec delay be een updates
// 20 seconds to be safe
delay(20000);
}

And this code works fine displaying 2 DS18B20 on serial monitor connected to 1 Onewire BUS, but I need to implement (uncomment) the thingspeak part now.

#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// replace with your channel’s thingspeak API key and your SSID and password
String apiKey = "THINGSPEAKKEY"; 
const char* ssid = "WIFINAME";
const char* password = "WIFIPASSWORD";
const char* server = "api.thingspeak.com";

/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 5

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

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

DeviceAddress Probe01 = { 0x28, 0xFF, 0x51, 0xA5, 0x61, 0x16, 0x03, 0x92 }; // probe 1
DeviceAddress Probe02 = { 0x28, 0xFF, 0xF8, 0x99, 0x52, 0x16, 0x04, 0xB1 }; // probe 2

WiFiClient client;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
    Serial.begin(115200);
  delay(10);

  // Initialize the Temperature measurement library
  sensors.begin();

 WiFi.begin(ssid, password);

  // Connecting to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected on IP ...");
  // Printing the ESP IP address
  Serial.println(WiFi.localIP());

}  //--(end setup )---

/*-----( Declare User-written Functions )-----*/
  void printTemp(DeviceAddress deviceAddress)
  {
  float tempC = sensors.getTempC(deviceAddress);
     if (tempC == -127.00) 
     {
     Serial.print("Error getting temperature  ");
     } 
     else
     {
     Serial.print(tempC);
     }
  }// End printTemp

void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(1000);
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   

  // Command all devices on bus to read temperature  

  sensors.requestTemperatures();  

  Serial.print("Probe 01 temperature is:   ");
    printTemp(Probe01);
  Serial.println();

  Serial.print("Probe 02 temperature is:   ");
    printTemp(Probe02);

  Serial.println();

/*
if (client.connect(server,80)) {
  String postStr = apiKey;
  postStr +="&field1=";
  postStr += float(StrProbe01);
  postStr +="&field2=";
   postStr += float(StrProbe02);
  postStr += "\r\n\r\n";

  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(postStr.length());
  client.print("\n\n");
  client.print(postStr);

  Serial.print("Temperature: ");
  Serial.print printTemp(Probe01);
  Serial.print(" degrees Celsius Humidity: ");
  Serial.print printTemp(Probe02);
  Serial.println("Sending data to Thingspeak");
  }
  client.stop();

  Serial.println("Waiting 20 secs");
  // thingspeak needs at least a 15 sec delay be een updates
  // 20 seconds to be safe
  delay(20000);
 */
}//--(end main loop )---

It has all to do on generate a sort of variable (perhaps float , im not sure) and passing it as a http string

Thanks

  • Your question would benefit greatly from a [stackoverflow.com/help/mcve](minimal, complete, verifiable example) since the problem you have is with code you haven't posted. It would also be helpful to post the version (again, minimal, complete and verifiable) which does work. – Mark Smith Feb 2 '17 at 10:50
  • @MarkSmith sorry about that, I tried to shorten the code but get that would be hard to simulate.. here goes the whole code (I tried to clear as much as possible) the problem start ater sensors.requestTemperatures(); when I add the Thingspeak section – Diego Feb 2 '17 at 12:23
0

Since the DeviceInformation variables are not POD (Plain Old Data) it would be slightly more efficient to use references or pointers, this will avoid copying them around. If you do that you could make you global variables Probe01 and Probe02 const variables.

In loop around line 98 you call printTemperature() and assign the return value to a float. Which is very strange, because around line 72 you define void printTemperature(). So I suspect there may be a function in the Dalas library call printTemperature that returns a float and this is the overloaded function it is talking about.

So to fix it change the name of you printTemperature function and change the two lines it is called on. Hopefully that will fix this problem.

  • Thanks @Matt , but like I said I am starting in the world of C and arduino, I am barelly merging samples from internet together and trying to make them work :) I updated my post with 2 codes that I got running, 1 code read ONE temp sensor and display on serial monitor and also send to thingspeak platform another code is able to read 2 sensors on the same bus, but I cannot manage to get this 2 readings to send over thingspeak – Diego Feb 2 '17 at 13:21
  • 1
    Possibly can use :: notation to qualify printTemperature(), ie to indicate which namespace to use. See eg namespace and name lookup at cppreference.com – James Waldby - jwpat7 Feb 2 '17 at 17:54
0

Re your edit : I'd create a new project and put just the commented out code in setup (and the minimum you need to get it working) and then post the problems you have with that.

I can't see any compile problems, but the data you are sending to thingspeak doesn't look right. I think you are sending:

String postStr = apiKey + "&field1=" + float(StrProbe01) + "&field2=" + float(StrProbe02) + "\r\n\r\n";

And I think you should be sending:

String postStr = "field1=" + float(StrProbe01) + "&field2=" + float(StrProbe02) + "\r\n\r\n";

(Based on this example Arduino.cc)

0

In the code that works, you have:

if (client.connect(server,80)) {
String postStr = apiKey;
postStr +="&field1=";
postStr += String(temperatureCString);
postStr +="&field2=";
postStr += String(temperatureFString);
postStr += "\r\n\r\n";

In the code that does not work you are doing this:

if (client.connect(server,80)) {
  String postStr = apiKey;
  postStr +="&field1=";
  postStr += float(StrProbe01);
  postStr +="&field2=";
   postStr += float(StrProbe02);
  postStr += "\r\n\r\n";

Print out the both the Strings that you are sending, postStr, using Serial.print. Compare the result. I'm not at home at the moment to try it out, but I'm sure the float(StrProbe01) and float(StrProbe02) is wrong. Thingspeak explains in their guidelines what the string that you are sending should look like.

0

Try returning float from printTemp:

 /*-----( Declare User-written Functions )-----*/
  float printTemp(DeviceAddress deviceAddress)
  {
  float tempC = sensors.getTempC(deviceAddress);
     if (tempC == -127.00) 
     {
     Serial.print("Error getting temperature  ");
     } 
     /* else
     {
     Serial.print(tempC);
     }
     */ you won't be needing this
     return tempC;
  }// End printTemp

And call it as you would in your commented example. I suspect that it is not the most efficient way, but it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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