I define machine-level env variables using this script (run from PS ISE running as admin):
[System.Environment]::SetEnvironmentVariable('MESH_PREFIX','MACS Mesh',[System.EnvironmentVariableTarget]::Machine)
[System.Environment]::SetEnvironmentVariable('MESH_PASSWORD','test',[System.EnvironmentVariableTarget]::Machine)
Here is the platform.ini that consumes these valuse:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
monitor_speed = 115200
upload_port = COM3 ; Leaf
monitor_filters =
log2file
time
default
board_build.filesystem = littlefs
lib_ldf_mode = chain
build_flags =
-fexceptions
-D MESH_PREFIX=${sysenv.MESH_PREFIX}
-D MESH_PASSWORD=${sysenv.MESH_PASSWORD}
When I do a verbose build, I see that the MESH_PREFIX sysenv var was incorrectly read:
-DMESH_PREFIX=MACS -DMESH_PASSWORD=test
As well, I get two build failures:
lib\Protocols\MeshClient.cpp: In member function 'virtual void MacsMesh::MeshClient::DoSetup()':
<command-line>: error: 'MACS' was not declared in this scope; did you mean 'MAC0'?
lib\Protocols\MeshClient.cpp:11:25: note: in expansion of macro 'MESH_PREFIX'
11 | m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
| ^~~~~~~~~~~
<command-line>: error: 'test' was not declared in this scope
lib\Protocols\MeshClient.cpp:11:38: note: in expansion of macro 'MESH_PASSWORD'
11 | m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
| ^~~~~~~~~~~~~
I wrote this code several months ago and used it successfully for several projects. When I decided to reflash one of the same boards running this code, I found that I could no longer build.
I know you hate to hear this, but: it’s the same source code, and the same physical device. The only difference that I am aware of is that I have updated VS Code and platformio since the last time this code built.
If I remove the space, changing ‘MACS Mesh’ to ‘MACS_Mesh,’ I get the following errors:
lib\Protocols\MeshClient.cpp: In member function 'virtual void MacsMesh::MeshClient::DoSetup()':
<command-line>: error: 'MACS_Mesh' was not declared in this scope
lib\Protocols\MeshClient.cpp:11:25: note: in expansion of macro 'MESH_PREFIX'
11 | m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
| ^~~~~~~~~~~
<command-line>: error: 'test' was not declared in this scope
lib\Protocols\MeshClient.cpp:11:38: note: in expansion of macro 'MESH_PASSWORD'
11 | m_pMeshClient->init(MESH_PREFIX, MESH_PASSWORD, m_pScheduler, MESH_PORT);
| ^~~~~~~~~~~~~
I am at a loss, as this code has been working perfectly on several projects. Please advise and thanks in advance!