Arduino unable to compile


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
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

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:
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




#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 = “”;//local netwrok setting
const char* mqtt_server = “”; //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() {

Serial.print("Connecting to ");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.print("Device ID: ");

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

//*************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

//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)) {
String temp = “Settings/esp8266test/” +StrDeviceID +"/SampleDelay";//topic constant
client.subscribe(temp.c_str());//subscribe to topic

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.println(" try again in 5 seconds");
  // Wait 5 seconds before retrying


//Main Loop
void loop() {

//Connect to MQTT SERVER

if (!client.connected()) {


//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

Serial.print("Publish message: ");//Display temp
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,

1 Like

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

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.

git clone GitHub - hallard/WebSocketToSerial: TCP Network to Serial Proxy using WebSocket for ESP8266
download and install ZIP libraries into Arduino:

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

Could you try?

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

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

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

You can share on or Personal Cloud Storage & File Sharing Platform - Google and post link here

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

@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.

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.

You should ask this with your complete code as new topic here or on

See Redirecting... or change extension to main.ino.

Thanks! That did the trick!