Can't compile arduino code based on SinricPro libraries - c++

I'm trying to compile my code based on SinricPro but I'm getting a huge error.
Libraries:
Wifi - 1.2.7
ArduinoJson - 6.12.0
SinricPro - 2.4.0
WebSockets - 2.2.0
Arduino board:
Node MCU with ESP8266MOD
The error:
Arduino: 1.8.13 (Windows Store 1.8.39.0) (Windows 10), Board: "NodeMCU 0.9 (ESP-12 Module), 80 MHz, 115200, 4M (3M SPIFFS)"
In file included from C:\Users\amng8\Documents\ArduinoProjects\Sinric\Sinric.ino:13:0:
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:122:5: error: 'vector' in namespace 'std' does not name a type
std::vector<SinricProDeviceInterface*> devices;
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'SinricProDeviceInterface* SinricProClass::getDevice(String)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:139:23: error: 'devices' was not declared in this scope
for (auto& device : devices) {
^
In file included from C:\Users\amng8\Documents\ArduinoProjects\Sinric\Sinric.ino:13:0:
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'DeviceType& SinricProClass::add(const char*, long unsigned int)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:211:3: error: 'devices' was not declared in this scope
devices.push_back(newDevice);
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::add(SinricProDeviceInterface*)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:219:3: error: 'devices' was not declared in this scope
devices.push_back(newDevice);
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::add(SinricProDeviceInterface&)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:226:3: error: 'devices' was not declared in this scope
devices.push_back(&newDevice);
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::handleRequest(ArduinoJson6120_000001::DynamicJsonDocument&, interface_t)':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:305:23: error: 'devices' was not declared in this scope
for (auto& device : devices) {
^
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h: In member function 'void SinricProClass::connect()':
C:\Users\amng8\Documents\Arduino\libraries\SinricPro\src/SinricPro.h:391:23: error: 'devices' was not declared in this scope
for (auto& device : devices) {
^
exit status 1
Error compiling for board NodeMCU 0.9 (ESP-12 Module).
My code:
// Uncomment the following line to enable serial debug output
#define ENABLE_DEBUG
#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include "SinricPro.h"
#include "SinricProGarageDoor.h"
#include "SinricProSwitch.h"
#define WIFI_SSID "DUMMY"
#define WIFI_PASS "DUMMY"
#define APP_KEY "DUMMY"
#define APP_SECRET "DUMMY"
#define GARAGEDOOR_ID "DUMMY"
#define SWITCH_LIGHTS_ID "DUMMY"
#define BAUD_RATE 9600
#define STATUS_LED D0
#define RELAY_1 D4
#define RELAY_2 D1
#define RELAY_3 D2
#define RELAY_4 D3
bool myPowerState = false;
bool onDoorState(const String& deviceId, bool &doorState) {
digitalWrite(RELAY_1, LOW);
delay(500);
digitalWrite(RELAY_1, HIGH);
Serial.printf("Garagedoor is %s now.\r\n", doorState?"closed":"open");
return true;
}
bool onPowerState(const String &deviceId, bool &state) {
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state?"on":"off");
myPowerState = state;
digitalWrite(RELAY_2, myPowerState?HIGH:LOW);
return true; // request handled properly
}
void setupWiFi() {
Serial.printf("\r\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) {
Serial.printf(".");
digitalWrite(STATUS_LED, HIGH);
delay(500);
digitalWrite(STATUS_LED, LOW);
delay(500);
}
IPAddress localIP = WiFi.localIP();
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]);
digitalWrite(STATUS_LED, HIGH);
}
void setupSinricPro() {
SinricProGarageDoor &myGarageDoor = SinricPro[GARAGEDOOR_ID];
myGarageDoor.onDoorState(onDoorState);
SinricProSwitch &mySwitch = SinricPro[SWITCH_LIGHTS_ID];
mySwitch.onPowerState(onPowerState);
// setup SinricPro
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); });
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); });
SinricPro.begin(APP_KEY, APP_SECRET);
}
void setup() {
pinMode(STATUS_LED, OUTPUT);
pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_2, OUTPUT);
pinMode(RELAY_3, OUTPUT);
pinMode(RELAY_4, OUTPUT);
digitalWrite(STATUS_LED, LOW);
digitalWrite(RELAY_1, HIGH);
digitalWrite(RELAY_2, HIGH);
digitalWrite(RELAY_3, HIGH);
digitalWrite(RELAY_4, HIGH);
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n");
setupWiFi();
setupSinricPro();
}
void loop() {
SinricPro.handle();
}
This error seems something from the SinricPro libraries and I can't seem to understand why is this error occurring.
GitHub issue

Related

Compilation Error Connecting ADS1115 with ESP8266

