Xinyuan-LilyGO / LilyGo-EPD-4-7-OWM-Weather-Display

Using the LilyGo EPD 4.7" display to show OWM Weather Data
65 stars 27 forks source link

Doesn't compile on IDE 2.0.4 #3

Closed dreamy1 closed 1 year ago

dreamy1 commented 1 year ago

Hello,

i installed all libs, but the compiler does an exit with al lot of errors:

`In file included from c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:37, from c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9, from C:\Users\Admin\Documents\Arduino\Libraries\LilyGo-EPD-4-7-OWM-Weather-Display-1-main\OWM_EPD47_epaper_v2.5\OWM_EPD47_epaper_v2.5.ino:12: c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp: In instantiation of 'static T ArduinoJson6201_F1::Converter<T, Enable>::fromJson(ArduinoJson6201_F1::JsonVariantConst) [with T = char; Enable = void]': c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/VariantRefBase.hpp:52:34: required from 'typename ArduinoJson6201_F1::enable_if<(! ArduinoJson6201_F1::ConverterNeedsWriteableRef::value), T>::type ArduinoJson6201_F1::VariantRefBase::as() const [with T = char; TDerived = ArduinoJson6201_F1::MemberProxy<ArduinoJson6201_F1::ElementProxy<ArduinoJson6201_F1::MemberProxy<ArduinoJson6201_F1::JsonObject, const char> >, const char>; typename ArduinoJson6201_F1::enable_if<(! ArduinoJson6201_F1::ConverterNeedsWriteableRef::value), T>::type = char]' C:\Users\Admin\Documents\Arduino\Libraries\LilyGo-EPD-4-7-OWM-Weather-Display-1-main\OWM_EPD47_epaper_v2.5\OWM_EPD47_epaper_v2.5.ino:194:72: required from here c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:24:20: error: no matching function for call to 'convertFromJson(ArduinoJson6201_F1::JsonVariantConst&, char&)' convertFromJson(src, result); // Error here? See https://arduinojson.org/v6/unsupported-as/


c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:264:13: note: candidate: 'void ArduinoJson6201_F1::convertFromJson(ArduinoJson6201_F1::JsonVariantConst, String&)' <near match>
 inline void convertFromJson(JsonVariantConst src, ::String& dst) {
             ^~~~~~~~~~~~~~~
c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:264:13: note:   conversion of argument 2 would be ill-formed:
c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:24:26: error: cannot bind non-const lvalue reference of type 'String&' to an rvalue of type 'String'
     convertFromJson(src, result);  // Error here? See https://arduinojson.org/v6/unsupported-as/
                          ^~~~~~
In file included from C:\Users\Admin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\cores\esp32/Arduino.h:176,
                 from C:\Users\Admin\Documents\Arduino\Libraries\LilyGo-EPD-4-7-OWM-Weather-Display-1-main\OWM_EPD47_epaper_v2.5\OWM_EPD47_epaper_v2.5.ino:5:
C:\Users\Admin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\cores\esp32/WString.h:59:9: note:   after user-defined conversion: 'String::String(const char*)'
         String(const char *cstr = "");
         ^~~~~~
In file included from c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:37,
                 from c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,
                 from C:\Users\Admin\Documents\Arduino\Libraries\LilyGo-EPD-4-7-OWM-Weather-Display-1-main\OWM_EPD47_epaper_v2.5\OWM_EPD47_epaper_v2.5.ino:12:
c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:280:13: note: candidate: 'void ArduinoJson6201_F1::convertFromJson(ArduinoJson6201_F1::JsonVariantConst, std::__cxx11::string&)' <near match>
 inline void convertFromJson(JsonVariantConst src, std::string& dst) {
             ^~~~~~~~~~~~~~~
c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:280:13: note:   conversion of argument 2 would be ill-formed:
c:\Users\Admin\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Variant/ConverterImpl.hpp:24:26: error: cannot bind non-const lvalue reference of type 'std::__cxx11::string&' {aka 'std::__cxx11::basic_string<char>&'} to an rvalue of type 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'}
     convertFromJson(src, result);  // Error here? See https://arduinojson.org/v6/unsupported-as/
                          ^~~~~~
In file included from c:\users\admin\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\string:52,
                 from c:\users\admin\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\stdexcept:39,
                 from c:\users\admin\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\array:39,
                 from c:\users\admin\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\tuple:39,
                 from c:\users\admin\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\functional:54,
                 from C:\Users\Admin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\cores\esp32/HardwareSerial.h:49,
                 from C:\Users\Admin\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\cores\esp32/Arduino.h:184,
                 from C:\Users\Admin\Documents\Arduino\Libraries\LilyGo-EPD-4-7-OWM-Weather-Display-1-main\OWM_EPD47_epaper_v2.5\OWM_EPD47_epaper_v2.5.ino:5:
c:\users\admin\appdata\local\arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\esp-2021r2-patch5-8.4.0\xtensa-esp32-elf\include\c++\8.4.0\bits\basic_string.h:514:7: note:   after user-defined conversion: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
       basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
       ^~~~~~~~~~~~

exit status 1

Compilation error: exit status 1`

