Open-Smartwatch / open-smartwatch-os

The Open-Smartwatch Operating System.
https://open-smartwatch.github.io
GNU General Public License v3.0
998 stars 163 forks source link

OswAppWeather for #207 #299

Closed Lorenzosciacca closed 1 year ago

Lorenzosciacca commented 2 years ago

Note: the update seems to be possible only when the wifi is already activated ( from the time update app for example) and anyway is not always possible to perform the get ( the usual wifi problem ?)

RuffaloLavoisier commented 2 years ago

@simonmicro Should we fix with the emulator exception handling build? See OSW-emulator CI.

@Lorenzosciacca Did you check if there are any exposed parts such as personal authentication keys?

Lorenzosciacca commented 2 years ago

@simonmicro Should we fix with the emulator exception handling build? See OSW-emulator CI.

@Lorenzosciacca Did you check if there are any exposed parts such as personal authentication keys?

I deactivated the Key

simonmicro commented 2 years ago

@simonmicro Should we fix with the emulator exception handling build? See OSW-emulator CI.

@Lorenzosciacca As this app won't work in the emulator, please make sure to disable your code by using the OSW_EMULATOR flag. Take a look at src/devices/bma400.cpp, which is also disabled this way. In your case you'll need to also disable the respective parts in the main.cpp. Maybe at some point in the future the OSW-OS will handle HTTP for you and therefore be compatible with the emulator. Until then, please deactivate it :)

@Lorenzosciacca Did you check if there are any exposed parts such as personal authentication keys?

Could you move that key either into the ´config_defaults.h, so someone compiling the OS by himself can change it (in that case you should test if the key is set during compile time and disable your code respectively like for the emulator)? Or into a config-variable, so the user can change / set it using the web interface?

Lorenzosciacca commented 2 years ago

@simonmicro Should we fix with the emulator exception handling build? See OSW-emulator CI.

@Lorenzosciacca As this app won't work in the emulator, please make sure to disable your code by using the OSW_EMULATOR flag. Take a look at src/devices/bma400.cpp, which is also disabled this way. In your case you'll need to also disable the respective parts in the main.cpp. Maybe at some point in the future the OSW-OS will handle HTTP for you and therefore be compatible with the emulator. Until then, please deactivate it :)

@Lorenzosciacca Did you check if there are any exposed parts such as personal authentication keys?

Could you move that key either into the ´config_defaults.h, so someone compiling the OS by himself can change it (in that case you should test if the key is set during compile time and disable your code respectively like for the emulator)? Or into a config-variable, so the user can change / set it using the web interface?

Sorry for the inconvenience, i didn't used the emulator yet, anyway i can do all the changes. For what concerns the key, off course i can move it to config_defaults.h, when i will be sure about the curent implementation i will also add the possibility to support multiple locations and to setup everything from the web UI.

Lorenzosciacca commented 2 years ago

i'm trying to solve this, but i'm a little bit confused. I have to use directly the esp32 functions without the wrapper? or using them with a new wrapper? (solved ?)

Lorenzosciacca commented 2 years ago

Note: the update seems to be possible only when the wifi is already activated ( from the time update app for example) and anyway is not always possible to perform the get ( the usual wifi problem ?)

I noticed that even if the config app said thah i had switched off the AutoAp it was enabled. I disabled it from the web UI and now i'm able to perform the get without the need of enabling the wifi from the time setup app.

RuffaloLavoisier commented 2 years ago

@Lorenzosciacca I wiii some modifications internally.

Lorenzosciacca commented 2 years ago

https://user-images.githubusercontent.com/60114811/193406360-c8ab02b4-00b7-445d-adb6-bc22d33b2c7d.mp4 All the icons are printed using gfx primitives, i would like to improve the aspect of the pop-up "loading..." and to provide the weather to other apps, like a watch face for example. There is also another aspect i would like to improve, now i saved the ssl root in weather.h, i think it would be great to allow also other apps to use the same certificate,you probably needs a certificate in order to get emails for example. What do you think about it? (edit: you can't use the same cert for different sites, so this doesn't make sense)

RuffaloLavoisier commented 2 years ago

@simonmicro Why not working OswAppWeather in emulator?

I got it.

RuffaloLavoisier commented 2 years ago

By default, does the process of generating a key or does the primary key exist?