I'm getting this fatal error:
util/delay.h: No such file or directory
when compiling the below sketch:
#include <Wire.h>
#include <Adafruit_ADS1115.h>
Adafruit_ADS1115 ads;
void setup(void)
{
Serial.begin(115200);
ads.setGain(GAIN_ONE);
ads.begin();
}
void loop(void)
{
int16_t adc0, adc1, adc2, adc3;
adc0 = ads.readADC_SingleEnded(0);
Serial.print("AIN0: ");
Serial.println(adc0);
delay(1000);
}
I tried including "Arduino.h" as suggested by friends, but no use. While if I compile with "Adafruit_ADS1x15.h" instead of the above, it do upload but the ADC is not giving values.
Could anybody assist me?

How to solve conflicting declaration on the Library?

This is my code to build SHT10 reading. But I got an error message. It says that pin D1 is conflicting between Sensirion.cpp and arduino.h
#include <Sensirion.h>
#include <SensirionSHT.h>
SensirionSHT Sensor = SensirionSHT(4, 5);
long delayTime = 1;
void setup() {
Serial.begin(9600);
}
void loop() {
Sensor.tick(delayTime);
Serial.println(Sensor.getTemperature());
delay(delayTime * 1000);
}
And this is the error messages
C:\Users\ASUS\Documents\Arduino\libraries\Sensirion-master\Sensirion.cpp:52:15: error: conflicting declaration 'const float D1'
const float D1 = -40.1; // for deg C # 5V
^
In file included from C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/Arduino.h:296:0,
from C:\Users\ASUS\Documents\Arduino\libraries\Sensirion-master\Sensirion.cpp:21:
C:\Users\ASUS\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\variants\nodemcu/pins_arduino.h:41:22: error: 'D1' has a previous declaration as 'const uint8_t D1'
static const uint8_t D1 = 5;
^
exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

How to handle compile errors thrown from M5Stack libraries in Arduino

