@@ -112,6 +112,59 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
112
112
break ;
113
113
}
114
114
115
+
116
+ case PLUGIN_WRITE: {
117
+ String cmd = parseString (string, 1 );
118
+ String param1 = parseString (string, 2 );
119
+
120
+ if (cmd.equalsIgnoreCase (F (" senseair_setrelay" ))) {
121
+ int par1;
122
+
123
+ if (validIntFromString (param1, par1)) {
124
+ if ((par1 == 0 ) || (par1 == 1 ) || (par1 == -1 )) {
125
+ short relaystatus = 0 ; // 0x3FFF represents 100% output.
126
+
127
+ // Refer to sensor model’s specification for voltage at 100% output.
128
+ switch (par1) {
129
+ case 0 :
130
+ relaystatus = 0 ;
131
+ break ;
132
+ case 1 :
133
+ relaystatus = 0x3FFF ;
134
+ break ;
135
+ default :
136
+ relaystatus = 0x7FFF ;
137
+ break ;
138
+ }
139
+ P052_data_struct *P052_data =
140
+ static_cast <P052_data_struct *>(getPluginTaskData (event->TaskIndex ));
141
+
142
+ if ((nullptr != P052_data) && P052_data->isInitialized ()) {
143
+ P052_data->modbus .writeSingleRegister (0x18 , relaystatus);
144
+ addLog (LOG_LEVEL_INFO, concat (F (" Senseair command: relay=" ), param1));
145
+ }
146
+ }
147
+ }
148
+ success = true ;
149
+ }
150
+
151
+ /*
152
+ // ABC functionality disabled for now, due to a bug in the firmware.
153
+ // See https://github.com/letscontrolit/ESPEasy/issues/759
154
+ if (cmd.equalsIgnoreCase(F("senseair_setABCperiod")))
155
+ {
156
+ if (param1.toInt() >= 0) {
157
+ Plugin_052_setABCperiod(param1.toInt());
158
+ addLog(LOG_LEVEL_INFO, String(F("Senseair command: ABCperiod=")) +
159
+ param1);
160
+ }
161
+ success = true;
162
+ }
163
+ */
164
+
165
+ break ;
166
+ }
167
+
115
168
case PLUGIN_WEBFORM_LOAD_OUTPUT_SELECTOR:
116
169
{
117
170
const __FlashStringHelper *options[P052_NR_OUTPUT_OPTIONS];
@@ -134,22 +187,10 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
134
187
if ((nullptr != P052_data) && P052_data->isInitialized ()) {
135
188
addFormSubHeader (F (" Device Information" ));
136
189
{
137
- int value = 0 ;
138
-
139
190
if (P052_data->modbus .detected_device_description .length () > 0 ) {
140
191
addRowLabel (F (" Detected Device" ));
141
192
addHtml (P052_data->modbus .detected_device_description );
142
193
}
143
-
144
- if (P052_data->readInputRegister (P052_IR29_FW_REV, value)) {
145
- addRowLabel (F (" FW rev." ));
146
- addHtmlInt (value);
147
- }
148
-
149
- addRowLabel (F (" Sensor ID" ));
150
- addHtml (formatToHex_decimal (P052_data->getSensorID ()));
151
-
152
-
153
194
addRowLabel (F (" Checksum (pass/fail/nodata)" ));
154
195
{
155
196
uint32_t reads_pass, reads_crc_failed, reads_nodata;
@@ -163,79 +204,58 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
163
204
addHtml (chksumStats);
164
205
}
165
206
166
- if (P052_data->readInputRegister (P052_IR7_MEASUREMENT_COUNT, value)) {
207
+ uint8_t errorcode = 0 ;
208
+ int value = P052_data->modbus .readInputRegister (0x06 , errorcode);
209
+
210
+ if (errorcode == 0 ) {
167
211
addRowLabel (F (" Measurement Count" ));
168
212
addHtmlInt (value);
169
213
}
170
214
171
- if (P052_data->readInputRegister (P052_IR8_MEASUREMENT_CYCLE_TIME, value)) {
215
+ value = P052_data->modbus .readInputRegister (0x07 , errorcode);
216
+
217
+ if (errorcode == 0 ) {
172
218
addRowLabel (F (" Measurement Cycle time" ));
173
219
addHtmlInt (value * 2 );
174
- addUnit (' s' );
175
220
}
176
221
177
- if (P052_data->readInputRegister (P052_IR9_MEASURED_UNFILTERED_CO2, value)) {
178
- addRowLabel (F (" Unfiltered CO2" ));
179
- addHtmlInt (value);
180
- }
181
-
182
- if (P052_data->readHoldingRegister (P052_HR11_MEASUREMENT_MODE, value)) {
183
- addRowLabel (F (" Measurement Mode" ));
184
- addHtml (value == 0 ? F (" Continuous" ) : F (" Single Measurement" ));
185
- }
186
-
187
- if (P052_data->readHoldingRegister (P052_HR14_ABC_PERIOD, value)) {
188
- addRowLabel (F (" ABC Period" ));
189
- addHtmlInt (value);
190
- addUnit (' h' );
191
- }
192
-
193
- if (P052_data->readHoldingRegister (P052_HR5_ABC_TIME, value)) {
194
- addRowLabel (F (" Time Since ABC" ));
195
- addHtmlInt (value);
196
- addUnit (' h' );
197
- }
222
+ value = P052_data->modbus .readInputRegister (0x08 , errorcode);
198
223
199
- if (P052_data-> readHoldingRegister (P052_HR19_METER_CONTROL, value) ) {
200
- addRowLabel (F (" HR19 " ));
224
+ if (errorcode == 0 ) {
225
+ addRowLabel (F (" Unfiltered CO2 " ));
201
226
addHtmlInt (value);
202
- addRowLabel (F (" nRDY" ));
203
- addEnabled (bitRead (value, 0 ) == 0 );
204
- addRowLabel (F (" ABC" ));
205
- addEnabled (bitRead (value, 1 ) == 0 );
206
- addRowLabel (F (" Static IIR filter" ));
207
- addEnabled (bitRead (value, 2 ) == 0 );
208
- addRowLabel (F (" Dynamic IIR filter" ));
209
- addEnabled (bitRead (value, 3 ) == 0 );
210
- addRowLabel (F (" Pressure Compensation" ));
211
- addEnabled (bitRead (value, 4 ) == 0 );
212
227
}
213
228
}
214
229
215
230
{
216
- int value = 0 ;
217
-
218
- /*
219
- if (P052_data->readHoldingRegister(P052_HR11_MEASUREMENT_MODE, value)) {
220
- // Disable selector for now, since single measurement not yet supported.
221
-
222
- const __FlashStringHelper *options[2] = { F("Continuous"), F("Single Measurement") };
223
- addFormSelector(F("Measurement Mode"), F("mode"), 2, options, nullptr, value);
224
- }
225
- */
231
+ uint8_t errorcode = 0 ;
226
232
227
- if (P052_data->readHoldingRegister (P052_HR12_MEASUREMENT_PERIOD, value)) {
228
- addFormNumericBox (F (" Measurement Period" ), F (" period" ), value, 2 , 65534 );
229
- addUnit (' s' );
230
- }
233
+ // int meas_mode = P052_data->modbus.readHoldingRegister(0x0A, errorcode);
234
+ // bool has_meas_mode = errorcode == 0;
235
+ int period = P052_data->modbus .readHoldingRegister (0x0B , errorcode);
236
+ bool has_period = errorcode == 0 ;
237
+ int samp_meas = P052_data->modbus .readHoldingRegister (0x0C , errorcode);
238
+ bool has_samp_meas = errorcode == 0 ;
239
+
240
+ if (/* has_meas_mode || */ has_period || has_samp_meas) {
241
+ // Disable selector for now, since single measurement not yet supported.
242
+
243
+ /*
244
+ if (has_meas_mode) {
245
+ const __FlashStringHelper * options[2] = { F("Continuous"), F("Single Measurement") };
246
+ addFormSelector(F("Measurement Mode"), F("mode"), 2, options, nullptr, meas_mode);
247
+ }
248
+ */
249
+ if (has_period) {
250
+ addFormNumericBox (F (" Measurement Period" ), F (" period" ), period, 2 , 65534 );
251
+ addUnit (' s' );
252
+ }
231
253
232
- if (P052_data->readHoldingRegister (P052_HR13_NR_OF_SAMPLES, value)) {
233
- addFormNumericBox (F (" Samples per measurement" ), F (" samp_meas" ), value, 1 , 1024 );
254
+ if (has_samp_meas) {
255
+ addFormNumericBox (F (" Samples per measurement" ), F (" samp_meas" ), samp_meas, 1 , 1024 );
256
+ }
234
257
}
235
258
}
236
- {
237
- // P052_ABC_PERIOD
238
- }
239
259
}
240
260
241
261
/*
@@ -379,12 +399,12 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
379
399
380
400
switch (PCONFIG (varnr)) {
381
401
case 1 : {
382
- value = P052_data->modbus .readInputRegister (P052_IR4_MEASURED_FILTERED_CO2 , errorcode);
402
+ value = P052_data->modbus .readInputRegister (P052_IR_SPACE_CO2 , errorcode);
383
403
logPrefix = F (" co2 = " );
384
404
break ;
385
405
}
386
406
case 2 : {
387
- int temperatureX100 = P052_data->modbus .readInputRegister (P052_IR5_TEMPERATURE , errorcode);
407
+ int temperatureX100 = P052_data->modbus .readInputRegister (P052_IR_TEMPERATURE , errorcode);
388
408
389
409
if (errorcode != 0 ) {
390
410
// SenseAir S8, not for other modules.
@@ -396,13 +416,13 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
396
416
break ;
397
417
}
398
418
case 3 : {
399
- int rhX100 = P052_data->modbus .readInputRegister (P052_IR6_SPACE_HUMIDITY , errorcode);
419
+ int rhX100 = P052_data->modbus .readInputRegister (P052_IR_SPACE_HUMIDITY , errorcode);
400
420
value = static_cast <float >(rhX100) / 100 .0f ;
401
421
logPrefix = F (" humidity = " );
402
422
break ;
403
423
}
404
424
case 4 : {
405
- int status = P052_data->modbus .readInputRegister (P052_IR29_FW_REV , errorcode);
425
+ int status = P052_data->modbus .readInputRegister (0x1C , errorcode);
406
426
407
427
if (errorcode == 0 ) {
408
428
int relayStatus = (status >> 8 ) & 0x1 ;
@@ -413,7 +433,7 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
413
433
break ;
414
434
}
415
435
case 5 : {
416
- int temperatureAdjustment = P052_data->modbus .readInputRegister (P052_IR11_MEASURED_CONCENTRATION_UNFILTERED , errorcode);
436
+ int temperatureAdjustment = P052_data->modbus .readInputRegister (0x0A , errorcode);
417
437
value = static_cast <float >(temperatureAdjustment);
418
438
logPrefix = F (" temperature adjustment = " );
419
439
break ;
@@ -424,7 +444,6 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
424
444
425
445
if (errorcode == 0 ) {
426
446
value = errorWord;
427
-
428
447
for (size_t i = 0 ; i < 9 ; i++) {
429
448
if (bitRead (errorWord, i)) {
430
449
log += F (" error code = " );
@@ -447,7 +466,7 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
447
466
}
448
467
449
468
if (P052_data->modbus .getLastError () == 0 ) {
450
- success = true ;
469
+ success = true ;
451
470
UserVar[event->BaseVarIndex + varnr] = value;
452
471
log += logPrefix;
453
472
log += value;
@@ -458,98 +477,6 @@ boolean Plugin_052(uint8_t function, struct EventStruct *event, String& string)
458
477
}
459
478
break ;
460
479
}
461
-
462
- case PLUGIN_WRITE:
463
- {
464
- P052_data_struct *P052_data =
465
- static_cast <P052_data_struct *>(getPluginTaskData (event->TaskIndex ));
466
-
467
- if ((nullptr != P052_data) && P052_data->isInitialized ()) {
468
- const String command = parseString (string, 1 );
469
-
470
- if (equals (command, F (" senseair" ))) {
471
- const String subcommand = parseString (string, 2 );
472
-
473
- if (equals (subcommand, F (" writehr" ))) {
474
- uint32_t addr = 0 ;
475
- uint32_t cmnd = 0 ;
476
-
477
- if (validUIntFromString (parseString (string, 3 ), addr) &&
478
- validUIntFromString (parseString (string, 4 ), cmnd)) {
479
- uint8_t errorcode = 0 ;
480
- P052_data->modbus .writeSingleRegister (addr, cmnd, errorcode);
481
- success = 0 == errorcode;
482
- }
483
- } else if (equals (subcommand, F (" readhr" ))) {
484
- uint32_t addr = 0 ;
485
-
486
- if (validUIntFromString (parseString (string, 3 ), addr)) {
487
- uint8_t errorcode = 0 ;
488
- const int value = P052_data->modbus .readHoldingRegister (addr, errorcode);
489
-
490
- if (0 == errorcode) {
491
- success = true ;
492
-
493
- if (Settings.UseRules ) {
494
- String eventvalues;
495
- eventvalues += (addr + 1 ); // HR1 = addr 0x00
496
- eventvalues += ' ,' ;
497
- eventvalues += value;
498
- eventQueue.add (event->TaskIndex , F (" readhr" ), eventvalues);
499
- }
500
- }
501
- }
502
- } else if (equals (subcommand, F (" enableabc" ))) {
503
- uint32_t hours = 0 ;
504
-
505
- if (validUIntFromString (parseString (string, 3 ), hours)) {
506
- // Read HR19
507
-
508
- // Clear bit 1 in register and write back HR19
509
-
510
- // Read HR14 and verify desired ABC period
511
-
512
- // If HR14 (ABC period) is not the desired period,
513
- // write desired ABC period to HR14
514
- }
515
- } else if (equals (subcommand, F (" disableabc" ))) {
516
- // Read HR19
517
-
518
- // Set bit 1 in register and write back HR19
519
- } else if (equals (subcommand, F (" setabcperiod" ))) {
520
- int period = 0 ;
521
-
522
- if (validIntFromString (parseString (string, 3 ), period)) {
523
- if (period >= 0 ) {
524
- P052_data->setABCperiod (period);
525
- addLog (LOG_LEVEL_INFO, String (F (" Senseair command: ABCperiod=" )) +
526
- period);
527
- success = true ;
528
- }
529
- }
530
- } else if (equals (subcommand, F (" setrelay" ))) {
531
- int state = 0 ;
532
-
533
- if (validIntFromString (parseString (string, 3 ), state)) {
534
- short relaystatus = 0 ; // 0x3FFF represents 100% output.
535
- success = true ;
536
-
537
- // Refer to sensor model’s specification for voltage at 100% output.
538
- if (state == 0 ) { relaystatus = 0 ; }
539
- else if (state == 1 ) { relaystatus = 0x3FFF ; }
540
- else if (state == -1 ) { relaystatus = 0x7FFF ; }
541
- else { success = false ; }
542
-
543
- if (success) {
544
- P052_data->modbus .writeSingleRegister (0x18 , relaystatus);
545
- addLog (LOG_LEVEL_INFO, concat (F (" Senseair command: relay=" ), state));
546
- }
547
- }
548
- }
549
- }
550
- }
551
- break ;
552
- }
553
480
}
554
481
return success;
555
482
}
0 commit comments