Permalink
Browse files

Use username and password in Fibaro version 3.x, to avoid incompatibi…

…lity with older versions.
  • Loading branch information...
1 parent e73a479 commit a6669496f2d855491868221c49665638f1846a91 @eburud eburud committed Jan 2, 2017
Showing with 19 additions and 10 deletions.
  1. +19 −10 push/DataPush.cpp
View
@@ -149,16 +149,25 @@ void CDataPush::DoFibaroPush()
std::stringstream Url;
std::vector<std::string> ExtraHeaders;
- // Create basic authentication header
- std::stringstream sstr;
- sstr << fibaroUsername << ":" << fibaroPassword;
- std::string m_AccessToken = base64_encode((const unsigned char *)(sstr.str().c_str()), strlen(sstr.str().c_str()));
- ExtraHeaders.push_back("Authorization:Basic " + m_AccessToken);
+ Url << "http://";
+
+ if (bIsV4) {
+ // Create basic authentication header
+ std::stringstream sstr;
+ sstr << fibaroUsername << ":" << fibaroPassword;
+ std::string m_AccessToken = base64_encode((const unsigned char *)(sstr.str().c_str()), strlen(sstr.str().c_str()));
+ ExtraHeaders.push_back("Authorization:Basic " + m_AccessToken);
+ }
+ else {
+ Url << fibaroUsername << ":" << fibaroPassword << "@"; // Add user name in url for earlier than V4
+ }
+
+ Url << fibaroIP << "/";
sendValue = CURLEncode::URLEncode(sendValue);
-
+
if (targetType==0) {
- Url << "http://" << fibaroIP << "/api/globalVariables";
+ Url << "api/globalVariables";
if (bIsV4)
Url << "/" << targetVariable;
@@ -180,7 +189,7 @@ void CDataPush::DoFibaroPush()
}
}
else if (targetType==1) {
- Url << "http://" << fibaroIP << "/api/callAction?deviceid=" << targetDeviceID << "&name=setProperty&arg1=" << targetProperty << "&arg2=" << sendValue;
+ Url << "api/callAction?deviceid=" << targetDeviceID << "&name=setProperty&arg1=" << targetProperty << "&arg2=" << sendValue;
if (fibaroDebugActive) {
_log.Log(LOG_NORM,"FibaroLink: sending value %s to property %s of virtual device id %d",sendValue.c_str(),targetProperty.c_str(),targetDeviceID);
}
@@ -191,7 +200,7 @@ void CDataPush::DoFibaroPush()
}
else if (targetType==2) {
if (((delpos==0)&&(lstatus=="Off"))||((delpos==1)&&(lstatus=="On"))) {
- Url << "http://" << fibaroIP << "/api/sceneControl?id=" << targetDeviceID << "&action=start";
+ Url << "api/sceneControl?id=" << targetDeviceID << "&action=start";
if (fibaroDebugActive) {
_log.Log(LOG_NORM,"FibaroLink: activating scene %d",targetDeviceID);
}
@@ -203,7 +212,7 @@ void CDataPush::DoFibaroPush()
}
else if (targetType==3) {
if (((delpos==0)&&(lstatus=="Off"))||((delpos==1)&&(lstatus=="On"))) {
- Url << "http://" << fibaroIP << "/api/settings/reboot";
+ Url << "api/settings/reboot";
if (fibaroDebugActive) {
_log.Log(LOG_NORM,"FibaroLink: reboot");
}

0 comments on commit a666949

Please sign in to comment.