diff --git a/CounterServer/module.php b/CounterServer/module.php index dd598ee..b970054 100644 --- a/CounterServer/module.php +++ b/CounterServer/module.php @@ -9,7 +9,7 @@ class CounterServer extends IPSModule $this->RegisterPropertyInteger('Connector', 0); $this->RegisterPropertyInteger('SourceJSON', 0); $this->RegisterPropertyInteger('UpdateTime', 60); - $this->RegisterPropertyInteger('ProjectIdPortal', 0); + $this->RegisterPropertyInteger('ProjectIdPortal', -1); $this->RegisterTimer('Update', 0, 'SECT_checkTable($_IPS[\'TARGET\']);'); } @@ -61,15 +61,17 @@ class CounterServer extends IPSModule $counterName = $c['name'] ?? $counterId; $type = $c['type'] ?? 'other'; $unit = $c['unit'] ?? 'kWh'; + $projectId = $this->ReadPropertyInteger('ProjectIdPortal'); + if ($projectId !== -1) { // ---------- UPSERT ---------- $sql = " INSERT INTO meter_devices (project_id, counter_id, meter_uuid, external_id, external_name, meter_type, billing_unit, is_active) VALUES ( - " . ($projectId === 'NULL' ? 'NULL' : $projectId) . ", + " . $this->esc($projectId) . "', '" . $this->esc($clientId . '_' . $counterId) . "', '" . $this->esc($counterId) . "', '" . $this->esc($clientId) . "', @@ -85,7 +87,9 @@ class CounterServer extends IPSModule is_active = 1 "; + MySQL_ExecuteSimple($sqlId, $sql); + } // ---------- GET meter_id ---------- $sqlGet = " diff --git a/library.json b/library.json index 212a1c4..de066fb 100644 --- a/library.json +++ b/library.json @@ -8,6 +8,6 @@ "date": 1491343200 }, "version": "1.0", - "build": 7, + "build": 8, "date": 0 } \ No newline at end of file