I have been looking at other development platforms for working on Atmel (Arduino/ATTiny) and Espressif (ESP8266) based devices. Most recently, I installed PlatformIO. But I'm having trouble with what appears to be recognition of global scope. Not sure...
I have a header file that includes a typedef for a configuration struct:
typedef struct {
char idPrefix[8];
char defPass[16];
char targetSSID[32];
char targetPass[64];
uint8_t beepInRange;
uint8_t beepOutofRange;
} devConfig;
I want to assign a config variable in my ino file:
devConfig myConfig;
but when i try to access it in my setup or loop, e.g.:
void setup() {
strncpy(myConfig.defPass, "somepass", 16);
}
It spits out the "error: 'myConfig' was not declared in this scope" when I try to platform run
Does this thing not support global variables in the same way as arduino? What am I doing wrong? Any help is appreciated.
I think you must have forgotten to add #include "Arduino.h"
header file in the main code. Also, do note that Platform IO compiles cpp files not ino file.
main.cpp
// Without Arduino.h this code will not compile
#include "Arduino.h"
#include "demo.h"
devConfig myConfig;
void setup() {
strncpy(myConfig.defPass, "somepass", 16);
}
void loop() {
}
demo.h
typedef struct {
char idPrefix[8];
char defPass[16];
char targetSSID[32];
char targetPass[64];
uint8_t beepInRange;
uint8_t beepOutofRange;
} devConfig;