From b6165e9a811889e9b1bfab577b3cc6a4c01be813 Mon Sep 17 00:00:00 2001 From: Staars Date: Wed, 12 Dec 2018 10:03:58 +0100 Subject: [PATCH 1/4] initial work on range-support --- sonoff/xsns_15_mhz19.ino | 54 +++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino index 21f5d8a15..04f27bee3 100644 --- a/sonoff/xsns_15_mhz19.ino +++ b/sonoff/xsns_15_mhz19.ino @@ -72,13 +72,18 @@ TasmotaSerial *MhzSerial; const char kMhzTypes[] PROGMEM = "MHZ19|MHZ19B"; -enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET }; -const uint8_t kMhzCommands[][2] PROGMEM = { - {0x86,0x00}, // mhz_cmnd_read_ppm - {0x79,0xA0}, // mhz_cmnd_abc_enable - {0x79,0x00}, // mhz_cmnd_abc_disable - {0x87,0x00}, // mhz_cmnd_zeropoint - {0x8D,0x00}}; // mhz_cmnd_reset +enum MhzCommands { MHZ_CMND_READPPM, MHZ_CMND_ABCENABLE, MHZ_CMND_ABCDISABLE, MHZ_CMND_ZEROPOINT, MHZ_CMND_RESET, MHZ_CMND_RANGE_1000, MHZ_CMND_RANGE_2000, MHZ_CMND_RANGE_3000, MHZ_CMND_RANGE_5000 }; +const uint8_t kMhzCommands[][4] PROGMEM = { +// 2 3 6 7 + {0x86,0x00,0x00,0x00}, // mhz_cmnd_read_ppm + {0x79,0xA0,0x00,0x00}, // mhz_cmnd_abc_enable + {0x79,0x00,0x00,0x00}, // mhz_cmnd_abc_disable + {0x87,0x00,0x00,0x00}, // mhz_cmnd_zeropoint + {0x8D,0x00,0x00,0x00}, // mhz_cmnd_reset + {0x99,0x00,0x03,0xE8}, // mhz_cmnd_set_range_1000 + {0x99,0x00,0x07,0xD0}, // mhz_cmnd_set_range_2000 + {0x99,0x00,0x0B,0xB8}, // mhz_cmnd_set_range_3000 + {0x99,0x00,0x13,0x88}}; // mhz_cmnd_set_range_5000 uint8_t mhz_type = 1; uint16_t mhz_last_ppm = 0; @@ -110,13 +115,12 @@ size_t MhzSendCmd(byte command_id) mhz_send[0] = 0xFF; // Start byte, fixed mhz_send[1] = 0x01; // Sensor number, 0x01 by default - memcpy_P(&mhz_send[2], kMhzCommands[command_id], sizeof(kMhzCommands[0])); + memcpy_P(&mhz_send[2], kMhzCommands[command_id], sizeof(kMhzCommands[2])); /* mhz_send[4] = 0x00; mhz_send[5] = 0x00; - mhz_send[6] = 0x00; - mhz_send[7] = 0x00; */ + memcpy_P(&mhz_send[6], kMhzCommands[command_id] + sizeof(kMhzCommands[2]), sizeof(kMhzCommands[2])); mhz_send[8] = MhzCalculateChecksum(mhz_send); return MhzSerial->write(mhz_send, sizeof(mhz_send)); @@ -246,11 +250,15 @@ void MhzEverySecond(void) /*********************************************************************************************\ * Command Sensor15 * - * 0 - (Not implemented) ABC Off - * 1 - (Not implemented) ABC On - * 2 - Manual start = ABC Off - * 3 - (Not implemented) Optional filter settings - * 9 - Reset + * 0 - (Not implemented) ABC Off + * 1 - (Not implemented) ABC On + * 2 - Manual start = ABC Off + * 3 - (Not implemented) Optional filter settings + * 9 - Reset + * 1000 - Range + * 2000 - Range + * 3000 - Range + * 5000 - Range \*********************************************************************************************/ bool MhzCommandSensor(void) @@ -266,6 +274,22 @@ bool MhzCommandSensor(void) MhzSendCmd(MHZ_CMND_RESET); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); break; + case 1000: + MhzSendCmd(MHZ_CMND_RANGE_1000); + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + break; + case 2000: + MhzSendCmd(MHZ_CMND_RANGE_2000); + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + break; + case 3000: + MhzSendCmd(MHZ_CMND_RANGE_3000); + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + break; + case 5000: + MhzSendCmd(MHZ_CMND_RANGE_5000); + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + break; default: serviced = false; } From 5c613040a1c861ec4600a309459df878d0b25eb5 Mon Sep 17 00:00:00 2001 From: Staars Date: Wed, 12 Dec 2018 10:11:19 +0100 Subject: [PATCH 2/4] mqtt messages updated --- sonoff/xsns_15_mhz19.ino | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino index 04f27bee3..6ddcb251a 100644 --- a/sonoff/xsns_15_mhz19.ino +++ b/sonoff/xsns_15_mhz19.ino @@ -261,6 +261,11 @@ void MhzEverySecond(void) * 5000 - Range \*********************************************************************************************/ +#define D_JSON_RANGE_1000 "1000 ppm range" +#define D_JSON_RANGE_2000 "2000 ppm range" +#define D_JSON_RANGE_3000 "3000 ppm range" +#define D_JSON_RANGE_5000 "5000 ppm range" + bool MhzCommandSensor(void) { boolean serviced = true; @@ -276,19 +281,19 @@ bool MhzCommandSensor(void) break; case 1000: MhzSendCmd(MHZ_CMND_RANGE_1000); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_1000); break; case 2000: MhzSendCmd(MHZ_CMND_RANGE_2000); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_2000); break; case 3000: MhzSendCmd(MHZ_CMND_RANGE_3000); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_3000); break; case 5000: MhzSendCmd(MHZ_CMND_RANGE_5000); - snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RESET); // not done yet + snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_SENSOR_INDEX_SVALUE, XSNS_15, D_JSON_RANGE_5000); break; default: serviced = false; From 47629a9d61c92c3a80cd6c9b5544ba331b0c62e8 Mon Sep 17 00:00:00 2001 From: Staars Date: Thu, 13 Dec 2018 12:34:51 +0100 Subject: [PATCH 3/4] add debug code to show final command sequence --- sonoff/xsns_15_mhz19.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino index 6ddcb251a..594a47106 100644 --- a/sonoff/xsns_15_mhz19.ino +++ b/sonoff/xsns_15_mhz19.ino @@ -123,6 +123,9 @@ size_t MhzSendCmd(byte command_id) memcpy_P(&mhz_send[6], kMhzCommands[command_id] + sizeof(kMhzCommands[2]), sizeof(kMhzCommands[2])); mhz_send[8] = MhzCalculateChecksum(mhz_send); + snprintf_P(log_data, sizeof(log_data), PSTR("Final MhzCommand: %x %x %x %x %x %x %x %x %x"),mhz_send[0],mhz_send[1],mhz_send[2],mhz_send[3],mhz_send[4],mhz_send[5],mhz_send[6],mhz_send[7],mhz_send[8]); + AddLog(LOG_LEVEL_DEBUG); + return MhzSerial->write(mhz_send, sizeof(mhz_send)); } From df4f305e3ae502e37f94ca61750683388c30d2fb Mon Sep 17 00:00:00 2001 From: Staars Date: Thu, 13 Dec 2018 13:46:59 +0100 Subject: [PATCH 4/4] correcting memcpy calls --- sonoff/xsns_15_mhz19.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sonoff/xsns_15_mhz19.ino b/sonoff/xsns_15_mhz19.ino index 594a47106..523dd3a66 100644 --- a/sonoff/xsns_15_mhz19.ino +++ b/sonoff/xsns_15_mhz19.ino @@ -115,12 +115,12 @@ size_t MhzSendCmd(byte command_id) mhz_send[0] = 0xFF; // Start byte, fixed mhz_send[1] = 0x01; // Sensor number, 0x01 by default - memcpy_P(&mhz_send[2], kMhzCommands[command_id], sizeof(kMhzCommands[2])); + memcpy_P(&mhz_send[2], kMhzCommands[command_id], sizeof(uint16_t)); /* mhz_send[4] = 0x00; mhz_send[5] = 0x00; */ - memcpy_P(&mhz_send[6], kMhzCommands[command_id] + sizeof(kMhzCommands[2]), sizeof(kMhzCommands[2])); + memcpy_P(&mhz_send[6], kMhzCommands[command_id] + sizeof(uint16_t), sizeof(uint16_t)); mhz_send[8] = MhzCalculateChecksum(mhz_send); snprintf_P(log_data, sizeof(log_data), PSTR("Final MhzCommand: %x %x %x %x %x %x %x %x %x"),mhz_send[0],mhz_send[1],mhz_send[2],mhz_send[3],mhz_send[4],mhz_send[5],mhz_send[6],mhz_send[7],mhz_send[8]);