@@ -315,14 +315,19 @@ class powermeter {
315
315
*/
316
316
void setHeader (HTTPClient *h, String auth = " " , u8_t realm = 0 ) {
317
317
h->setFollowRedirects (HTTPC_STRICT_FOLLOW_REDIRECTS);
318
- // / h->setUserAgent("Ahoy-Agent");
319
318
// / // TODO: Ahoy-0.8.850024-zero
320
319
h->setUserAgent (mApp ->getVersion ());
321
320
h->setConnectTimeout (500 );
322
321
h->setTimeout (1000 );
323
322
h->addHeader (" Content-Type" , " application/json" );
324
323
h->addHeader (" Accept" , " application/json" );
325
324
325
+ if (auth != NULL && realm) {
326
+ // h->addHeader("WWW-Authenticate", "Digest qop=\"auth\", realm=\"" + "shellypro4pm-f008d1d8b8b8" + "\\", nonce=\"60dc59c6\", algorithm=SHA-256");
327
+ } else if (!auth.isEmpty ()) {
328
+ h->addHeader (" Authorization" , " Basic " + auth);
329
+ }
330
+
326
331
/*
327
332
Shelly PM Mini Gen3
328
333
Shelly Plus 1PM
@@ -343,11 +348,6 @@ class powermeter {
343
348
Shelly 3EM
344
349
Shelly EM + 120A Clamp
345
350
346
- */
347
-
348
- /* if (auth != NULL && realm) http.addHeader("WWW-Authenticate", "Digest qop=\"auth\", realm=\"" + shellypro4pm-f008d1d8b8b8 + "\", nonce=\"60dc59c6\", algorithm=SHA-256");
349
- else if (auth != NULL) http.addHeader("Authorization", "Basic " + auth);*/
350
- /*
351
351
All Required:
352
352
realm: string, device_id of the Shelly device.
353
353
username: string, must be set to admin.
@@ -596,10 +596,11 @@ class powermeter {
596
596
bool result = false ;
597
597
mLog ->addProperty (" mod" , " getPowermeterWattsTibber" );
598
598
599
- String auth = mCfg ->groups [group].pm_pass ;
600
- String url = String (" http://" ) + mCfg ->groups [group].pm_src + String (" /" ) + String (mCfg ->groups [group].pm_jsonPath );
599
+ String url = String (" http://" );
600
+ url += String (mCfg ->groups [group].pm_user ) + " :" + String (mCfg ->groups [group].pm_pass ) + " @" ;
601
+ url += String (mCfg ->groups [group].pm_src ) + " /" + String (mCfg ->groups [group].pm_jsonPath );
601
602
602
- setHeader (&http, auth );
603
+ setHeader (&http, mCfg -> groups [group]. pm_cred );
603
604
http.begin (url);
604
605
605
606
if (http.GET () == HTTP_CODE_OK && http.getSize () > 0 ) {
@@ -629,6 +630,12 @@ class powermeter {
629
630
}
630
631
}
631
632
}
633
+ else if (http.GET () != HTTP_CODE_OK || http.getSize () <= 0 )
634
+ {
635
+ DBGPRINT (" http-error: " ); DBGPRINTLN (String (http.GET ()));
636
+ DBGPRINT (" http-error size: " ); DBGPRINTLN (String (http.getSize ()));
637
+ result = false ;
638
+ }
632
639
633
640
http.end ();
634
641
return result;
0 commit comments