danjulio / MPPT-Solar-Charger

Supporting documentation and software for the MPPT Solar Charger
141 stars 33 forks source link

Compiling the ESP8266 code for ESP32 (M5Stamp C3 Mate) #5

Open adrian0 opened 8 months ago

adrian0 commented 8 months ago

Hi Dan, I wonder if it's possible to get the sample code running on ESP32s

Swapping out the ESP8266WiFi.h for the regular WiFi.h library is the one obvious change. But I can't work out how to get past the compilation errors with mpptChg.h

/Users/goldie/Downloads/MPPT-Solar-Charger-master/examples/esp8266/esp8266_solar_data/esp8266_solar_data.ino: In function 'void setup()':
/Users/goldie/Downloads/MPPT-Solar-Charger-master/examples/esp8266/esp8266_solar_data/esp8266_solar_data.ino:129:29: error: no matching function for call to 'mpptChg::begin(int, int)'
   chg.begin(SDA_PIN, SCL_PIN);
                             ^
In file included from /Users/goldie/Downloads/MPPT-Solar-Charger-master/examples/esp8266/esp8266_solar_data/esp8266_solar_data.ino:1:
/Users/goldie/Dropbox/Personal Docs/Arduino/libraries/mpptChg/mpptChg.h:173:8: note: candidate: 'bool mpptChg::begin()'
   bool begin();
        ^~~~~
/Users/goldie/Dropbox/Personal Docs/Arduino/libraries/mpptChg/mpptChg.h:173:8: note:   candidate expects 0 arguments, 2 provided
/Users/goldie/Downloads/MPPT-Solar-Charger-master/examples/esp8266/esp8266_solar_data/esp8266_solar_data.ino: In function 'void publish_data(int)':
/Users/goldie/Downloads/MPPT-Solar-Charger-master/examples/esp8266/esp8266_solar_data/esp8266_solar_data.ino:267:33: error: call of overloaded 'publish(int16_t&)' is ambiguous
       if (!chg_ib.publish(reg_ib)) {
                                 ^
In file included from /Users/goldie/Downloads/MPPT-Solar-Charger-master/examples/esp8266/esp8266_solar_data/esp8266_solar_data.ino:29:
/Users/goldie/Dropbox/Personal Docs/Arduino/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h:274:8: note: candidate: 'bool Adafruit_MQTT_Publish::publish(double, uint8_t)'
   bool publish(
        ^~~~~~~
/Users/goldie/Dropbox/Personal Docs/Arduino/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h:279:8: note: candidate: 'bool Adafruit_MQTT_Publish::publish(int32_t)'
   bool publish(int32_t i);
        ^~~~~~~
/Users/goldie/Dropbox/Personal Docs/Arduino/libraries/Adafruit_MQTT_Library/Adafruit_MQTT.h:280:8: note: candidate: 'bool Adafruit_MQTT_Publish::publish(uint32_t)'
   bool publish(uint32_t i);
        ^~~~~~~

exit status 1

Compilation error: no matching function for call to 'mpptChg::begin(int, int)'
danjulio commented 8 months ago

The Arduino library was written with conditional code for the ESP8266 allowing specifying the I2C pins in the begin() method so it won't compile with that code for the ESP32. Try changing the

#ifdef ESP8266

to

#ifdef ESP32

in the mpptChg.cpp and mpptChg.h files in your Arduino library installation.

I'm currently on holiday so can't test this for a while but update this if it works (or what it takes to get it to work) and we can update the Arduino library to support both ESP8266 and ESP32.

adrian0 commented 7 months ago

NoteToSelfSoThatIDontForget

Changing the ifdef statement to ESP32 seems to highlight that the variable types used for the ESP8266 library don't work for the ESP32. Ran out of time before having to travel for work. When back home, I need to work a bit more on the variable types for ESP32.