airgradienthq / arduino

Other
201 stars 107 forks source link

[docs] instructions to compile #160

Open hestiahacker opened 3 months ago

hestiahacker commented 3 months ago

Problem

Attempting to compile in the Arduino IDE results in the following error:

/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:40:10: fatal error: AirGradient.h: No such file or directory
   40 | #include "AirGradient.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: AirGradient.h: No such file or directory

The tactical problem issue here is that some included files are in examples/OneOpenAir, while others are in src, and Arduino IDE is not looking in all these places.

However, the core problem is I can not find instructions on how to configure the Arduino IDE to compile. Since I expect others can compile the code, I expect this is just a setup problem and not a broken codebase.

Steps to reproduce

  1. Set up Arduino IDE to compile for the ESP32 board using the instructions on the blog
  2. Install the "serial" library for Python (e.g. sudo apt install python3-serial)
  3. Checkout this repo and open ./examples/OneOpenAir/OneOpenAir.ino in the Arduino IDE
  4. Click the verify button (check mark button in the upper left of the Arduino IDE) and see the posted error above

Attempts at resolving this

I tried a number of things to resolve this.

All of the above gave same error message except the last one, which give the error message below:

/home/user/air_gradient_open_air_firmware/OneOpenAir/OneOpenAir.ino:41:10: fatal error: OtaHandler.h: No such file or directory
   41 | #include "OtaHandler.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.
exit status 1

Compilation error: OtaHandler.h: No such file or directory

Symlinking to ../examples/OneOpenAir/OtaHandler.h, ../examples/OneOpenAir/LocalServer.h and ../examples/OneOpenAir/OpenMetrics.h works around the "No such file" errors, but then exposes the more serious compilation errors below:

