Platformio portable user config help prod_env.ini

Hello,
I would love to be able to create a portable configuration as suggested in the documentation, but I am not able to build using the file I have created.

Could someone please help me format it properly?
I tried my best to follow the directions, but I cannot seem to get it right (I get stuck at ‘building’, perpetual pinwheel.).

Any help would be greatly appreciated in understanding the way this configuration should be made.

I have a heltec board:
heltec-wifi-lora-32-915

and would like to enable the following features:
bme280
TSL2561
LORA
BT

Here is my my_prod_env.ini:

[platformio]
default_envs = heltec-wifi-lora-32-915-ota

[env:heltec-wifi-lora-32-915]
extends = env:heltec-wifi-lora-32-915
lib_deps =
;  ${com-esp.lib_deps}
  ${env.lib_deps}              ; Inherit all the library dependencies from [env]
  ${libraries.wifimanager32}   ; Add another library dependency on top of them
  ${libraries.lora}
  ${libraries.bme280}
  ${libraries.TSL2561}
build_flags =
;  ${com-esp.build_flags}
  ${env.build_flags}           ; Inherit all the build flags from [env]
  '-DZgatewayLORA="LORA"'      ; Add some of our own build flags
  '-DLORA_BAND=915E6'
  '-DGateway_Name="OMG_1"'
  '-DZgatewayBT="BT"'
  '-DLED_SEND_RECEIVE=25'
  '-DTimeLedON=0.1'
  '-DLED_SEND_RECEIVE_ON=1'
  '-DZsensorBME280="BME280"'
  '-DZsensorTSL2561="TSL2561"'
  '-DMQTT_USER="REDACTED"'
  '-DMQTT_PASS="REDACTED"'
  '-DMQTT_SERVER="mqttserver.local"'
  '-Dota_password="otapassword"'
  '-UZmqttDiscovery'
  
[env:heltec-wifi-lora-32-915-ota]
extends = env:nodemcuv2-pilight-bme280
upload_protocol = espota
upload_port = OpenMQTTGateway.local
upload_flags =
  --auth=otapassword
  --port=8266

Thanks in advance!

Hi @Refuge, you’re using extends = with the same env as you’re defining in your custom env. I would also rename your custom environment to not clarify it in the build option listing. I’m also not sure why your [env:heltec-wifi-lora-32-915-ota] is using extends = env:nodemcuv2-pilight-bme280. is it a completely separate environment you want to define here, or just to add the OTA possibility to the above environment?

My suggestion would be to define everything in one environment with a unique env name. e.g.

[env:heltec-wifi-lora-32-915-YOURS]
platform = ${com.esp32_platform}
board = heltec_wifi_lora_32
lib_deps =
  ${com-esp.lib_deps}
  ${libraries.wifimanager32}
  ${libraries.lora}
  ${libraries.bme280}
  ${libraries.TSL2561}
build_flags =
  ${com-esp.build_flags}
  '-DZgatewayLORA="LORA"'
  '-DLORA_BAND=915E6'
  '-DGateway_Name="OpenMQTTGateway_ESP32_LORA"'
  '-DLED_SEND_RECEIVE=25'
  '-DTimeLedON=0.1'
  '-DLED_SEND_RECEIVE_ON=1'
  '-DZsensorBME280="BME280"'
  '-DZsensorTSL2561="TSL2561"'
  '-DMQTT_USER="REDACTED"'
  '-DMQTT_PASS="REDACTED"'
  '-DMQTT_SERVER="mqttserver.local"'
  '-Dota_password="otapassword"'
  '-UZmqttDiscovery'
upload_protocol = espota
upload_port = OpenMQTTGateway_ESP32_LORA.local
upload_flags =
  --auth=otapassword
  --port=8266

With all the OTA details commented out the first time you upload via cable, then afterward uncommenting them to allow for future OTA.

Of the shorter version with extends and using the default env lib_deps and build_flags

[env:heltec-wifi-lora-32-915-YOURS]
extends = env:heltec-wifi-lora-32-915
lib_deps =
  ${env:heltec-wifi-lora-32-915.lib_deps}
  ${libraries.bme280}
  ${libraries.TSL2561}
build_flags =
  ${env:heltec-wifi-lora-32-915.build_flags}
  '-DZsensorBME280="BME280"'
  '-DZsensorTSL2561="TSL2561"'
  '-DMQTT_USER="REDACTED"'
  '-DMQTT_PASS="REDACTED"'
  '-DMQTT_SERVER="mqttserver.local"'
  '-Dota_password="otapassword"'
  '-UZmqttDiscovery'
upload_protocol = espota
upload_port = OpenMQTTGateway_ESP32_LORA.local
upload_flags =
  --auth=otapassword
  --port=8266

I didn’t really check for any additional BT requirement and if LORA and BT are mutually compatible with the heltec, but I hope the above gets you closer to what you’re looking for.

Thank you for your help!

I’m not sure I understand the structure of this file; or how to set it up.

I just tried to copy paste from different examples to see if i could figure it out. Your explanation helped a bit but this is still very confusing for me. At least it seems to make sense to the compiler…

I’ll give this a shot, but an ELI5 for how this file is to be configured would be awesome.

Also, i’m not sure how to comment out, is that the semicolon?
I’m not sure i understand how to upload the second time if it was commented out the first time… am I missing something?

Thank you! again

For starters it’s best to stick to the first example above, and ignore the second one using the extends and using the default env lib_deps and build_flags, until you get more familiar with the whole process.

Initially you copy and paste a whole environment which is closest to what you want/need from platformio.ini (in your case this was '[env:heltec-wifi-lora-32-915]`) and give it a slightly different name to make it unique. Then you add any additional appropriate lib_deps and/or build_flags according to your additional needs, for you these were

'-DZsensorBME280="BME280"'
'-DZsensorTSL2561="TSL2561"'

and other extras like the OTA details etc.

That’s correct - the semicolon to comment out/

The first time you need to comment out all the OTA details

;upload_protocol = espota
;upload_port = OpenMQTTGateway_ESP32_LORA.local
;upload_flags =
;  --auth=otapassword
;  --port=8266

, but leave the build_flag

'-Dota_password="otapassword"'

so as to send the OTA password the first time to the heltec, so that future OTA connections will actually work :wink:

You possibly need an extra upload_port line with

upload_port = /dev/cu......

depending on which OS you are using and how the heltec ESP32 gets recognised by it.

Once the initial serial cable upload has succeeded you can comment out/delete the

upload_port = /dev/cu......

line again and uncomment all the OTA lines for all future OTA updates.

upload_protocol = espota
upload_port = OpenMQTTGateway_ESP32_LORA.local
upload_flags =
  --auth=otapassword
  --port=8266

Hope this makes things a bit clearer :slight_smile: also this thread might give you possible future hints for your portable configuration setup.

1 Like

Thank you for this!

I’ll give it a shot and report back.
Thank you!