Comments (23)
Hi, that would be best without an external api.
Why I'm using external api right now? Because there was existing, solid, simple and maintained library that allow connect with Garmin cloud written in Go. It was used in bodycomposition. When I decided to create this app I couldn't find any of that kind of lib in .NET world that would work like that. So I just wrapped Go library in API and made mobile client to it.
Experience in Xamarin is not necessary for test it. Sending request to Garmin can be wrapped in separated library without refences to Xamarin it self. By the way I'm thinking about switching to .net MAUI to check it out. Because Xamarin is outdated and MAUI is some kind of rebranded Xamarin.
Thanks for sharing the info about that lib, When I have more time I will try to check it out and dig into it. You are free to check it in your own, any help is appreciated.
from mi-scale-exporter.
Thanks for the prompt reply. I am not sure why I have not thought of a separate library :) actually I already have this close to ready because I was going to implement my own WebAPI (I trust mine better :)) with the same interface as it is very straight forward. I think it quite simple to have a class Lib that exposes a static method that does all the work. The method could have the same API interface as the original GO version, so it should be plug-n-play (of course without the need JSON serialization).
I am also waiting for MAUI, especially its development to become fully supported under VSCode, without the need to install Visual Studio.
from mi-scale-exporter.
There is one thing that I can think of that may be platform specific and that is the use of local storage. Fit files needed to be written to storage before upload. But I suppose using the general core FileStream class would work
from mi-scale-exporter.
Hi I published the repo: https://github.com/Abasz/GarminWeightScaleUploader
I tested it via the unit test classes and it should work. Note that due to the way the Fit SDK is implemented I had to change some of the types on the Model classes (like doubles to float etc.).
Also if you would be able to add an Activity Class settings for the user settings that would be great. Its not strictly necessary but according to the SDK it is included in the UserSettings message.
Please let me know if you have any questions or if you need anything else.
from mi-scale-exporter.
Nice job, This week I will test the solution. And if I find something, I will let you know or open a pull request.
If everything will works fine, Could you please create a nuget package later?
from mi-scale-exporter.
yes absolutely that makes sense. I never done that before tough, so I might need some time on that
from mi-scale-exporter.
Hi, I checked your project and it worked for me in unit tests (it uploaded weight to my garmin account) but I got some issues when I tried to integrate it with xamarin app.
-
Do you have have source of Fit.dll library? It's built in .Net Framework 4.5 and probably only for Windows so it cannot be used in mobile. But I found nuget Dynastream Fit Portable. It's little old too (.core 1.1) and some features are missing (Ex. BMI). I couldn't use it in Xamarin because Xamarin support only .netstandard (2.0/2.1) libraries.
-
But .NET MAUI is already built on top of .NET 6 and it can consume libraries from .net core 1.1
-
So I created empty hello world app in .NET MAUI Android. Changed your code to use Dynastream nuget instead of Fit.dll (tested it by unit tests and it worked after some tweaks like removing BMI). The second library (GarminConnectClient) I get from your fork.
-
But when I tested the app (in Emulator and on my phone) I got problem with connection to garmin cloud. I got 403 and in Content: error code 1020 Access Denied from cloudflare.
So in summary it looks promising. Soon I will try refactor app from Xamarin to MAUI, but then I have no idea how deal with the cloudflare at the moment
from mi-scale-exporter.
Hi, I checked your project and it worked for me in unit tests (it uploaded weight to my garmin account) but I got some issues when I tried to integrate it with xamarin app.
- Do you have have source of Fit.dll library? It's built in .Net Framework 4.5 and probably only for Windows so it cannot be used in mobile. But I found nuget Dynastream Fit Portable. It's little old too (.core 1.1) and some features are missing (Ex. BMI). I couldn't use it in Xamarin because Xamarin support only .netstandard (2.0/2.1) libraries.
This will not work with the Nuget Portable version. The reason for the need of using a specific Fit.dll is that the BMI field is an undocumented "garmin only" field. So I had to extend the FIT SDK with the FitGen method provided by the SDK. I noticed the incompatibility issue when I was trying to create a NuGet package. I pushed some changes that I think resolves it. Also I uploaded a nuget package that has all the necessary DLL-s. Hope this will work this way.
- But .NET MAUI is already built on top of .NET 6 and it can consume libraries from .net core 1.1
- So I created empty hello world app in .NET MAUI Android. Changed your code to use Dynastream nuget instead of Fit.dll (tested it by unit tests and it worked after some tweaks like removing BMI). The second library (GarminConnectClient) I get from your fork.
- But when I tested the app (in Emulator and on my phone) I got problem with connection to garmin cloud. I got 403 and in Content: error code 1020 Access Denied from cloudflare.
I tested this on windows and everything worked like a charm. Then I tried to move it under linux and create a webapi (porting your go version). I have the same issue... I am still trying to debug that... It must be the http client the framework uses behind the scene as every other thin is the same. Actually I implemented a similar client under nodejs and I crossed checked what I use there also that works under linux properly...
So in summary it looks promising. Soon I will try refactor app from Xamarin to MAUI, but then I have no idea how deal with the cloudflare at the moment
Yes I am working on that too in the meantime. The issue is currently that I have zero idea what the cause of this difference could be. I mean I drilled down in the debug data quite far and the requests are identical... Nevertheless, I will keep looking. As a try, you could try to change the user agent to some android chrome specific (although this did not solve my issue under ubunut but who know).
EDIT:
On thought on the Fit.dll: can you please remove the "processorArchitecture=MSIL" in csproj? I think that could also cause issues.
from mi-scale-exporter.
I tested another library and it has the same issue... it works perfectly on windows, and it does not work on Linux...
I cannot wrap my head around this. I suspect that on the tcp request going out from linux something is included/or omited in the request that triggers cloudflare.
from mi-scale-exporter.
@lswiderski @lswiderski it's kind of easy to spot the issue. We can make a http request to some http self hosted server with spoofed hosts record. Then we can dump the request with wireshark/tcpdump etc... After that we can compare the request from the windows and Linux. As admin I will be more than happy to help with that :)
from mi-scale-exporter.
Ok, so the good news is that after 4 hours of testing and researching (and praying that I dont get caught at the office with :):) ) I was able to find the issue and make this work on Linux. The bad news is that the project needs to be updated to a higher dotnet version.
For some reason Cloudflare was unhappy when the program makes a request from Linux with a HTTP version 1.1 or 1.0 (this never came up as an issue under Windows, I can only speculate about the reasons for this), so the DefaultRequestVersion
had to be set to HttpVersion.Version20
and the DefaultVersionPolicy
to HttpVersionPolicy.RequestVersionOrLower
. However this is only available (I think) on Dotnet Core 2.2 or later...
Also I checked in Chrome what Http version is used when accessing the web interface and there also h2 is used.
I also made some researches why the Go Lang implementation of the uploader works from linux, and it turns out that the net/http package uses h2 as default.
So I conclude that this is seemingly an actual fix for the Cloudflare issue.
As a next steps I will
- push the changes to my fork of the GarminConnectClient (I will try to PL the changes to the original GarminConnectClient repo, but not sure if it ever gets merged)
- update the Target Framework of the Weight Uploader to net6.0 and make necessary changes
- create a new nuget package as a new release
from mi-scale-exporter.
New release as nuget is available and all changes are pushed to the repos.
from mi-scale-exporter.
Unfortunately When I added nuget I catch exception from internals with newtonsoft.Json couldn't be found. So again I tried with yours source codes and I couldn't deploy it with Fit.dll. After replacing it with Dynastream.Fit, I got same result in http client. Http 403 and 1020 from cloudflare in emulator and in phone.
from mi-scale-exporter.
Hi, let's tackle Cloudflare first. I think this is should be still the incorrect protocol. It is possible that the native httphandler overrides this. Can you please add the following tag to the csproj file:
falseOn the Newtonsoft and the fit.dll those are the results of the incorrect packaging. As I said I never did nuget before so I will try to resolve this. I will try to look into these, but for the proof of concept I suppose you can you the source code. If the cloudflare issue is not resolved there is no reason for moving forward.
from mi-scale-exporter.
Can you please add the following tag to the csproj file:
false
Which tag should I set to false?
About the library release It doesn't need to be nuget package, it can be dll but target to min .net standard 2 or .net 5/6
from mi-scale-exporter.
Sorry, when I edited my post I deleted it:
<UseNativeHttpHandler>false</UseNativeHttpHandler>
from mi-scale-exporter.
I have a good news. After disable native http handler it works in dummy .NET MAU Android App
Also when I add manually newtonsoft.Json 13.0.1 it works with you nuget (so with fit.dll). However compiler gives me warning about mismatch the processor architecture, but no error in emulator or on my phone.
I already started with refactor App to MAUI in free time
from mi-scale-exporter.
I released the alpha version of MAUI version.
The UI is buggy and will change in future but the feature with direct call to Garmin Connect is working.
from mi-scale-exporter.
That is excellent news. I will try to test it.
Also I will need to do some refactoring on the garmin-connect fork wtr. to httpclient and the login mechanism. I will also tackle this FIT.dll error and the other errors.
from mi-scale-exporter.
I tested the app, it works for me. I made some changes to the GarminConnectClient to avoid certain bugs. I this is quite final for this purposes from my side.
this is the relase
from mi-scale-exporter.
Great! Can you release this in nuget.org? It will help in nuget management when all required libs are from one nuget repository
from mi-scale-exporter.
https://www.nuget.org/packages/GarminWeightScaleUploader.Library/0.2.1
I hope it works. Let me know if you have any issues.
from mi-scale-exporter.
Version 2.0.1 with direct call to Garmin API is released, so I'm closing this feature request. Thanks @Abasz for your work.
from mi-scale-exporter.
Related Issues (20)
- Error 502 when try upload to Garmin cloud HOT 3
- "age_label" string in Metabolic age column HOT 3
- Missing cookie SESSONID HOT 23
- Error during the upload to Garmin (Android 14) HOT 23
- Incorect resolution HOT 4
- Feature Request: Ability to enter muscle mass as a percentage HOT 2
- Feedback / Enhancement ideas HOT 3
- problem z odczytem danych z wagi Mi Smart Scale 2
- Flur exception HOT 2
- Error code 502 HOT 6
- auth appeared successful but failed to find regex match for service ticket HOT 1
- Body fat is 2% higher HOT 2
- How to synchronize data to Jiaming Asia/China, which is two different accounts from Jiaming International HOT 2
- Extend support for other popular scales with body composition HOT 4
- Getting a flur exception error on upload HOT 1
- Export from Zepp(Amazfit) to Garmin HOT 3
- Bluetooth HOT 1
- Failed to connect HOT 1
- Zepp Life required after Bluetooth address HOT 2
- App crashed HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mi-scale-exporter.