I'm currently trying to program my M5Stack with an ESP32 chip in it. I downloaded (or atleast I thought) all of the dependencies needed to upload to the board, but I can't even get my program to compile. I downloaded the ESP32 throught the board manager, I followed the M5Stack tutorial on their website and seem to be finding errors in thheir library itself. I'm not sure how to fix, below is my code and below that are the error messages im getting.
#include <M5Stack.h>
#include <Wire.h>
#define SPEAKER_PIN 25
#include "config.h"
AdafruitIO_Feed *voltage1 = io.feed("V1");
AdafruitIO_Feed *voltage2 = io.feed("V2");
AdafruitIO_Feed *curr = io.feed("Current");
void setup() {
// put your setup code here, to run once:
M5.begin(true, true, true, false);
Serial.begin(115200);
dacWrite(25,0);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextSize(5);
// wait for serial monitor to open
while(! Serial);
Serial.print("Connecting to Adafruit IO");
// connect to io.adafruit.com
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
// ads.getAddr_ADS1100(ADS1100_DEFAULT_ADDRESS);
// ads.setGain(GAIN_ONE);
// ads.setMode(MODE_CONTIN);
// ads.setRate(RATE_32);
// ads.setOSMode(OSMODE_SINGLE);
// ads.begin();
}
void loop() {
io.run();
// put your main code here, to run repeatedly:
float v1 = (float)analogRead(36) / 4096 * 17.4 * 0.975;
float v2 = (float)analogRead(35) / 4096 * 17.4 * 0.975;
float current = (float)analogRead(5);
Serial.print("v1: ");
Serial.print(v1);
Serial.println("V");
Serial.print("v2: ");
Serial.print(v2);
Serial.println("V");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(10, 10);
M5.Lcd.print("V1: ");
M5.Lcd.print(v1);
M5.Lcd.print("V");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(10, 70);
M5.Lcd.print("V2: ");
M5.Lcd.print(v2);
M5.Lcd.print("V");
M5.Lcd.setTextColor(WHITE);
M5.Lcd.setCursor(10, 140);
M5.Lcd.print("Current: ");
M5.Lcd.print(current);
M5.Lcd.print("A");
delay(500);
M5.Lcd.setCursor(10, 10);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.print("V1: ");
M5.Lcd.print(v1);
M5.Lcd.print("V");
M5.Lcd.setCursor(10, 70);
M5.Lcd.setTextColor(BLACK);
M5.Lcd.print("V2: ");
M5.Lcd.print(v2);
M5.Lcd.print("V");
M5.Lcd.setTextColor(BLACK);
M5.Lcd.setCursor(10, 140);
M5.Lcd.print("Current: ");
M5.Lcd.print(current);
M5.Lcd.print("A");
Serial.print("sending v1-> ");
Serial.println(v1);
voltage1->save(v1);
Serial.print("sending v2-> ");
Serial.println(v2);
voltage2->save(v2);
Serial.print("sending Current-> ");
Serial.println(current);
curr->save(current);
}
Error output:
Arduino: 1.8.12 (Windows 10), Board: "M5Stack-Core-ESP32, QIO, 80MHz, Default, 921600, None"
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp: In member function 'void M5Display::drawPngUrl(const char*, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t, double, uint8_t)':
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:543:3: error: 'HTTPClient' was not declared in this scope
HTTPClient http;
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:545:7: error: 'WiFi' was not declared in this scope
if (WiFi.status() != WL_CONNECTED) {
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:545:24: error: 'WL_CONNECTED' was not declared in this scope
if (WiFi.status() != WL_CONNECTED) {
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:550:3: error: 'http' was not declared in this scope
http.begin(url);
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:553:19: error: 'HTTP_CODE_OK' was not declared in this scope
if (httpCode != HTTP_CODE_OK) {
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:559:3: error: 'WiFiClient' was not declared in this scope
WiFiClient *stream = http.getStreamPtr();
^
C:\Users\graff\OneDrive\Documents\Arduino\libraries\M5Stack\src\M5Display.cpp:559:15: error: 'stream' was not declared in this scope
WiFiClient *stream = http.getStreamPtr();
^
Multiple libraries were found for "WiFi.h"
Used: C:\Users\graff\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\graff\OneDrive\Documents\Arduino\libraries\WiFi
Multiple libraries were found for "SD.h"
Used: C:\Users\graff\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Not used: C:\Users\graff\OneDrive\Documents\Arduino\libraries\SD
exit status 1
Error compiling for board M5Stack-Core-ESP32.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
First of all you should do what your compiler wants:
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This gives more details and if the solution is not working edit your question and replace the compiler output with the detailed Info.Include the missinglibs manually in your program
#include <WiFi.h>
#include <SD.h>
#include <M5Stack.h>
#include <Wire.h>
and checkthe dependencies you have in
#include "config.h"
as I could not compile due to missing file

FirebaseArduino.h:20:18: fatal error: string: No such file or directory (Arduino)

I'm developing a project using FirebaseArduino library (Realtime database) on my Arduino Uno WiFi Rev2. When I ran my code, I got a mistake as following:
#include FirebaseArduino.h
#include WiFiNINA.h
Error message:
C:\Users\Documents\Arduino\libraries\firebase-arduino-USER\master\src/FirebaseArduino.h:20:18:
fatal error: string: No such file or directory
//FirebaseArduino.h lines 17 - 23
#ifndef FIREBASE_ARDUINO_H
#define FIREBASE_ARDUINO_H
#include <string> // Error
#include "Firebase.h"
#include "FirebaseObject.h"
// my code
#include <WiFiNINA.h>
#include <FirebaseArduino.h>
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PWD"
#define FIREBASE_HOST "****"
#define FIREBASE_AUTH "****"
void setup() {
//conect wifi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Firebase.begin(FIREBASE_HOST, FAREBASE_AUTH);
}
String firebaseGet(String s)
{
String x = Firebase.getString(s);
yield();
delay(100);
return x;
delay(100);
}
void loop() {
String firebaseStatus = firebaseGet("****");
if (firebaseStatus == "ON")
{
//code to happen if the status is ON
}
else if (firebaseResult == "OFF")
{
//code to happen if the status is OFF
}
}
I found some possible problems:
1 - Arduino IDE version INCOMPATIBLE -- Tried to use 1.8.5, 1.6.12 and failed;
1.6.9 doesn't have INCOMPATIBLE problem. But it still cannot run.
2 - Should install old library of firebase -- still cannot run

A newbie and the timer module that doesn't compile

I'm totally new to C/C++. I've done some higher languages like Java and C# but that's something else I must say. I'm trying to build a timer module for the Arduino so that I can easily queue work that has to be executed after a certain amount of time without the use of delay(). I would like to create it as intuitively as possible so that I can easily re-use it.
So far I've tried a lot of different approaches. What I did is mostly read tutorials on how to achieve a certain thing in C/C++ and created my little project out of that.
Main .ino file:
#include "Timer.h"
Timer timer;
void setup()
{
// Init the timer
timer.init();
pinMode(13, OUTPUT);
// Define the state
int state = 1;
// Create the action
TimerAction action;
action.create(1000, &timerElapsed, 1 -1);
action.state = &state;
}
void loop()
{
timer.run();
}
void timerElapsed(TimerAction action) {
int *state = (int*)action.state;
if (state == 0) {
digitalWrite(13, HIGH);
*state = 1;
}
else
{
digitalWrite(13, LOW);
*state = 0;
}
}
It's very simple. I'm trying to blink the onboard led as a proof of concept.
This is the Timer.h file:
#ifndef _TIMER_h
#define _TIMER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
struct Timer {
TimerAction* actions;
uint8_t size;
void init();
void queue(TimerAction action);
void dequeue(TimerAction action);
void dequeueIdx(int idx);
void run();
};
struct TimerAction {
// Sets whether to repeat the action
uint8_t repetitive;
// Sets how many times to repeat the action, -1 for infinite
// Will only be used when repetitive == 1
long finite;
void (*callback)(TimerAction sender);
void *state;
unsigned long last;
unsigned long interval;
void create(long interval, void(*callback)(TimerAction sender), uint8_t repetitive = 0U, long finite = -1L);
};
#endif
This is the Timer.ino file:
#include "Timer.h"
void Timer::init() {
size = 0;
actions = new TimerAction[10];
}
void Timer::queue(TimerAction action) {
action.last = millis();
actions[size - 1] = action;
size++;
}
void Timer::dequeue(TimerAction action) {
for (int i = 0; i < size; i++)
if (&(actions[i]) == &action) {
memmove(actions + i, actions + i + 1, (size - (i + 1)) * sizeof(TimerAction));
break;
}
}
void Timer::dequeueIdx(int idx) {
memmove(actions + idx, actions + idx + 1, (size - (idx + 1)) * sizeof(TimerAction));
}
void Timer::run() {
for (int i = 0; i < size; i++)
if ((actions[i].last + actions[i].interval) >= millis()) {
TimerAction action = actions[i];
action.callback(action);
if (action.repetitive == 1) {
if (action.finite > 0)
action.finite--;
else
if (action.finite == 0)
dequeueIdx(i);
}
else
dequeueIdx(i);
}
}
void TimerAction::create(long _interval, void(*_callback)(TimerAction sender),
uint8_t _repetitive = 0U, long _finite = -1L) {
interval = _interval;
callback = _callback;
repetitive = _repetitive;
finite = _finite;
}
These are the errors the compiler spewed out:
Arduino: 1.6.1 (Windows 8.1), Board: "Arduino Uno"
In file included from Stoplicht.ino:1:0:
Timer.h:13:2: error: 'TimerAction' does not name a type
TimerAction* actions;
^
Timer.h:17:13: error: 'TimerAction' has not been declared
void queue(TimerAction action);
^
Timer.h:18:15: error: 'TimerAction' has not been declared
void dequeue(TimerAction action);
^
Timer.ino: In member function 'void Timer::init()':
Timer.ino:5:2: error: 'actions' was not declared in this scope
Timer.ino: At global scope:
Timer.ino:8:6: error: prototype for 'void Timer::queue(TimerAction)' does not match any in class 'Timer'
In file included from Stoplicht.ino:1:0:
Timer.h:17:7: error: candidate is: void Timer::queue(int)
void queue(TimerAction action);
^
Timer.ino:15:6: error: prototype for 'void Timer::dequeue(TimerAction)' does not match any in class 'Timer'
In file included from Stoplicht.ino:1:0:
Timer.h:18:7: error: candidate is: void Timer::dequeue(int)
void dequeue(TimerAction action);
^
Timer.ino: In member function 'void Timer::dequeueIdx(int)':
Timer.ino:24:10: error: 'actions' was not declared in this scope
Timer.ino: In member function 'void Timer::run()':
Timer.ino:29:8: error: 'actions' was not declared in this scope
Timer.ino: At global scope:
Timer.ino:45:52: error: default argument given for parameter 3 of 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
In file included from Stoplicht.ino:1:0:
Timer.h:36:7: error: after previous specification in 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
void create(long interval, void(*callback)(TimerAction sender), uint8_t repetitive = 0U, long finite = -1L);
^
Timer.ino:45:52: error: default argument given for parameter 4 of 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
In file included from Stoplicht.ino:1:0:
Timer.h:36:7: error: after previous specification in 'void TimerAction::create(long int, void (*)(TimerAction), uint8_t, long int)' [-fpermissive]
void create(long interval, void(*callback)(TimerAction sender), uint8_t repetitive = 0U, long finite = -1L);
^
Let me explain why I'm using Array over a std::vector. My chain of thought was this: the Arduino is quite weak and actions is going to be accessed a lot. So I thought it's a bit more work to implement it initially but it will make sure the timer doesn't use too much of the Arduino's resources.
I've tried a lot of things but I don't really understand where the problem lies. So that's why I'm asking an expert to look at my code and maybe put me on the right track.
In Timer.h you have:
TimerAction* actions;
At the point in time that the compiler sees that line of code it has not seen what a TimerAction is. As such it does not know what the type is and is giving you an error. What you need to do is forward declare TimerAction before Timer so the compiler knows what it is doing.
#ifndef _TIMER_h
#define _TIMER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
struct TimerAction;
struct Timer {
//...