tobiasehlert / teslamateapi

TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON
MIT License
90 stars 20 forks source link

Charge details giving an error #18

Closed alecwills closed 3 years ago

alecwills commented 3 years ago

API is working correctly for all endpoints except /api/v1/cars/:carid/charges/:chargeid the :carid and :chargeid I am using are both valid. The web response is _ERR_EMPTYRESPONSE The logs on the docker instance (Ubuntu server 19.10 64bit on Raspberry Pi 4) is; sql: Scan error on column index 5, name "not_enough_power_to_heat": sql/driver: couldn't convert <nil> (<nil>) into type bool

I've checked the DB and while this column exists every row has null in this column. Note: I am in Australia and car is Model 3 and I don't believe my battery is ever heated as it's never cold enough here.

LelandSindt commented 3 years ago

I see/can confirm this same behaviour.

tobiasehlert commented 3 years ago

Hello @alecwills

Some rows can contain null as data and a SQL query with book does not support null. There is a workaround that I've done at drives endpoint that I can add here, and that is to use NullBoolean instead of Boolean only. I can make a fix and you can test it. Can you send the full row of data? I think that there is may e some more cell containing null that we can fix at the same time.

My wife is at the computer currently but later in the evening I will add a little code :-)

Regards, Tobias

LelandSindt commented 3 years ago

google -> https://stackoverflow.com/questions/26976251/how-can-i-fetch-a-null-boolean-from-postgres-in-go -> https://golang.org/pkg/database/sql/#NullBool -> https://github.com/tobiasehlert/teslamateapi/pull/19

tobiasehlert commented 3 years ago

google -> https://stackoverflow.com/questions/26976251/how-can-i-fetch-a-null-boolean-from-postgres-in-go -> https://golang.org/pkg/database/sql/#NullBool -> https://github.com/tobiasehlert/teslamateapi/pull/19

Here is the NullSupport fine containing the fix.. it's using SQL package for this but there could be a better way of implementation maybe. https://www.github.com/tobiasehlert/teslamateapi/tree/main/src%2FNullSupport.go

tobiasehlert commented 3 years ago

Now you can test the fix in docker image with label main instead if latest :-) confirm if it fix by @LelandSindt helped you @alecwills

LelandSindt commented 3 years ago

Ah, I thought that NullBool was made available from github.com/lib/pq I didn't see that you had aliased it from elsewhere.

LelandSindt commented 3 years ago

Not sure if its a better way, but [after some experimenting] I confirmed that you can import database/sql and then reference sql.NullBool directly

but then it looks like you are also pulling in some logic to help with the json marshaling.

..... if it's not already clear, I am here to learn as much as I am here to help.

tobiasehlert commented 3 years ago

Ah, I thought that NullBool was made available from github.com/lib/pq I didn't see that you had aliased it from elsewhere.

Yeah.. I had issues with errors in the sql statements and that what was I was finding after extensive googling.. 😄

Anyhow.. there is probably a better solution to not link a full library. the database/sql library does include a looot of stuff, so would be pretty nice to only have the part that is needed. But I'm not sure how to structure a new type like that. Might be something for future enhancements when I'm bored. It works as it is today and that is the important thing 👍

alecwills commented 3 years ago

Now you can test the fix in docker image with label main instead if latest :-) confirm if it fix by @LelandSindt helped you @alecwills

Thanks @tobiasehlert @LelandSindt I'm not a developer or big github user so can't quite tell who resolved this. I can confirm I have pulled the main label docker image and it is now working as expected. Thanks for your speedy help. I assume I close this, apologies if that's wrong.

idominiki commented 3 years ago

Hey @tobiasehlert,

I think I have the same problem. Since 4 weeks I can access the charges data. Now I got the error " Empty reply from server " Bildschirmfoto 2021-05-31 um 17 34 05

What should I do?