home/user/air_gradient_open_air_firmware/OneOpenAir/AgConfigure.cpp: In member function 'bool Configuration::parse(String, bool)':
/home/user/air_gradient_open_air_firmware/OneOpenAir/AgConfigure.cpp:277:45: error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String')
  277 |     if (jconfig[jprop_configurationControl] ==
In file included from /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/Arduino.h:192,
                 from /home/user/air_gradient_open_air_firmware/OneOpenAir/Main/PrintLog.h:4,
                 from /home/user/air_gradient_open_air_firmware/OneOpenAir/AgConfigure.h:5,
                 from /home/user/air_gradient_open_air_firmware/OneOpenAir/AgConfigure.cpp:1:
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/WString.h:211:8: note: candidate: 'bool String::operator==(const String&) const' (reversed)
  211 |   bool operator==(const String &rhs) const {
      |        ^~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/WString.h:214:8: note: candidate: 'bool String::operator==(const char*) const' (reversed)
  214 |   bool operator==(const char *cstr) const {
      |        ^~~~~~~~
In file included from /home/user/air_gradient_open_air_firmware/OneOpenAir/Libraries/Arduino_JSON/src/JSON.h:25,
                 from /home/user/air_gradient_open_air_firmware/OneOpenAir/Libraries/Arduino_JSON/src/Arduino_JSON.h:23,
                 from /home/user/air_gradient_open_air_firmware/OneOpenAir/AgConfigure.cpp:2:
/home/user/air_gradient_open_air_firmware/OneOpenAir/Libraries/Arduino_JSON/src/JSONVar.h:85:8: note: candidate: 'bool JSONVar::operator==(const JSONVar&) const'
   85 |   bool operator==(const JSONVar& v) const;
      |        ^~~~~~~~
/home/user/air_gradient_open_air_firmware/OneOpenAir/AgConfigure.cpp:286:45: error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String')
  286 |     if (jconfig[jprop_configurationControl] ==
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/WString.h:211:8: note: candidate: 'bool String::operator==(const String&) const' (reversed)
  211 |   bool operator==(const String &rhs) const {
      |        ^~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.0/cores/esp32/WString.h:214:8: note: candidate: 'bool String::operator==(const char*) const' (reversed)
  214 |   bool operator==(const char *cstr) const {
      |        ^~~~~~~~
/home/user/air_gradient_open_air_firmware/OneOpenAir/Libraries/Arduino_JSON/src/JSONVar.h:85:8: note: candidate: 'bool JSONVar::operator==(const JSONVar&) const'
   85 |   bool operator==(const JSONVar& v) const;
      |        ^~~~~~~~
/home/user/air_gradient_open_air_firmware/OneOpenAir/AgApiClient.cpp: In member function 'bool AgApiClient::postToServer(String)':
/home/user/air_gradient_open_air_firmware/OneOpenAir/AgApiClient.cpp:108:7: error: 'WiFi' was not declared in this scope
  108 |   if (WiFi.isConnected() == false) {
      |       ^~~~
/home/user/air_gradient_open_air_firmware/OneOpenAir/AgApiClient.cpp:118:3: error: 'WiFiClient' was not declared in this scope
  118 |   WiFiClient wifiClient;
      |   ^~~~~~~~~~
/home/user/air_gradient_open_air_firmware/OneOpenAir/AgApiClient.cpp:120:20: error: 'wifiClient' was not declared in this scope
  120 |   if (client.begin(wifiClient, uri.c_str()) == false) {
      |                    ^~~~~~~~~~

exit status 1

Compilation error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String')
hestiahacker commented 3 months ago

Update: I found the Flashing Of The AirGradient Firmware instructions. This resulted in a 'class Configuration' has no member named 'isOfflineMode' error message.

This is with version 3.1.0-beta.1 of the AirGradient library and commit 2e62abe2d7d8a3c549f04b78bfcff8c745ce9af0 of this repo.

The Flashing instructions say to install additional libraries listed on the top of the example code, but the example code does not specify any additional libraries to install.

home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void setup()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:184:25: error: 'class Configuration' has no member named 'isOfflineMode'
  184 |           configuration.isOfflineMode() ? "online mode" : "offline mode", "");
      |                         ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:188:25: error: 'class Configuration' has no member named 'setOfflineMode'
  188 |           configuration.setOfflineMode(!configuration.isOfflineMode());
      |                         ^~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:188:55: error: 'class Configuration' has no member named 'isOfflineMode'
  188 |           configuration.setOfflineMode(!configuration.isOfflineMode());
      |                                                       ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:192:29: error: 'class Configuration' has no member named 'isOfflineMode'
  192 |               configuration.isOfflineMode() ? " = True" : "  = False", "");
      |                             ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:201:38: error: 'class Configuration' has no member named 'isOfflineMode'
  201 |       connectToWifi = !configuration.isOfflineMode();
      |                                      ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:203:21: error: 'class Configuration' has no member named 'setOfflineModeWithoutSave'
  203 |       configuration.setOfflineModeWithoutSave(true);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:225:24: error: 'class Measurements' has no member named 'otaBootCount'; did you mean 'bootCount'?
  225 |           measurements.otaBootCount = 0;
      |                        ^~~~~~~~~~~~
      |                        bootCount
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:232:27: error: 'class AgApiClient' has no member named 'isNotAvailableOnDashboard'
  232 |             if (apiClient.isNotAvailableOnDashboard()) {
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:244:21: error: 'class OledDisplay' has no member named 'showRebooting'
  244 |         oledDisplay.showRebooting();
      |                     ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:250:21: error: 'class WifiConnector' has no member named 'hasConfigurated'
  250 |   if (wifiConnector.hasConfigurated() == false) {
      |                     ^~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:252:19: error: 'class Configuration' has no member named 'setOfflineModeWithoutSave'
  252 |     configuration.setOfflineModeWithoutSave(true);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:260:66: error: 'class Configuration' has no member named 'getDisplayBrightness'
  260 |     Serial.println("Display brightness: " + String(configuration.getDisplayBrightness()));
      |                                                                  ^~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:261:17: error: 'class OledDisplay' has no member named 'setBrightness'
  261 |     oledDisplay.setBrightness(configuration.getDisplayBrightness());
      |                 ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:261:45: error: 'class Configuration' has no member named 'getDisplayBrightness'
  261 |     oledDisplay.setBrightness(configuration.getDisplayBrightness());
      |                                             ^~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void loop()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:302:21: error: 'class Configuration' has no member named 'isOfflineMode'
  302 |   if (configuration.isOfflineMode() ||
      |                     ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void ledBarEnabledUpdate()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:465:36: error: 'class Configuration' has no member named 'getLedBarBrightness'
  465 |     int brightness = configuration.getLedBarBrightness();
      |                                    ^~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:470:18: error: 'class LedBar' has no member named 'setBrightness'; did you mean 'setBrighness'?
  470 |       ag->ledBar.setBrightness(brightness);
      |                  ^~~~~~~~~~~~~
      |                  setBrighness
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void displayExecuteOta(OtaState, String, int)':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:514:19: error: 'class OledDisplay' has no member named 'showNewFirmwareVersion'
  514 |       oledDisplay.showNewFirmwareVersion(msg);
      |                   ^~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:523:19: error: 'class OledDisplay' has no member named 'showNewFirmwareFailed'
  523 |       oledDisplay.showNewFirmwareFailed();
      |                   ^~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:533:19: error: 'class OledDisplay' has no member named 'showNewFirmwareUpdating'
  533 |       oledDisplay.showNewFirmwareUpdating(String(processing));
      |                   ^~~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:549:23: error: 'class OledDisplay' has no member named 'showNewFirmwareSuccess'
  549 |           oledDisplay.showNewFirmwareSuccess(String(i));
      |                       ^~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void oneIndoorInit()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:634:20: error: 'class StateMachine' has no member named 'executeLedBarPowerUpTest'; did you mean 'executeLedBarTest'?
  634 |       stateMachine.executeLedBarPowerUpTest();
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~
      |                    executeLedBarTest
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void configUpdateHandle()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:851:23: error: 'class Configuration' has no member named 'isLedBarBrightnessChanged'
  851 |     if (configuration.isLedBarBrightnessChanged()) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:852:25: error: 'class Configuration' has no member named 'getLedBarBrightness'
  852 |       if (configuration.getLedBarBrightness() == 0) {
      |                         ^~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:858:20: error: 'class LedBar' has no member named 'setBrightness'; did you mean 'setBrighness'?
  858 |         ag->ledBar.setBrightness(configuration.getLedBarBrightness());
      |                    ^~~~~~~~~~~~~
      |                    setBrighness
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:858:48: error: 'class Configuration' has no member named 'getLedBarBrightness'
  858 |         ag->ledBar.setBrightness(configuration.getLedBarBrightness());
      |                                                ^~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:863:23: error: 'class Configuration' has no member named 'isLedBarModeChanged'
  863 |     if (configuration.isLedBarModeChanged()) {
      |                       ^~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:864:25: error: 'class Configuration' has no member named 'getLedBarBrightness'
  864 |       if (configuration.getLedBarBrightness() == 0) {
      |                         ^~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:871:22: error: 'class LedBar' has no member named 'setBrightness'; did you mean 'setBrighness'?
  871 |           ag->ledBar.setBrightness(configuration.getLedBarBrightness());
      |                      ^~~~~~~~~~~~~
      |                      setBrighness
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:871:50: error: 'class Configuration' has no member named 'getLedBarBrightness'
  871 |           ag->ledBar.setBrightness(configuration.getLedBarBrightness());
      |                                                  ^~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:877:23: error: 'class Configuration' has no member named 'isDisplayBrightnessChanged'
  877 |     if (configuration.isDisplayBrightnessChanged()) {
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:878:19: error: 'class OledDisplay' has no member named 'setBrightness'
  878 |       oledDisplay.setBrightness(configuration.getDisplayBrightness());
      |                   ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:878:47: error: 'class Configuration' has no member named 'getDisplayBrightness'
  878 |       oledDisplay.setBrightness(configuration.getDisplayBrightness());
      |                                               ^~~~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:884:32: error: 'class Configuration' has no member named 'newFirmwareVersion'
  884 |   fwNewVersion = configuration.newFirmwareVersion();
      |                                ^~~~~~~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:887:22: error: 'class Measurements' has no member named 'otaBootCount'; did you mean 'bootCount'?
  887 |     if (measurements.otaBootCount == 0) {
      |                      ^~~~~~~~~~~~
      |                      bootCount
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:893:50: error: 'class Measurements' has no member named 'otaBootCount'; did you mean 'bootCount'?
  893 |       if ((measurements.bootCount - measurements.otaBootCount) >= (int)otaBootCount) {
      |                                                  ^~~~~~~~~~~~
      |                                                  bootCount
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:898:64: error: 'class Measurements' has no member named 'otaBootCount'; did you mean 'bootCount'?
  898 |             String(30 - (measurements.bootCount - measurements.otaBootCount)) +
      |                                                                ^~~~~~~~~~~~
      |                                                                bootCount
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:904:20: error: 'class Measurements' has no member named 'otaBootCount'; did you mean 'bootCount'?
  904 |       measurements.otaBootCount = measurements.bootCount;
      |                    ^~~~~~~~~~~~
      |                    bootCount
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void appLedHandler()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:916:21: error: 'class Configuration' has no member named 'isOfflineMode'
  916 |   if (configuration.isOfflineMode() == false) {
      |                     ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void appDispHandler()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:935:23: error: 'class Configuration' has no member named 'isOfflineMode'
  935 |     if (configuration.isOfflineMode() == false) {
      |                       ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino: In function 'void sendDataToServer()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/OneOpenAir.ino:1158:73: error: 'class Configuration' has no member named 'isOfflineMode'
 1158 |   if (configuration.isPostDataToAirGradient() == false || configuration.isOfflineMode()) {
      |                                                                         ^~~~~~~~~~~~~
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/LocalServer.cpp: In member function 'void LocalServer::_GET_config()':
/home/user/air_gradient_open_air_firmware/examples/OneOpenAir/LocalServer.cpp:45:57: error: no matching function for call to 'Configuration::toString(AgFirmwareMode&)'
   45 |     server.send(200, "application/json", config.toString(fwMode));
      |                                          ~~~~~~~~~~~~~~~^~~~~~~~
In file included from /home/user/air_gradient_open_air_firmware/examples/OneOpenAir/LocalServer.h:4,
                 from /home/user/air_gradient_open_air_firmware/examples/OneOpenAir/LocalServer.cpp:1:
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.h:67:10: note: candidate: 'String Configuration::toString()'
   67 |   String toString(void);
      |          ^~~~~~~~
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.h:67:10: note:   candidate expects 0 arguments, 1 provided

exit status 1

Compilation error: 'class Configuration' has no member named 'isOfflineMode'
hestiahacker commented 3 months ago

After some additional research, it appears the commit which added isOfflineMode (commit da6326db0fded87110163d7fc93f200afe6e202d) is only in tags 3.1.1 and 3.1.2 (as seen with git tag -l --contains da6326db0fded87110163d7fc93f200afe6e202d).

The latest version available in the Arduino Library is 3.1.0-beta.1, which is why I'm running into this issue. If the Arduino library can not be automatically released when a firmware version is released, perhaps we can add instructions on how to configure the Arduino IDE use the local git checkout instead of having to install the library with the library manager to ensure this is resolved going forward?

pnt325 commented 2 months ago

Hi @hestiahacker

You can download firmware on branch master for office release. For newest support function and bugfix on branch develop.

The Arduino IDE only get the firmware for office release after 1-2 days.

hestiahacker commented 2 months ago

The stacktrace from my previous comment was from trying to compile the firmware on the master branch.

Since then, version 3.1.3 of the library has been released and is available in the published libraries, however the master branch still does not compile, this time with a different error because the otaBootCount member doesn't exist.

The best way to solve this problem is to have the OneOpenAir.ino sketch use the local files to compile instead of requiring a library to be installed. As you seem to have indicated, the library available via the Arduino IDE will always lag behind.

My goal in opening this ticket is to ensure a new developer can always compile at least the master branch, and ideally also the develop branch as well. I have started creating this documentation, but since I am still unable to compile, clearly the documentation is not yet ready to be submitted to be merged in.

pnt325 commented 2 months ago

Hi @hestiahacker All build is worked without any problem and otaBootCount is removed from code since 3.1.3

Please follow instruction begin of file: https://github.com/airgradienthq/arduino/blob/8a83e408d3c036b089b63c053a11364b41a26092/examples/OneOpenAir/OneOpenAir.ino#L12-L27

If it's not worked, please remove the library on your PC then install again.

abstractpoint commented 2 months ago

I'm also having compile issues, and I have followed these instructions above. 3.1.3 firmware and Library. Docs for compiling is a great idea.

/Users/temp/Repositories/2024/arduino/examples/OneOpenAir/OneOpenAir.ino: In function 'void oneIndoorInit()':
/Users/temp/Repositories/2024/arduino/examples/OneOpenAir/OneOpenAir.ino:722:25: error: 'Serial0' was not declared in this scope
   if (ag->pms5003.begin(Serial0) == false) {
                         ^~~~~~~
/Users/temp/Repositories/2024/arduino/examples/OneOpenAir/OneOpenAir.ino:722:25: note: suggested alternative: 'Serial1'
   if (ag->pms5003.begin(Serial0) == false) {
                         ^~~~~~~
...
pnt325 commented 2 months ago

I'm also having compile issues, and I have followed these instructions above. 3.1.3 firmware and Library. Docs for compiling is a great idea.

/Users/temp/Repositories/2024/arduino/examples/OneOpenAir/OneOpenAir.ino: In function 'void oneIndoorInit()':
/Users/temp/Repositories/2024/arduino/examples/OneOpenAir/OneOpenAir.ino:722:25: error: 'Serial0' was not declared in this scope
   if (ag->pms5003.begin(Serial0) == false) {
                         ^~~~~~~
/Users/temp/Repositories/2024/arduino/examples/OneOpenAir/OneOpenAir.ino:722:25: note: suggested alternative: 'Serial1'
   if (ag->pms5003.begin(Serial0) == false) {
                         ^~~~~~~
...

You're missed Enable CDC On Boot

hestiahacker commented 2 months ago

I've added documentation on compiling based on what I've collected and what was said in this thread, but this project still doesn't compile.

I hope someone will be able to follow the development setup instructions and reproduce this issue so we can get to the bottom of it and get it resolved.

Still unable to compile

I have gone through the instructions for setting up a development environment again on a new machine using AirGradient Air Quality Sensor library version 3.1.3 and I am still unable to compile the firmware. I am on the "master" branch, and more specifically: on commit 3b6859f483f494d0556d36acdb95bfc3d7957f08.

/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp: In member function 'bool Configuration::parse(String, bool)':
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:277:45: error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String')
  277 |     if (jconfig[jprop_configurationControl] ==
In file included from /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.1/cores/esp32/Arduino.h:192,
                 from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Main/PrintLog.h:4,
                 from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.h:5,
                 from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:1:
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.1/cores/esp32/WString.h:211:8: note: candidate: 'bool String::operator==(const String&) const' (reversed)
  211 |   bool operator==(const String &rhs) const {
      |        ^~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.1/cores/esp32/WString.h:214:8: note: candidate: 'bool String::operator==(const char*) const' (reversed)
  214 |   bool operator==(const char *cstr) const {
      |        ^~~~~~~~
In file included from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/JSON.h:25,
                 from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/Arduino_JSON.h:23,
                 from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:2:
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/JSONVar.h:85:8: note: candidate: 'bool JSONVar::operator==(const JSONVar&) const'
   85 |   bool operator==(const JSONVar& v) const;
      |        ^~~~~~~~
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:286:45: error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String')
  286 |     if (jconfig[jprop_configurationControl] ==
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.1/cores/esp32/WString.h:211:8: note: candidate: 'bool String::operator==(const String&) const' (reversed)
  211 |   bool operator==(const String &rhs) const {
      |        ^~~~~~~~
/home/user/.arduino15/packages/esp32/hardware/esp32/3.0.1/cores/esp32/WString.h:214:8: note: candidate: 'bool String::operator==(const char*) const' (reversed)
  214 |   bool operator==(const char *cstr) const {
      |        ^~~~~~~~
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/JSONVar.h:85:8: note: candidate: 'bool JSONVar::operator==(const JSONVar&) const'
   85 |   bool operator==(const JSONVar& v) const;
      |        ^~~~~~~~
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp: In member function 'bool AgApiClient::postToServer(String)':
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp:108:7: error: 'WiFi' was not declared in this scope
  108 |   if (WiFi.isConnected() == false) {
      |       ^~~~
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp:118:3: error: 'WiFiClient' was not declared in this scope
  118 |   WiFiClient wifiClient;
      |   ^~~~~~~~~~
/home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp:120:20: error: 'wifiClient' was not declared in this scope
  120 |   if (client.begin(wifiClient, uri.c_str()) == false) {
      |                    ^~~~~~~~~~

exit status 1

Compilation error: exit status 1

If we look at there errors, we can see they match up with the source code in this repo, so this is not a matter of having outdated code.

Conflicting documentation

We also have conflicting documentation about which board to select in the Arduino IDE. Changing boards does not affect the compilation error above (all three options result in the same compilation error), but this is an additional problem related to the instructions to compile needing to be updated.

From https://www.airgradient.com/blog/install-arduino-c3-mini/ we see:

Don’t forget to select the Lolin C3 Mini board from Tools > Board > ESP 32 menu after installation.

From comments in the source code we see: Set board to "ESP32C3 Dev Module"

https://github.com/airgradienthq/arduino/blob/8a83e408d3c036b089b63c053a11364b41a26092/examples/OneOpenAir/OneOpenAir.ino#L20-L21

Then, to further complicate matters, the Arduino IDE auto-detects the device as an Adafruit QT Py ESP32-C3

mattkelly commented 2 months ago

@hestiahacker just confirming I'm seeing the exact same build errors as you. Thank you for writing up great instructions! Definitely extremely confusing trying to get started without them.

hestiahacker commented 2 months ago

Thanks for your comment, @mattkelly. I was starting to wonder if I was in the twilight zone, where the code works fine for everyone except me!

I look forward to being a regular contributor once I get set up. I'm a big fan of documentation, so whenever I can't figure some thing out, there will be a PR after I get it sorted. 🙂

mattkelly commented 2 months ago

@hestiahacker FWIW if you need help getting unblocked, here's a minimal commit off of develop to make compilation/running work:

  1. Lazily remove wifi connection check for now
  2. Fix types used for comparison
  3. C++ doesn't support designated initializers, so don't use one
hestiahacker commented 2 months ago

Thanks for the patch, @mattkelly! I can confirm that after those changes, it doesn't give me the same compilation errors. Instead, it now fails because the sketch is too big. This is true whether the "ESP32C3 Dev Module" board is selected (as the comments indicate) or when the "Lolin C3 Mini" board is selected (as the instructions indicate).

Sketch uses 1459008 bytes (111%) of program storage space. Maximum is 1310720 bytes.
Global variables use 41068 bytes (12%) of dynamic memory, leaving 286612 bytes for local variables. Maximum is 327680 bytes.
Sketch too big; see https://support.arduino.cc/hc/en-us/articles/360013825179 for tips on reducing it.
text section exceeds available space in board

Compilation error: text section exceeds available space in board

The Arduino support document didn't have any easy fixes (e.g. a compiler setting to optimize for size instead of speed).

For anyone else who is playing along at home, these changes should not be made to your source tree. It won't make any difference at all. Instead, they should be applied to the files in ~/Arduino/libraries/AirGradient_Air_Quality_Sensor/, as that's the copy that the compiler is going to use.

I'm very much looking forward to providing instructions on how to use the code in the repo instead of the library, so if anyone figures out how to do that, please let me know. Without those instructions, every API change will require releasing a new version of the library before it can be used in the code base (as opposed to adding it and using it at the same time).

mattkelly commented 2 months ago

Yup thanks for the clarification re: source tree - I've been finding my first dive into the Arduino ecosystem pretty confusing tbh!

I was also seeing the too big sketch error and honestly, I'm not sure how I got around it. I think I did an extra clean build somehow - it was a while ago now. I suspect that there's some cruft buildup happening from multiple repeated builds, not really sure yet.

stablestud commented 1 month ago

Interesting that you all used Arduino IDE to compile the project, I use PlatformIO and compilation works fine for the esp32-c3 (AirGradient ONE) environment: pio run -e esp32-c3 but not for the esp8266 environment: pio run -e esp8266 (compilation errors) It's used by old models so this was not of my concern.

@pnt325 @airgradienthq But I wonder what's the correct way of compiling the project then: Arduino IDE or PlatformIO?

To flash the device I do:

  1. Press Boot SW while plugging cable in
  2. pio run -e esp32-c3 --target upload
  3. Replug cable to reset device
  4. Done
stablestud commented 1 month ago

Additionally I added the following entries to the platformio.ini under the [env:esp32-c3] tag

board_build.flash_mode = qio
board_build.f_flash = 80000000L

Whether these are required I don't know, I simply translated the important flashing steps from OneOpenAir.ino (Arduino IDE) to PlatformIO

hestiahacker commented 1 month ago

Given that the name of the repo is "arduino", I expected the it was expected to be compiled with the Arduino IDE. I'll be interested to see what @airgradienthq has to say about this.

pnt325 commented 1 month ago

Hi @hestiahacker

You can find it on Arduino libraries with name AirGradient Air Quality Sensor. We are develop the library for Arduino, please follow the instruction on head of file to configuration Arduino before build at here. We are already test worked before release

hestiahacker commented 1 month ago

Hello @pnt325

I feel like there's been a miscommunication here. There are two issues that have not been answered.

  1. The code does not compile in the Arduino IDE. This has been verified by multiple people. If @mattkelly's patch is applied, it still does not compile because the sketch is too big as described here.
  2. Because the OneOpenAir.ino uses the library instead of the code from the repo, it's difficult for contributors to make changes to the library and test them. In order to make changes, we have to modify files in ~/Arduino/libraries/AirGradient_Air_Quality_Sensor/ as described in this comment, and then if they work, copy those change over to the checkout of this git repo, submit them without end to end testing, hope that they get accepted, and only after they are accepted and a new version of the library is released can contributors fully test their changes. If there's an error, the entire process starts over. There's also a risk of an error when we're copying the code from the libraries directory to the git checkout which wouldn't exist if we could use the code from the git checkout directly.

This ticket has been open for nearly two months and we are still unable to compile the project, which is a very frustrating experience for someone considering volunteering their time to help maintain the firmware.

airgradienthq commented 1 month ago

@hestiahacker i am using the Arduino software to compile and flash since many months with the master branch and it works just fine for me.

It's very late here but I will publish my version number and settings here tomorrow.

airgradienthq commented 1 month ago

Arduino Editor

image

Board Manager:

image

Here are my Arduino Settings:

image
airgradienthq commented 1 month ago

@hestiahacker I just re-installed my complete environment and followed these steps and 3.1.4 compiles and flashes.

I am on Mac (Ventura 13.1) and cannot test on Linux. So I'm not sure if there is a problem from that side.

hestiahacker commented 1 month ago

I set up a new computer with Arduino IDE 2.3.2 (Linux), and it doesn't compile there. There are two issues, compiler errors and a space issue. I've fixed the latter (error on my part), but the former requires code changes.

I'm using v3.1.4 of the AirGradient library.

Three compilation errors

WiFi not defined

WiFi is not declared in src/AgApiClient.cpp because neither WiFi.h nor WiFiClient.h are included in AgApiClient.cpp or AgApiClient.h

I don't understand how this is compiling on your machine.

Ambiguous overload

error: ambiguous overload for 'operator==' in AgConfigure.cpp

These errors is just a matter of casting the jconfig values to a Strings. Maybe this is a difference in compilers since it looks like you're using an old version of the Arduino IDE which was doing an implicit cast.

Designated initializers

error: 'esp_mqtt_client_config_t' has no non-static data member named 'uri'

As said previously: "C++ doesn't support designated initializers, so don't use one". The only thing I can think of is that maybe this is another difference between the versions of Arduino that we are using.

Details

Here are all the details of the compiler errors when trying to compile the master branch

Compiler errors ``` /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp: In member function 'bool Configuration::parse(String, bool)': /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:290:45: error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String') 290 | if (jconfig[jprop_configurationControl] == In file included from /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.3/cores/esp32/Arduino.h:192, from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Main/PrintLog.h:4, from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.h:5, from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:1: /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.3/cores/esp32/WString.h:211:8: note: candidate: 'bool String::operator==(const String&) const' (reversed) 211 | bool operator==(const String &rhs) const { | ^~~~~~~~ /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.3/cores/esp32/WString.h:214:8: note: candidate: 'bool String::operator==(const char*) const' (reversed) 214 | bool operator==(const char *cstr) const { | ^~~~~~~~ In file included from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/JSON.h:25, from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/Arduino_JSON.h:23, from /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:2: /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/JSONVar.h:85:8: note: candidate: 'bool JSONVar::operator==(const JSONVar&) const' 85 | bool operator==(const JSONVar& v) const; | ^~~~~~~~ /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgConfigure.cpp:298:45: error: ambiguous overload for 'operator==' (operand types are 'JSONVar' and 'String') 298 | if (jconfig[jprop_configurationControl] == /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.3/cores/esp32/WString.h:211:8: note: candidate: 'bool String::operator==(const String&) const' (reversed) 211 | bool operator==(const String &rhs) const { | ^~~~~~~~ /home/user/.arduino15/packages/esp32/hardware/esp32/3.0.3/cores/esp32/WString.h:214:8: note: candidate: 'bool String::operator==(const char*) const' (reversed) 214 | bool operator==(const char *cstr) const { | ^~~~~~~~ /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/Libraries/Arduino_JSON/src/JSONVar.h:85:8: note: candidate: 'bool JSONVar::operator==(const JSONVar&) const' 85 | bool operator==(const JSONVar& v) const; | ^~~~~~~~ /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp: In member function 'bool AgApiClient::postToServer(String)': /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp:108:7: error: 'WiFi' was not declared in this scope 108 | if (WiFi.isConnected() == false) { | ^~~~ /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp:118:3: error: 'WiFiClient' was not declared in this scope 118 | WiFiClient wifiClient; | ^~~~~~~~~~ /home/user/Arduino/libraries/AirGradient_Air_Quality_Sensor/src/AgApiClient.cpp:120:20: error: 'wifiClient' was not declared in this scope 120 | if (client.begin(wifiClient, uri.c_str()) == false) { | ^~~~~~~~~~ exit status 1 Compilation error: exit status 1 ```

Sketch too large

This was an error on my part. I had the Partition Scheme set to the default instead of the "Minimal SPIFFS..." option. Once I fixed that, I was able to compile my fork (with @mattkelly's patch). To be clear, I could still not compile the master branch of this repo (airgradienthq/arduino) due to the compilation errors described above.

Note: This Partition Scheme setting got reset to the default when I was switching between the "Wemos D1 Mini" board that the documentation says should be selected and the "ESP32C3 Dev Module" that the comments say should be selected.

stablestud commented 1 month ago

What about using PlatformIO as official way? What purpose has the current PlatformIO config file?