Do you have any ideas?

Thanks,
Stefan
HowardAtHome commented 1 year ago

It is because ArduinoJson has taken out some of the features in the latest version.

.as<char*>() no longer compiles.

Easiest fix is the following every time you see .as<char*>() String Icon = current_weather["icon"];
WxConditions[0].Icon = Icon;

I am just getting this to work, I think the OpenWeather API has also changed

dreamy1 commented 1 year ago

Thanks for your quick reply!

I just updated the Json library to an older version....works now :-)

The OpenWeather API still works too.

kubark42 commented 1 year ago

It is because ArduinoJson has taken out some of the features in the latest version.

.as<char*>() no longer compiles.

Easiest fix is the following every time you see .as<char*>() String Icon = current_weather["icon"]; WxConditions[0].Icon = Icon;

I am just getting this to work, I think the OpenWeather API has also changed

@HowardAtHome thanks for diving into this a bit. I'm not fully sure I understand what you mean.

I see things like: WxConditions[0].Main0 = root["weather"][0]["main"].as<char*>(); Serial.println("Main: " + String(WxConditions[0].Main0));

Howeer, it's unclear to me what it should look like once it's fixed.

Could you maybe post a working code section so we can see?

kubark42 commented 1 year ago

Quick update: I was able to find https://arduinojson.org/v6/api/jsondocument/as/, where it looks like repacing

.as<char*>()

with

.as<const char*>()

should be the ticket. I did exactly this and, indeed, it compiles!

However, I am having trouble with the OpenWeather API. The console spits out:

WiFi connected at: 192.168.43.251
Thu Mar 23 2023   18:54:58
connection failed, error: connection failed, error: connection failed, error: connection failed, error: Received all weather data...
Thu Mar 23 2023   18:54:58
Awake for : 1.536-secs

Based on @dreamy1's comment about the API still working, it's possible this is due to some issue with parsing the returned API data.

@dreamy1 do you see a route to making the software could be made compatible with the latest ArduinoJSON, instead of downgrading it? (I know it's not your responsibility, but just kind of thinking out loud here.) It can cause a lot of headaches and stress to maintain old library versions, especially as people will inadvertently use them. Arduino, whether for better for worse, pushes the latest libraries onto users, so it's fair to assume that moving forward, if you were, if you were, people will have the old library.

dreamy1 commented 1 year ago

I replaced in the meantime the json issue like mentioned above - for me it worked as before.

It seems that you have a problem with your connection, with verifying your api key or with getting the NTP time.

dreamy1 commented 1 year ago

The question is: did your code work with the older json lib?

dreamy1 commented 1 year ago

Maybe it is a general problem with the code - it seems that there was an "issue" with the original author.

Maybe you want to try his software as i have too: https://github.com/G6EJD/LilyGo-EPD-4-7-OWM-Weather-Display-1

kubark42 commented 1 year ago

The question is: did your code work with the older json lib?

I only just downloaded the code today and gave it a try, so I don't have a reference from the past.

It seems that you have a problem with your connection, with verifying your api key or with getting the NTP time.

I think you're right that the problem is the API key. Looking at https://openweathermap.org/api#current, it's unclear to me which product I would need to subscribe to. The couple I randomly clicked on require creating payment plans, and that's definitely not something I want to do just in order to play around with the LilyGo.

Do you have any guidance here?


UPDATE

From https://openweathermap.org/faq#error401

API calls return an error 401

You can get the error 401 in the following cases:

  • ...
  • Your API key is not activated yet. Within the next couple of hours, it will be activated and ready to use.
  • ...

So maybe I need to wait a bit...

dreamy1 commented 1 year ago

Yes, all you have to do is to register there. So you will automatically get the subscription / API key, it is visible in you account when you are signed in.

With this key you will get API data for:

And this two data arrays are used in the software.