Code Help Please: Arduino IDE, Error compiling for board SparkFun ESP8266 Thing


#1

Hi,
I’m making a greenhouse that automatically opens its windows according to temperature, waters plants according to soil moisture, and sends the temp/humidity and soil moisture data to the Cayenne web interface. I’ve been writing the code in stages (get Cayenne to recognise my Sparkfun ESP8266 board, then adding the soil moisture sensor, then the temp sensor) and have just added a servo motor and ‘if’ statement linking it to the temperature. The previous iteration with both sensors works perfectly, but this gives me the error: Error compiling for board SparkFun ESP8266 Thing. I have tried updating my boards and libraries as well as turning my computer and board off and on again. Not sure what to do now to make it compile. Any helpful hints?

Code then error message follows:

`#include <dummy.h>

#include <ESP8266httpUpdate.h>

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
//SIGNAL PINS: Sevo -> ‘ADC’, Temp/Humidity sensor -> 4, moisture sensor -> ‘0’

// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <Servo.h>

// WiFi network info.
char ssid[] = “my wifi network”;
char wifiusername[] = “my wifi network”;
char wifiPassword[] = “password”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “valid”;
char password[] = “valid”;
char clientID[] = “valid”;

int sense_Pin = A0; // sensor input at Analog pin ‘ADC’ 0 - the only one

int value = 0;

int DHpin = 4;
byte dat [5];
int tempvalue = 0;
int humvalue = 0;

int tempthreshold = 220; // a threshold level that corresponds to 22 degrees celcius for the temp sensor’s analog input

#define VIRTUAL_CHANNEL 1;
#define ACTUATOR_PIN 0;

Servo s1;

void start_test () {
digitalWrite (DHpin, LOW); // bus down, send start signal
delay (30); // delay greater than 18ms, so DHT11 start signal can be detected

digitalWrite (DHpin, HIGH);
delayMicroseconds (40); // Wait for DHT11 response

pinMode (DHpin, INPUT);
while (digitalRead (DHpin) == HIGH);
delayMicroseconds (80); // DHT11 response, pulled the bus 80us
if (digitalRead (DHpin) == LOW);
delayMicroseconds (80); // DHT11 80us after the bus pulled to start sending data

for (int i = 0; i < 4; i ++) // receive temperature and humidity data, the parity bit is not considered
dat[i] = read_data ();

pinMode (DHpin, OUTPUT);
digitalWrite (DHpin, HIGH); // send data once after releasing the bus, wait for the host to open the next Start signal
}

void setup()
{
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode (DHpin, OUTPUT); // initialize the servo pin as an output:
s1.attach(A0);
}

void loop() {
Cayenne.loop();
value = analogRead(A0);
value = value / 10;
start_test ();
tempvalue = dat [2] / 10; //convert data to variable
humvalue = dat [0] / 10;

if (tempvalue > tempthreshold) {
s1.write(30);
}

else {
s1.write(0);
}
}

byte read_data () {
byte data;
for (int i = 0; i < 8; i ++) {
if (digitalRead (DHpin) == LOW) {
while (digitalRead (DHpin) == LOW); // wait for 50us
delayMicroseconds (30); // determine the duration of the high level to determine the data is '0 'or ‘1’
if (digitalRead (DHpin) == HIGH)
data |= (1 << (7 - i)); // high front and low in the post
while (digitalRead (DHpin) == HIGH); // data '1 ', wait for the next one receiver
}
}
return data;
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. on virtual channel 0…
Cayenne.virtualWrite(1, value);
Cayenne.virtualWrite(2, tempvalue);
Cayenne.virtualWrite(3, humvalue);
Cayenne.virtualWrite(4, s1);
//Cayenne.virtualWrite(3, “Current temperature =”);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
//CAYENNE_IN_DEFAULT()


Error messages follow:

Arduino: 1.8.5 (Mac OS X), Board: “SparkFun ESP8266 Thing, 80 MHz, Flash, 512K (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

In file included from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTWiFiClient.h:21:0,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTESP8266.h:23,
from /Users/chelsea/Desktop/Moisture___Temp_Humidity___Servo/Moisture___Temp_Humidity___Servo.ino:12:
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneArduinoMQTTClient.h: In instantiation of ‘static void CayenneArduinoMQTTClient::publishData(CayenneTopic, unsigned int, const T&, const char*, const char*) [with T = Servo; CayenneTopic = CayenneTopic]’:
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneArduinoMQTTClient.h:144:52: required from ‘void CayenneArduinoMQTTClient::virtualWrite(unsigned int, const T&, const char*, const char*) [with T = Servo]’
/Users/chelsea/Desktop/Moisture___Temp_Humidity___Servo/Moisture___Temp_Humidity___Servo.ino:109:29: required from here
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneArduinoMQTTClient.h:345:3: error: no matching function for call to ‘CayenneMQTT::DataArray<>::add(const char*&, const Servo&)’
values.add(subkey, data);
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneArduinoMQTTClient.h:345:3: note: candidates are:
In file included from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/CayenneMQTTClient.h:24:0,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMessage.h:32,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneHandlers.h:29,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneArduinoDefines.h:131,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneArduinoMQTTClient.h:21,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTWiFiClient.h:21,
from /Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTESP8266.h:23,
from /Users/chelsea/Desktop/Moisture___Temp_Humidity___Servo/Moisture___Temp_Humidity___Servo.ino:12:
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:65:8: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, const char*, bool, bool) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
void add(const char* unit, const char* value, bool unitInFlash = false, bool valueInFlash = false) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:65:8: note: no known conversion for argument 2 from ‘const Servo’ to ‘const char*’
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:106:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
inline void add(const char* unit, const int value) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:106:15: note: no known conversion for argument 2 from ‘const Servo’ to ‘int’
Multiple libraries were found for “Servo.h”
Used: /Users/chelsea/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/Servo
Not used: /Applications/Arduino.app/Contents/Java/libraries/Servo
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:121:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, unsigned int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
inline void add(const char* unit, const unsigned int value) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:121:15: note: no known conversion for argument 2 from ‘const Servo’ to ‘unsigned int’
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:136:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, long int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
inline void add(const char* unit, const long value) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:136:15: note: no known conversion for argument 2 from ‘const Servo’ to ‘long int’
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:151:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, long unsigned int) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
inline void add(const char* unit, const unsigned long value) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:151:15: note: no known conversion for argument 2 from ‘const Servo’ to ‘long unsigned int’
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:167:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, float) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
inline void add(const char* unit, const float value) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:167:15: note: no known conversion for argument 2 from ‘const Servo’ to ‘float’
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:178:15: note: void CayenneMQTT::DataArray<BUFFER_SIZE, MAX_VALUES>::add(const char*, double) [with int BUFFER_SIZE = 64; int MAX_VALUES = 4]
inline void add(const char* unit, const double value) {
^
/Users/chelsea/Documents/Arduino/libraries/Cayenne-MQTT-ESP-master/src/CayenneMQTTClient/…/CayenneUtils/CayenneDataArray.h:178:15: note: no known conversion for argument 2 from ‘const Servo’ to ‘double’
exit status 1
Error compiling for board SparkFun ESP8266 Thing.`


#2

the issue is probably in this line

Cayenne.virtualWrite(4, s1);

you need to convert s1 to a number. it is currently a servo. maybe s1.read() ? I’m not sure exactly if the library lets you do that.

Otherwise you can use a variable to set the servo in the first place eg, s1.write(pos); and then send the pos variable to cayenne.