BlazejosP / huawei-sun2000-API-CLI

Huawei SUN2000 compatible devices which working with Huawei Cloud Service command line bash API for monitoring or download data from their FusionSolarApp API
https://www.buymeacoffee.com/blazejosP
GNU General Public License v3.0
110 stars 15 forks source link

Problem with login to fusionSolarApp service from this software #15

Closed BlazejosP closed 3 years ago

BlazejosP commented 3 years ago

During upgrade on Huawei side on their server 26 April to 1st of May service was totally switch off. They switch on their service and open API between 1st to 3rd of May and since then is working. This software especially after upgrade on Huawei side need some rebuild they introduced some changes in API not well documented there is a problem now with login from this software to their API which is partially resolved induced but this small changes by Huawei. I have now last documentation and with help of their Help desk try to resolve this made changes in function login_to_API and hope until end of May this software will work again back like before Huawei upgrade. As for now actually version and a previous one are not working because this problem with login.

januweness commented 3 years ago

Thanks so much. Apparently, the output syntax has changed, and the separators like IFS=';' and the array indices like xsrf_token=${array[1]} need to be redone. Hopefully the syntax has only changed for the login process.....

Thanks a lot for developing this in bash!

BlazejosP commented 3 years ago

Great hope that we will solve this in not so long time and about bash that was a totally improvisation. I just need simple text mode application to pull data and then send to (influxDB/Grafana) from inverter. Bash have some limitations sometimes I regret that I don't start this from scratch in python year ago. But as for now meaby is more flexible thanks to Bash utilisation.

BlazejosP commented 3 years ago

Function login_to_API rebuild and is working now. From my test looks like for now is working fusionsolarapp.sh and are some problems with TUI fusionsolarapp_interface.sh. About functions

login_to_API getStationList getDevList getStationRealKpi getDevRealKpi

are working but there is problem with functions which use time in their input. Years are crazy like year 53355. Looks like again that Huawei change something silently in time handling in their API. So rest of functions where we have $curent_time in input need also some modifications because are not working or shows some rubbish.

januweness commented 3 years ago

are working but there is problem with functions which use time in their input. Years are crazy like year 53355. Looks like again that Huawei change something silently in time handling in their API. So rest of functions where we have $curent_time in input need also some modifications because are not working or shows some rubbish.

The year 53355 comes out because they changed the units from seconds since 01.January 1970 to nanoseconds since 01January 1970. This gives three extra digits, and with the correspondingly much larger number, a date far in the future results. Pretty silly given that performance is measured every hour, but easy to handle: just cut the last three digits, or better, only take the first 10 digits: time=$(echo $getKpiStationHour | jq '.data[].collectTime'| cut -c1-10 | head -1) before converting to calendar date: date -d @${time} "+%Y-%m-%dT%X" >> $out.time

In order to convert a calendar date to nanoseconds since 01Jan.1970: date +%s%N

januweness commented 3 years ago

Hi again, the function: getDevRealKpi is not working for me as the command: getDevRealKpi=$(printf '{"devIds": "'${stations_Code_array[0]}'", "devTypeId": "'${device_TypeId_array[0]}'"}'| http --follow --timeout 3600 POST https://intl.fusionsolar.huawei.com/thirdData/getDevRealKpi XSRF-TOKEN:''$xsrf_token'' Content-Type:'application/json' Cookie:'web-auth=true; XSRF-TOKEN='$xsrf_token'; JSESSIONID='$jsesionid'')

leaves empty output. Any clue? => Sorry, found it: Need to run getDevList first, then it works.....

BlazejosP commented 3 years ago

Great that you found solution to this Time problem in functions will be great if you will upload this modification in this part where you done them during review of the code. I myself plan in next two-three days check step by step all the functions and found what is not working fix this what is necessary to fix and hope in next 5/6 days we will have program working like before Huawei server upgrade. Than I can go to my previous plans which I have before implement TUI on Dialog library and implement sending data to influxDB what was done before in previous versions.

BlazejosP commented 3 years ago

=> Sorry, found it: Need to run getDevList first, then it works.....

I forgotten to write this in instructions my mistake :-1: you found clue yourself :+1:

rest of the functions are depending on login_to_API getStationList Especially this related to power plant

getDevList is necessary if you take data from individual device in

getDevRealKpi
getDevFiveMinutes getDevKpiDay getDevKpiMonth getDevKpiYear

Will be necessary document this in some way what is necessary to have other functions working

januweness commented 3 years ago

 I entered the code, trying to fix the Times, but after running a test, I am confused now as all dates displayed are fine.

The commands like:    local curent_time_actually=$(echo ${currentTime::-3}) do exactly what I proposed, but 70 of such commands are already in the code for some time, so I am not sure where you encounter the problem with the crazy dates?

This message is intended only for the recipient(s) named above. It may contain proprietary information and/or protected content. Any unauthorised disclosure, use, retention or dissemination is prohibited. If you have received this e-mail in error, please notify the sender immediately. ESA applies appropriate organisational measures to protect personal data, in case of data privacy queries, please contact the ESA Data Protection Officer @.***).

BlazejosP commented 3 years ago

Hope now this problem with time is solved in getDevRealKpi years are correct now. There is other problems with they are not working ( technically they are working they even show sucess = true but there is no data in data =[] inside my case can you test this on your account that you have the same?)

getKpiStationHour ${stations_Code_array[0]} $date getKpiStationDay ${stations_Code_array[0]} $date getKpiStationMonth ${stations_Code_array[0]} $date getKpiStationYear ${stations_Code_array[0]} $date

and

getDevFiveMinutes ${device_Id_array[1]} ${device_TypeId_array[1]} $date getDevKpiDay ${device_Id_array[1]} ${device_TypeId_array[1]} $date getDevKpiMonth ${device_Id_array[1]} ${device_TypeId_array[1]} $date getDevKpiYear ${device_Id_array[1]} ${device_TypeId_array[1]} $date

I starts to have felling that A) something is still broken in huawei API server \ OR B) My account after upgrade has limited data access only to login_to_API getStationList getDevList getStationRealKpi getDevRealKpi

strange before upgrade all functions worked. I even tested this without this software in Postman and answers are also empty for this particular functions something must be on Huawei server probably?

BlazejosP commented 3 years ago

I will be happy if any person who still has problems with login to HuaweiSolarApp will rapport this problem here I try to help. Before please download the latest version and try with your login and password