Lorenzosciacca commented 2 years ago

(Solved) Right now, if you notice, i declare the secure client, but i'm not using it for the request and the reason is the following. In order to connect to a public server ( eg openweather) you need the root key of the Certificate Authority (CA) that signed the certificate of the public server. When you use your browser, before establishing a secure connection, a handshake procedure is carried on by client and server. During this procedure the server identifies itself to the client by sending the server certificate(SC). The certificate sent by the server contains the ID, the domain name and also a public key. The client in order to continue the procedure should already have the CA certificate (CAc) signed by the same Certificate Authority that signed the SC. The point is that the CA certificate, the one i want to keep on the smartwatch, doesn't last forever, it expires more or less in a year. This problem, for what concerns the weather api is not critical, i can use http, without a cert. , and take the risk of someone stealing my api key. But if we want to implement something like a calendar sync or a email app we should find a way to have always a valid CA cert. CAc

RuffaloLavoisier commented 2 years ago

I would appreciate it if you could write an additional user manual readme that can use OpenWeather (API key setting..).

Lorenzosciacca commented 2 years ago

I would appreciate it if you could write an additional user manual readme that can use OpenWeather (API key setting..).

sure 👍

Lorenzosciacca commented 2 years ago

I would appreciate it if you could write an additional user manual readme that can use OpenWeather (API key setting..).

Where should i post it?

RuffaloLavoisier commented 2 years ago

Thank you for writing an additional user manual. readmeYou can use OpenWeather (set API key..).

Where should I post it?

If you update it in the comments, I will add the file after checking it.

Lorenzosciacca commented 2 years ago

@RuffaloLavoisier , the doc file https://github.com/Lorenzosciacca/OSW_weather/blob/main/readme_.md The images are here

RuffaloLavoisier commented 2 years ago

Great! I'd appreciate it if you could add to this PR.

Lorenzosciacca commented 2 years ago

Great! I'd appreciate it if you could add to this PR.

ok, i don't know where i should put it

RuffaloLavoisier commented 2 years ago

Thanks, I'll arrange the code on the weekend.

simonmicro commented 2 years ago

Oh shit.

simonmicro commented 2 years ago

I fucked up my git commands...

simonmicro commented 2 years ago

Sorry, I messed that up. Fixed it again :sweat_smile:

simonmicro commented 2 years ago

@Lorenzosciacca Heyho - @RuffaloLavoisier and I just took a spin on your work. Please check if we broke anything or messed something up. Also make sure to force-reset your environment to your forks branch, as we fixed some problems inside your history and rebased everything on top of our current develop.

RuffaloLavoisier commented 2 years ago

@Lorenzosciacca And please check if the part we modified works normally on your device!

Lorenzosciacca commented 2 years ago

(Solved) I'm sorry for the delay, i just figured out that i'm not able to access to the develop branch using github desktop. The error displayed is: 'fatal: not a git repository: ../../../.git/modules/emulator/lib/cmdline fatal: could not reset submodule index' This happens when, from a new repository cloned now from my github, i switch from main to develop. In the old repo, the one i used until a few days ago, this does not happens. Instead, on the "old" repo i have a "Merge branch" merge image In order to avoid to mess everything up what should I do?

RuffaloLavoisier commented 2 years ago

Please check your Discord message.

RuffaloLavoisier commented 2 years ago

If you need help, the internal community can help you.

simonmicro commented 2 years ago

@Lorenzosciacca Last check: Is everything OK? We'll merge this soon :tm:

Lorenzosciacca commented 2 years ago

@simonmicro, there are a couple of bugs in the last changes. Anyway i'm going to solve them as well as possibile

simonmicro commented 2 years ago

@simonmicro, there are a couple of bugs in the last changes. Anyway i'm going to solve them as well as possibile

@Lorenzosciacca If you need any help (because we broke something either by rebase or on our own), just hit me up in our Discord :)

Lorenzosciacca commented 2 years ago

@simonmicro , @RuffaloLavoisier , i don't know if i accidentally messed up everything with 4fb4d18 , but the only change i wanted to make was instead abfead5. Anyway now ti works.

simonmicro commented 2 years ago

Fixed the commit history :grin:

simonmicro commented 2 years ago

During testing, I've noted a crash:

