Arduino unable to compile


#1

Hello,

I am having a few issues in compiling an arduino program.
This program will compile with the arduino ide.
When I try to compile it under platform I get the following.
[09/07/17 01:28:11] Processing huzzah (platform: espressif8266; board: huzzah; framework: arduino)

Verbose mode can be enabled via -v, --verbose option
Collected 24 compatible libraries
Looking for dependencies…
Library Dependency Graph

|-- v2.6
|-- v1.0
Compiling .pioenvs\huzzah\src\main.o
Compiling .pioenvs\huzzah\FrameworkArduino\cont.o
Compiling .pioenvs\huzzah\FrameworkArduino\cont_util.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_eboot_command.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_flash_utils.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_i2s.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_main.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_noniso.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_phy.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_postmortem.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_si2c.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_timer.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_wiring.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_wiring_analog.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_wiring_digital.o
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_wiring_pulse.o
src\main.cpp: In function ‘void setup()’:
src\main.cpp:53:14: error: ‘setup_wifi’ was not declared in this scope
setup_wifi(); //setup wifi
^
src\main.cpp:55:22: error: ‘callback’ was not declared in this scope
client.setCallback(callback); // setup Mqtt callback
^
src\main.cpp: In function ‘void loop()’:
src\main.cpp:154:24: error: ‘GetTemp’ was not declared in this scope
strcpy(msg,GetTemp());
^
src\main.cpp: In function ‘char* GetTemp()’:
src\main.cpp:165:8: warning: address of local variable ‘str’ returned [-Wreturn-local-addr]
char str[8];
^
Compiling .pioenvs\huzzah\FrameworkArduino\core_esp8266_wiring_pwm.o
*** [.pioenvs\huzzah\src\main.o] Error 1
[ERROR] Took 3.34 seconds

Linter
Severity Provider Description Line
Error GCC ‘setup_wifi’ was not declared in this scope 53:14
Error Build error: ‘setup_wifi’ was not declared in this scopee 53:14
Error GCC ‘callback’ was not declared in this scope 55:22
Error Build error: ‘callback’ was not declared in this scopee 55:22
Error GCC ‘GetTemp’ was not declared in this scope 154:24
Error Build error: ‘GetTemp’ was not declared in this scopee 154:24
Warning GCC address of local variable ‘str’ returned [-Wreturn-local-addr] 165:8

Here is the code.

/*
Basic MQTT:
Setup:
const char* mqtt_server = "address of server"
char MQTTuser[15] = “server username”;
char MQTTpass[30] = “server password”;
client.setServer(address of server, port);
client.setCallback(callback); // setup Mqtt callback

void callback(char* topic, byte* payload, unsigned int length) {
Called when message sent to subscribe Topic
}

Subscribe:
client.subscribe(“Topic”)

Publish
client.publish(“Topic”,“Payload”);

*/

#include “Arduino.h”
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ESP.h>

// Update these with values suitable for your network.
const char* ssid = “YOUR SSID”;
const char* password = “YOUR AP PASSWORD”;

//MQTT Settings
//const char* mqtt_server = “192.168.1.252”;//local netwrok setting
const char* mqtt_server = “192.168.0.91”; //Golbal setting
char MQTTuser[15] = “username”;
char MQTTpass[30] = “password”;

//ESP WIFI setup from example
WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0; //Time of last message sent, used for timing
char msg[50]; //general string variable
int value = 0; //Not sure if needed… delete?
const int analogInPin = A0; // Analog input pin that the Temp Sensor is attached to
int sensorValue = 0; // value read from the pin
int DelaySec = 30; // Default number of seconds between samples
int DeviceID = ESP.getChipId();//returns the ESP8266 chip ID as a 32-bit integer.
String StrDeviceID = String(DeviceID,HEX); //convert chip ID to hex

//Setup Function
void setup() {
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
Serial.begin(115200); //Setup serial port
setup_wifi(); //setup wifi
client.setServer(mqtt_server, 1883); // setup MQTT connection
client.setCallback(callback); // setup Mqtt callback
}

// Wifi Setup Function
void setup_wifi() {

delay(10);
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”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("Device ID: ");
Serial.println(StrDeviceID);
}

