@@ -547,18 +547,21 @@ void CDomoticzHardwareBase::SendKwhMeterOldWay(const int NodeID, const int Child
547
547
548
548
void CDomoticzHardwareBase::SendKwhMeter (const int NodeID, const int ChildID, const int BatteryLevel, const double musage, const double mtotal, const std::string &defaultname)
549
549
{
550
- int Idx = (NodeID * 256 ) + ChildID;
550
+ int dID = (NodeID << 8 ) | ChildID;
551
+ char szTmp[30 ];
552
+ sprintf (szTmp, " %08X" , dID);
553
+
551
554
bool bDeviceExits = true ;
552
555
std::vector<std::vector<std::string> > result;
553
- result = m_sql.safe_query (" SELECT Name FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d ) AND (Type==%d) AND (Subtype==%d)" ,
554
- m_HwdID, int (Idx) , int (pTypeGeneral), int (sTypeKwh ));
556
+ result = m_sql.safe_query (" SELECT Name FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q' ) AND (Type==%d) AND (Subtype==%d)" ,
557
+ m_HwdID, szTmp , int (pTypeGeneral), int (sTypeKwh ));
555
558
if (result.size () < 1 )
556
559
{
557
560
bDeviceExits = false ;
558
561
}
559
562
560
563
_tGeneralDevice gdevice;
561
- gdevice.intval1 = Idx ;
564
+ gdevice.intval1 = dID ;
562
565
gdevice.subtype = sTypeKwh ;
563
566
gdevice.floatval1 = (float )musage;
564
567
gdevice.floatval2 = (float )(mtotal*1000.0 );
@@ -567,17 +570,20 @@ void CDomoticzHardwareBase::SendKwhMeter(const int NodeID, const int ChildID, co
567
570
if (!bDeviceExits)
568
571
{
569
572
// Assign default name for device
570
- m_sql.safe_query (" UPDATE DeviceStatus SET Name='%q' WHERE (HardwareID==%d) AND (DeviceID==%d ) AND (Type==%d) AND (Subtype==%d)" ,
571
- defaultname.c_str (), m_HwdID, int (Idx) , int (pTypeGeneral), int (sTypeKwh ));
573
+ m_sql.safe_query (" UPDATE DeviceStatus SET Name='%q' WHERE (HardwareID==%d) AND (DeviceID=='%q' ) AND (Type==%d) AND (Subtype==%d)" ,
574
+ defaultname.c_str (), m_HwdID, szTmp , int (pTypeGeneral), int (sTypeKwh ));
572
575
}
573
576
}
574
577
575
578
double CDomoticzHardwareBase::GetKwhMeter (const int NodeID, const int ChildID, bool &bExists)
576
579
{
577
- int Idx = (NodeID * 256 ) + ChildID;
580
+ int dID = (NodeID << 8 ) | ChildID;
581
+ char szTmp[30 ];
582
+ sprintf (szTmp, " %08X" , dID);
583
+
578
584
std::vector<std::vector<std::string> > result;
579
- result = m_sql.safe_query (" SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID==%d ) AND (Type==%d) AND (Subtype==%d)" ,
580
- m_HwdID, int (Idx) , int (pTypeGeneral), int (sTypeKwh ));
585
+ result = m_sql.safe_query (" SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q' ) AND (Type==%d) AND (Subtype==%d)" ,
586
+ m_HwdID, szTmp , int (pTypeGeneral), int (sTypeKwh ));
581
587
if (result.size () < 1 )
582
588
{
583
589
bExists = false ;
0 commit comments