@@ -54,8 +54,9 @@ namespace http {
54
54
}
55
55
56
56
std::string idx = request::findValue (&req, " idx" );
57
+ std::string ssensorname = request::findValue (&req, " sensorname" );
57
58
std::string ssensortype = request::findValue (&req, " sensortype" );
58
- if ((idx == " " ) || (ssensortype == " " ))
59
+ if ((idx == " " ) || (ssensortype. empty ()) || (ssensorname. empty () ))
59
60
return ;
60
61
61
62
bool bCreated = false ;
@@ -81,15 +82,15 @@ namespace http {
81
82
82
83
bool bPrevAcceptNewHardware = m_sql.m_bAcceptNewHardware ;
83
84
m_sql.m_bAcceptNewHardware = true ;
84
-
85
+ unsigned long long DeviceRowIdx = - 1 ;
85
86
switch (iSensorType)
86
87
{
87
88
case 1 :
88
89
// Pressure (Bar)
89
90
{
90
91
std::string rID = std::string (ID);
91
92
padLeft (rID, 8 , ' 0' );
92
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypePressure , 12 , 255 , 0 , " 0.0" , devname);
93
+ DeviceRowIdx=DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypePressure , 12 , 255 , 0 , " 0.0" , devname);
93
94
bCreated = true ;
94
95
}
95
96
break ;
@@ -98,21 +99,21 @@ namespace http {
98
99
{
99
100
std::string rID = std::string (ID);
100
101
padLeft (rID, 8 , ' 0' );
101
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypePercentage , 12 , 255 , 0 , " 0.0" , devname);
102
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypePercentage , 12 , 255 , 0 , " 0.0" , devname);
102
103
bCreated = true ;
103
104
}
104
105
break ;
105
106
case 3 :
106
107
// Gas
107
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeP1Gas, sTypeP1Gas , 12 , 255 , 0 , " 0" , devname);
108
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeP1Gas, sTypeP1Gas , 12 , 255 , 0 , " 0" , devname);
108
109
bCreated = true ;
109
110
break ;
110
111
case 4 :
111
112
// Voltage
112
113
{
113
114
std::string rID = std::string (ID);
114
115
padLeft (rID, 8 , ' 0' );
115
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeVoltage , 12 , 255 , 0 , " 0.000" , devname);
116
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeVoltage , 12 , 255 , 0 , " 0.000" , devname);
116
117
bCreated = true ;
117
118
}
118
119
break ;
@@ -121,7 +122,7 @@ namespace http {
121
122
{
122
123
std::string rID = std::string (ID);
123
124
padLeft (rID, 8 , ' 0' );
124
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeTextStatus , 12 , 255 , 0 , " Hello World" , devname);
125
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeTextStatus , 12 , 255 , 0 , " Hello World" , devname);
125
126
bCreated = true ;
126
127
}
127
128
break ;
@@ -133,13 +134,13 @@ namespace http {
133
134
unsigned char ID3 = (unsigned char )((nid & 0x0000FF00 ) >> 8 );
134
135
unsigned char ID4 = (unsigned char )((nid & 0x000000FF ));
135
136
sprintf (ID, " %X%02X%02X%02X" , ID1, ID2, ID3, ID4);
136
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeLighting2, sTypeAC , 12 , 255 , 0 , " 15" , devname);
137
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeLighting2, sTypeAC , 12 , 255 , 0 , " 15" , devname);
137
138
bCreated = true ;
138
139
}
139
140
break ;
140
141
case 7 :
141
142
// Alert
142
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneral, sTypeAlert , 12 , 255 , 0 , " No Alert!" , devname);
143
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneral, sTypeAlert , 12 , 255 , 0 , " No Alert!" , devname);
143
144
bCreated = true ;
144
145
break ;
145
146
case 8 :
@@ -151,20 +152,20 @@ namespace http {
151
152
unsigned char ID4 = (unsigned char )((nid & 0x000000FF ));
152
153
sprintf (ID, " %X%02X%02X%02X" , ID1, ID2, ID3, ID4);
153
154
}
154
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeThermostat, sTypeThermSetpoint , 12 , 255 , 0 , " 20.5" , devname);
155
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeThermostat, sTypeThermSetpoint , 12 , 255 , 0 , " 20.5" , devname);
155
156
bCreated = true ;
156
157
break ;
157
158
case 9 :
158
159
// Current/Ampere
159
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeCURRENT, sTypeELEC1 , 12 , 255 , 0 , " 0.0;0.0;0.0" , devname);
160
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeCURRENT, sTypeELEC1 , 12 , 255 , 0 , " 0.0;0.0;0.0" , devname);
160
161
bCreated = true ;
161
162
break ;
162
163
case 10 :
163
164
// Sound Level
164
165
{
165
166
std::string rID = std::string (ID);
166
167
padLeft (rID, 8 , ' 0' );
167
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeSoundLevel , 12 , 255 , 0 , " 65" , devname);
168
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeSoundLevel , 12 , 255 , 0 , " 65" , devname);
168
169
bCreated = true ;
169
170
}
170
171
break ;
@@ -173,34 +174,34 @@ namespace http {
173
174
{
174
175
std::string rID = std::string (ID);
175
176
padLeft (rID, 8 , ' 0' );
176
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeBaro , 12 , 255 , 0 , " 1021.34;0" , devname);
177
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeBaro , 12 , 255 , 0 , " 1021.34;0" , devname);
177
178
bCreated = true ;
178
179
}
179
180
break ;
180
181
case 12 :
181
182
// Visibility (km)
182
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneral, sTypeVisibility , 12 , 255 , 0 , " 10.3" , devname);
183
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneral, sTypeVisibility , 12 , 255 , 0 , " 10.3" , devname);
183
184
bCreated = true ;
184
185
break ;
185
186
case 13 :
186
187
// Distance (cm)
187
188
{
188
189
std::string rID = std::string (ID);
189
190
padLeft (rID, 8 , ' 0' );
190
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeDistance , 12 , 255 , 0 , " 123.4" , devname);
191
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeDistance , 12 , 255 , 0 , " 123.4" , devname);
191
192
bCreated = true ;
192
193
}
193
194
break ;
194
195
case 14 : // Counter Incremental
195
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneral, sTypeCounterIncremental , 12 , 255 , 0 , " 0" , devname);
196
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneral, sTypeCounterIncremental , 12 , 255 , 0 , " 0" , devname);
196
197
bCreated = true ;
197
198
break ;
198
199
case 15 :
199
200
// Soil Moisture
200
201
{
201
202
std::string rID = std::string (ID);
202
203
padLeft (rID, 8 , ' 0' );
203
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeSoilMoisture , 12 , 255 , 3 , devname);
204
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeSoilMoisture , 12 , 255 , 3 , devname);
204
205
bCreated = true ;
205
206
}
206
207
break ;
@@ -209,7 +210,7 @@ namespace http {
209
210
{
210
211
std::string rID = std::string (ID);
211
212
padLeft (rID, 8 , ' 0' );
212
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeLeafWetness , 12 , 255 , 2 , devname);
213
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeLeafWetness , 12 , 255 , 2 , devname);
213
214
bCreated = true ;
214
215
}
215
216
break ;
@@ -218,7 +219,7 @@ namespace http {
218
219
{
219
220
std::string rID = std::string (ID);
220
221
padLeft (rID, 8 , ' 0' );
221
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeZWaveClock , 12 , 255 , 0 , " 24:12:00" , devname);
222
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeZWaveClock , 12 , 255 , 0 , " 24:12:00" , devname);
222
223
bCreated = true ;
223
224
}
224
225
break ;
@@ -227,7 +228,7 @@ namespace http {
227
228
{
228
229
std::string rID = std::string (ID);
229
230
padLeft (rID, 8 , ' 0' );
230
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeKwh , 12 , 255 , 0 , " 0;0.0" , devname);
231
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeKwh , 12 , 255 , 0 , " 0;0.0" , devname);
231
232
bCreated = true ;
232
233
}
233
234
break ;
@@ -236,7 +237,7 @@ namespace http {
236
237
{
237
238
std::string rID = std::string (ID);
238
239
padLeft (rID, 8 , ' 0' );
239
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeCurrent , 12 , 255 , 0 , " 6.4" , devname);
240
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeCurrent , 12 , 255 , 0 , " 6.4" , devname);
240
241
bCreated = true ;
241
242
}
242
243
break ;
@@ -245,7 +246,7 @@ namespace http {
245
246
{
246
247
std::string rID = std::string (ID);
247
248
padLeft (rID, 8 , ' 0' );
248
- unsigned long long devidx = m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeLimitlessLights, sTypeLimitlessRGB , 12 , 255 , 1 , devname);
249
+ unsigned long long devidx = DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeLimitlessLights, sTypeLimitlessRGB , 12 , 255 , 1 , devname);
249
250
if (devidx != -1 )
250
251
{
251
252
// Set switch type to dimmer
@@ -255,65 +256,65 @@ namespace http {
255
256
}
256
257
break ;
257
258
case pTypeTEMP:
258
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeTEMP, sTypeTEMP1 , 12 , 255 , 0 , " 0.0" , devname);
259
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeTEMP, sTypeTEMP1 , 12 , 255 , 0 , " 0.0" , devname);
259
260
bCreated = true ;
260
261
break ;
261
262
case pTypeHUM:
262
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeHUM, sTypeTEMP1 , 12 , 255 , 50 , " 1" , devname);
263
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeHUM, sTypeTEMP1 , 12 , 255 , 50 , " 1" , devname);
263
264
bCreated = true ;
264
265
break ;
265
266
case pTypeTEMP_HUM:
266
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeTEMP_HUM, sTypeTH1 , 12 , 255 , 0 , " 0.0;50;1" , devname);
267
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeTEMP_HUM, sTypeTH1 , 12 , 255 , 0 , " 0.0;50;1" , devname);
267
268
bCreated = true ;
268
269
break ;
269
270
case pTypeTEMP_HUM_BARO:
270
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeTEMP_HUM_BARO, sTypeTHB1 , 12 , 255 , 0 , " 0.0;50;1;1010;1" , devname);
271
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeTEMP_HUM_BARO, sTypeTHB1 , 12 , 255 , 0 , " 0.0;50;1;1010;1" , devname);
271
272
bCreated = true ;
272
273
break ;
273
274
case pTypeWIND:
274
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeWIND, sTypeWIND1 , 12 , 255 , 0 , " 0;N;0;0;0;0" , devname);
275
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeWIND, sTypeWIND1 , 12 , 255 , 0 , " 0;N;0;0;0;0" , devname);
275
276
bCreated = true ;
276
277
break ;
277
278
case pTypeRAIN:
278
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeRAIN, sTypeRAIN3 , 12 , 255 , 0 , " 0;0" , devname);
279
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeRAIN, sTypeRAIN3 , 12 , 255 , 0 , " 0;0" , devname);
279
280
bCreated = true ;
280
281
break ;
281
282
case pTypeUV:
282
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeUV, sTypeUV1 , 12 , 255 , 0 , " 0;0" , devname);
283
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeUV, sTypeUV1 , 12 , 255 , 0 , " 0;0" , devname);
283
284
bCreated = true ;
284
285
break ;
285
286
case pTypeRFXMeter:
286
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeRFXMeter, sTypeRFXMeterCount , 10 , 255 , 0 , " 0" , devname);
287
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeRFXMeter, sTypeRFXMeterCount , 10 , 255 , 0 , " 0" , devname);
287
288
bCreated = true ;
288
289
break ;
289
290
case pTypeAirQuality:
290
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeAirQuality, sTypeVoltcraft , 12 , 255 , 0 , devname);
291
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeAirQuality, sTypeVoltcraft , 12 , 255 , 0 , devname);
291
292
bCreated = true ;
292
293
break ;
293
294
case pTypeUsage:
294
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeUsage, sTypeElectric , 12 , 255 , 0 , " 0" , devname);
295
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeUsage, sTypeElectric , 12 , 255 , 0 , " 0" , devname);
295
296
bCreated = true ;
296
297
break ;
297
298
case pTypeLux:
298
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeLux, sTypeLux , 12 , 255 , 0 , " 0" , devname);
299
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeLux, sTypeLux , 12 , 255 , 0 , " 0" , devname);
299
300
bCreated = true ;
300
301
break ;
301
302
case pTypeP1Power:
302
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeP1Power, sTypeP1Power , 12 , 255 , 0 , " 0;0;0;0;0;0" , devname);
303
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeP1Power, sTypeP1Power , 12 , 255 , 0 , " 0;0;0;0;0;0" , devname);
303
304
bCreated = true ;
304
305
break ;
305
306
case 1000 :
306
307
// Waterflow
307
308
{
308
309
std::string rID = std::string (ID);
309
310
padLeft (rID, 8 , ' 0' );
310
- m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeWaterflow , 12 , 255 , 0 , " 0.0" , devname);
311
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, rID.c_str (), 1 , pTypeGeneral, sTypeWaterflow , 12 , 255 , 0 , " 0.0" , devname);
311
312
bCreated = true ;
312
313
}
313
314
break ;
314
315
case 1001 :
315
316
// Wind + Temp + Chill
316
- m_sql.UpdateValue (HwdID, ID, 1 , pTypeWIND, sTypeWIND4 , 12 , 255 , 0 , " 0;N;0;0;0;0" , devname);
317
+ DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeWIND, sTypeWIND4 , 12 , 255 , 0 , " 0;N;0;0;0;0" , devname);
317
318
bCreated = true ;
318
319
break ;
319
320
case 1002 :
@@ -324,7 +325,7 @@ namespace http {
324
325
unsigned char ID3 = (unsigned char )((nid & 0x0000FF00 ) >> 8 );
325
326
unsigned char ID4 = (unsigned char )((nid & 0x000000FF ));
326
327
sprintf (ID, " %02X%02X%02X%02X" , ID1, ID2, ID3, ID4);
327
- unsigned long long devidx = m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneralSwitch, sSwitchTypeSelector , 12 , 255 , 0 , " 0" , devname);
328
+ unsigned long long devidx = DeviceRowIdx= m_sql.UpdateValue (HwdID, ID, 1 , pTypeGeneralSwitch, sSwitchTypeSelector , 12 , 255 , 0 , " 0" , devname);
328
329
if (devidx != -1 )
329
330
{
330
331
// Set switch type to selector
@@ -344,6 +345,10 @@ namespace http {
344
345
root[" status" ] = " OK" ;
345
346
root[" title" ] = " CreateVirtualSensor" ;
346
347
}
348
+ if (DeviceRowIdx != -1 )
349
+ {
350
+ m_sql.safe_query (" UPDATE DeviceStatus SET Name='%q', Used=1 WHERE (ID==%llu)" , ssensorname.c_str (), DeviceRowIdx);
351
+ }
347
352
}
348
353
}
349
354
}
0 commit comments