//MQTT Callback function
void callback(char* topic, byte* payload, unsigned int length) {
// Display Message
Serial.print(“Message arrived [”);
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();

//*************Parsing Recieved Message
String temp = “Settings/esp8266test/” +StrDeviceID +"/SampleDelay";//Compare constant
if (strcmp(topic,temp.c_str() ) == 0){//See if the message is for this device, and for sample delay setting
//Get Payload
char num[10];
for (int i = 0; i < length; i++) {
num[i] = (char)payload[i];
}
DelaySec = atoi(num);//conver string to number
Serial.print("Delay chagned to [sec]: ");//display change
Serial.println(DelaySec);
}
}

//MQTT Connection function
void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(“Attempting MQTT connection…”);
// Attempt to connect
if (client.connect(“ESP8266Client”,MQTTuser,MQTTpass)) {
Serial.println(“connected”);
String temp = “Settings/esp8266test/” +StrDeviceID +"/SampleDelay";//topic constant
client.subscribe(temp.c_str());//subscribe to topic

}
//Errors
else {
  /*rc values on connect
  *0: Connection successful
  *1: Connection refused - incorrect protocol version
  *2: Connection refused - invalid client identifier
  *3: Connection refused - server unavailable
  *4: Connection refused - bad username or password
  *5: Connection refused - not authorised
  *6-255: Currently unused.*/

  Serial.print("failed, rc=");
  Serial.print(client.state());
  Serial.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying
  delay(5000);
}

}
}

//Main Loop
void loop() {

//Connect to MQTT SERVER

if (!client.connected()) {
reconnect();

}
client.loop();

//Wait  to  see if DelaySec has passed

long now = millis(); //delay code: millis() Returns the number of milliseconds since the Arduino board began running the current program
if (abs(now - lastMsg) > DelaySec*1000) {
lastMsg = now;
//Get temp
strcpy(msg,GetTemp());

Serial.print("Publish message: ");//Display temp
Serial.println(msg);
String temp = "devices/esp8266test/" +StrDeviceID +"/Temperature";//Topic constant
client.publish(temp.c_str(), msg);//publish msg to topic temp

}
}

//Get Temp function
char * GetTemp(void){
char str[8];
sensorValue = analogRead(analogInPin);
float temp;
temp = ((sensorValue*0.9766)-32) * 0.5556;//conver ADC read to Deg C
dtostrf(temp,1,2,str);//convert float to char[]
return str;
}

Any help would be great.

Thank you,


#3

For some reason the includes will not post
I included ESP8266WiFi.h, PubSubClient.h, and ESP.h


#4

I have this problem with this code.

The attached code builds flawlessly in Arduino after adding the two libraries as zip files.

pio builds with have C/C++ syntax errors.

Arduino:
git clone https://github.com/hallard/WebSocketToSerial.git
download and install ZIP libraries into Arduino:

https://github.com/me-no-dev/ESPAsyncWebServer/archive/master.zip
https://github.com/me-no-dev/ESPAsyncTCP/archive/master.zip

With pio, I created a project, setup the framework, board, installed the two async libraries, and moved the .ino file into src.


#5

Could you try?
http://docs.platformio.org/en/latest/platforms/espressif8266.html#using-arduino-framework-with-staging-version


#6

I ran the commands and updated the .ini file. Still get compilation problems. Works fine in Arduino.

 Compiling .pioenvs\nodemcuv2\FrameworkArduino\HardwareSerial.o
C:/Users/jmorrison/Dropbox/Arduino/WebSocketToSerial/src/WebSocketToSerial.ino:205:33: error: 'AnimationParam' does not name a type
// Use the internal hardware buffer
^
C:/Users/jmorrison/Dropbox/Arduino/WebSocketToSerial/src/WebSocketToSerial.ino:205:49: error: ISO C++ forbids declaration of 'param' with no type [-fpermissive]
// Use the internal hardware buffer
^
*** [.pioenvs\nodemcuv2\src\WebSocketToSerial.ino.o] Error 1
 [ERROR] Took 39.80 seconds

#7

Could you provide test project/archive to reproduce this issue?


#8

How do I attach a .zip file? The upload only allows pic files.


#9

You can share on https://www.dropbox.com or https://www.google.com/drive/ and post link here


#10

Was this resolved?? I have a similar issue using the readSwitch() function: Compiles fine in Arduino IDE, but give an error in PIO: src/main.cpp:622:32: error: ‘readSwitch’ was not declared in this scope


#11

@coyote Take care that you must declare all function prototypes at the beginning of your cpp file. Arduino auto-declares it for you in a pre-processing step. So if you have function void readSwitch() { /* some code */} you must put void readSwitch(); after the includes in your cpp file. This is not an error related to PlatformIO, it just gives your source files to the GCC/G++ compiler without any pre-processing done.


#12

checked that: the function declaration is not in the cpp file. It seems the Arduino IDE builds using default libraries that are not present in PIO.


#13

You should ask this with your complete code as new topic here or on https://arduino.stackexchange.com/


#14

See http://docs.platformio.org/en/latest/faq.html#convert-arduino-file-to-c-manually or change extension to main.ino.


#15

Thanks! That did the trick!