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,