I: src/services/OswServiceTaskMemMonitor.cpp@48: Low memory condition resolved. Deactivating countermeasures...
I: src/apps/_experiments/OswAppWeather.cpp@384: size of wstr: 200
I: src/apps/_experiments/OswAppWeather.cpp@303: weather updated correctly

abort() was called at PC 0x401b94c7 on core 0

Backtrace:0x40084041:0x3fff00000x4008f555:0x3fff0020 0x40094cd1:0x3fff0040 0x401b94c7:0x3fff00c0 0x401b950e:0x3fff00e0 0x401b8b0b:0x3fff0100 0x401b8ee6:0x3fff0120 0x401b8c69:0x3fff0140 0x40100dab:0x3fff0160 0x401147d5:0x3fff0180 0x40113e6e:0x3fff01a0 0x40113f27:0x3fff01c0 0x4011400f:0x3fff01e0 

  #0  0x40084041:0x3fff0000 in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:402
  #1  0x4008f555:0x3fff0020 in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/esp_system.c:128
  #2  0x40094cd1:0x3fff0040 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/abort.c:46
  #3  0x401b94c7:0x3fff00c0 in __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47
  #4  0x401b950e:0x3fff00e0 in std::terminate() at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57
  #5  0x401b8b0b:0x3fff0100 in __cxa_throw at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
  #6  0x401b8ee6:0x3fff0120 in operator new(unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_op.cc:54
  #7  0x401b8c69:0x3fff0140 in operator new[](unsigned int) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/new_opv.cc:32
  #8  0x40100dab:0x3fff0160 in Graphics2D::enableBuffer() at /home/simon/Git/open-smartwatch-os/include/gfx_2d.h:61
      (inlined by) OswHal::enableDisplayBuffer() at /home/simon/Git/open-smartwatch-os/src/hal/display.cpp:51
  #9  0x401147d5:0x3fff0180 in OswServiceTaskMemMonitor::loop() at /home/simon/Git/open-smartwatch-os/src/services/OswServiceTaskMemMonitor.cpp:57
  #10 0x40113e6e:0x3fff01a0 in OswServiceManager::loop() at /home/simon/Git/open-smartwatch-os/src/services/OswServiceManager.cpp:44
  #11 0x40113f27:0x3fff01c0 in OswServiceManager::worker() at /home/simon/Git/open-smartwatch-os/src/services/OswServiceManager.cpp:31
  #12 0x4011400f:0x3fff01e0 in OswServiceManager::setup()::{lambda(void*)#1}::_FUN(void*) at /home/simon/Git/open-smartwatch-os/src/services/OswServiceManager.cpp:15
      (inlined by) _FUN at /home/simon/Git/open-smartwatch-os/src/services/OswServiceManager.cpp:15

ELF file SHA256: 0000000000000000

I think this could be a problem on OSW side (why was the watch drawing the app, while the lock was being held by the memory service?!)... I would like to investigate that - just in case. Furthermore, on failed API requests (e.g. 401) the whole wifi stack is bugged -> I also need to fix this. :sweat:

Otherwise GREAT work! The app looks beautiful!

P.S. Could you merge your docs (https://github.com/Lorenzosciacca/OSW_weather/blob/main/readme_.md) into the docs folder of OSW? This way your great docs are also user-accessible :)

Lorenzosciacca commented 2 years ago

This seems to be strange. But, from my test, it is not frequent. Anyway, for what concerns the API response 401, the expected behavior is that the app doesn't load the data and just stop displaying the old weather data. For a more user friendly approach i should also display the error code on the watch. This is the serial output for a wrong api key: 401

for the docs, this folder?

simonmicro commented 2 years ago

@Lorenzosciacca

  1. The error comes from a bad_alloc -> maybe the watch runs out-of-memory (I've updated the main-catches to show that)
  2. I mean this docs folder
  3. The bugged wifi stack did not happen for me anymore, so whatever :)
simonmicro commented 2 years ago

Okay. @Lorenzosciacca last thing to do would be the docs. I'll quickly rebase your branch one last time and then we are ready to go (sorry, this PR took a while longer than expected).

Lorenzosciacca commented 2 years ago

@simonmicro , thank you! The documentation i wrote is quite long, do you want that i load the file inside firmware>apps>OswWeather.md and the pictures in a separate folder like assets>apps>OswWeather ?