Skip to content

Commit

Permalink
v3.2.1
Browse files Browse the repository at this point in the history
3.2.1 20170113
* Fix some failed command decoding (#228)
* Removed passwords from status messages (#216)
* Add I2C BH1750 sensor (#222)
* Sensor rewrite preparing for online selection
  • Loading branch information
arendst committed Jan 13, 2017
1 parent ff1921c commit 1d9447b
Show file tree
Hide file tree
Showing 13 changed files with 638 additions and 505 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
## Sonoff-MQTT-OTA-Arduino
Provide ESP8266 based itead Sonoff with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.

Current version is **3.1.16** - See ```sonoff/_releasenotes.ino``` for change information.
Current version is **3.2.1** - See ```sonoff/_releasenotes.ino``` for change information.

See [Wiki](https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/wiki) for more information.
See [Community](https://groups.google.com/d/forum/sonoffusers) for forum and more user experienkce.

Starting with version 2.0.0 the following devices are supported:
<img alt="Sonoff" src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoffbasic.jpg" width="250" align="right" />
- iTead Sonoff Basic
- iTead Sonoff RF
- iTead Sonoff SV
- iTead Sonoff Dual
- [iTead Sonoff Basic](http://sonoff.itead.cc/en/products/sonoff/sonoff-basic)
- [iTead Sonoff RF](http://sonoff.itead.cc/en/products/sonoff/sonoff-rf)
- [iTead Sonoff SV](https://www.itead.cc/sonoff-sv.html)
- [iTead Sonoff TH10/TH16 with temperature sensor](http://sonoff.itead.cc/en/products/sonoff/sonoff-th)
<img alt="Sonoff" src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoff_th.jpg" width="250" align="right" />
- iTead Sonoff TH10 / TH16 with temperature sensor
- iTead Sonoff Pow
- iTead Sonoff Touch
- iTead Sonoff 4CH
- iTead S20 Smart Socket
- iTead Motor Clockwise/Anticlockwise
- ElectroDragon IoT Relay Board

See [my Wiki](https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/wiki) for more information.
- [iTead Sonoff Dual](http://sonoff.itead.cc/en/products/sonoff/sonoff-dual)
- [iTead Sonoff Pow](http://sonoff.itead.cc/en/products/sonoff/sonoff-pow)
- [iTead Sonoff 4CH](http://sonoff.itead.cc/en/products/sonoff/sonoff-4ch)
- [iTead S20 Smart Socket](http://sonoff.itead.cc/en/products/residential/s20-socket)
- [iTead Slampher](http://sonoff.itead.cc/en/products/residential/slampher-rf)
- [iTead Sonoff Touch](http://sonoff.itead.cc/en/products/residential/sonoff-touch)
- [iTead 1 Channel Switch 5V / 12V](https://www.itead.cc/smart-home/inching-self-locking-wifi-wireless-switch.html)
- [iTead Motor Clockwise/Anticlockwise](https://www.itead.cc/smart-home/motor-reversing-wifi-wireless-switch.html)
- [Electrodragon IoT Relay Board](http://www.electrodragon.com/product/wifi-iot-relay-board-based-esp8266/)

<img alt="Sonoff" src="https://github.com/arendst/arendst.github.io/blob/master/media/sonofftoucheu.jpg" height="280" align="left" />
<img alt="Sonoff" src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoff4ch.jpg" height="250" align="right" />
Binary file modified api/arduino/sonoff.ino.bin
Binary file not shown.
10 changes: 9 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
/* 3.1.16 20170109
/* 3.2.1 20170113
* Fix some failed command decoding (#228)
* Removed passwords from status messages (#216)
*
* 3.2.0 20170111
* Add I2C BH1750 sensor (#222)
* Sensor rewrite preparing for online selection
*
* 3.1.16 20170109
* Fix Domoticz possible error condition
* Remove Wifi password from connection message (#216)
* Add Configure Other menu item to web page (#209)
Expand Down
399 changes: 43 additions & 356 deletions sonoff/sonoff.ino

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions sonoff/user_config.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*********************************************************************************************\
* User specific configuration parameters
*
*
* ATTENTION: Changes to most PARAMETER defines will only override flash settings if you change
* define CFG_HOLDER.
* define CFG_HOLDER.
* Most parameters can be changed online using commands via MQTT, WebConsole or serial
*
* Corresponding MQTT/Serial/Console commands in [brackets]
Expand Down Expand Up @@ -136,12 +136,12 @@

/*********************************************************************************************\
* Sonoff Basic, Sonoff RF, Sonoff SV, Sonoff Dual, Sonoff TH, S20 Smart Socket
*
*
* >>> Select Board "Generic ESP8266 Module" and Flash Size "1M (64K SPIFFS)" <<<
\*********************************************************************************************/

#if MODULE == SONOFF // programming header 1:3.3V 2:rx 3:tx 4:gnd
#define APP_NAME "Sonoff 8266 module"
#define APP_NAME "Sonoff 8266 Module"
#define MQTT_GRPTOPIC "sonoffs" // [GroupTopic] MQTT Group topic
/*-------------------------------------------------------------------------------------------*/
#define LED_PIN 13 // GPIO 13 = Green/Blue Led (0 = On, 1 = Off) - Sonoff
Expand Down Expand Up @@ -172,20 +172,20 @@
// *** Option 2 - Use Adafruit DHT library - Select either Option 1 OR Option 2
// #define SEND_TELEMETRY_DHT2 // Enable sending temperature and humidity telemetry
/*-------------------------------------------------------------------------------------------*\
* I2C devices BMP085, BMP180, BMP280, BME280 and HTU21D
* I2C devices BH1750, BMP085, BMP180, BMP280, BME280 and HTU21D
\*-------------------------------------------------------------------------------------------*/
#define I2C_SDA_PIN 4 // GPIO 04 = I2C SDA (Sonoff_TH10A(16A)- Needs extra hardware)
#define I2C_SCL_PIN 14 // GPIO 14 = I2C SCL (Sonoff_TH10A(16A))
// #define SEND_TELEMETRY_I2C // Enable sending I2C sensor telemetry

/*********************************************************************************************\
* Sonoff Touch and Sonoff 4CH
*
*
* >>> Select Board "Generic ESP8285 Module" (=Flash Mode "DOUT") and Flash Size "1M (64K SPIFFS)" <<<
\*********************************************************************************************/

#elif MODULE == SONOFF_2 // programming header 1:3.3V 2:rx 3:tx 4:gnd
#define APP_NAME "Sonoff 8285 module"
#define APP_NAME "Sonoff 8285 Module"
#define MQTT_GRPTOPIC "sonoff2s" // [GroupTopic] MQTT Group topic
/*-------------------------------------------------------------------------------------------*/
#define LED_PIN 13 // GPIO 13 = Green/Blue Led (0 = On, 1 = Off) - Sonoff
Expand Down Expand Up @@ -226,20 +226,20 @@
// *** Option 2 - Use Adafruit DHT library - Select either Option 1 OR Option 2
// #define SEND_TELEMETRY_DHT2 // Enable sending temperature and humidity telemetry
/*-------------------------------------------------------------------------------------------*\
* I2C devices BMP085, BMP180, BMP280, BME280 and HTU21D
* I2C devices BH1750, BMP085, BMP180, BMP280, BME280 and HTU21D
\*-------------------------------------------------------------------------------------------*/
#define I2C_SDA_PIN 8 // GPIO 08 = I2C SDA (Sonoff 4CH - Needs extra hardware)
#define I2C_SCL_PIN 7 // GPIO 07 = I2C SCL (Sonoff 4CH - Needs extra hardware)
// #define SEND_TELEMETRY_I2C // Enable sending I2C sensor telemetry

/*********************************************************************************************\
* Sonoff Pow
*
*
* >>> Select Board "Generic ESP8266 Module" and Flash Size "1M (64K SPIFFS)" or "4M (1M SPIFFS)" <<<
\*********************************************************************************************/

#elif MODULE == SONOFF_POW // programming header 1:3.3V 2:rx 3:tx 4:gnd
#define APP_NAME "Sonoff Pow module"
#define APP_NAME "Sonoff Pow Module"
#define MQTT_GRPTOPIC "pows" // [GroupTopic] MQTT Group topic
#define USE_POWERMONITOR // Enable Power Monitoring
// #define USE_POWERCALIBRATION // Enable setting Calibration parameters by user commands
Expand All @@ -256,12 +256,12 @@

/*********************************************************************************************\
* Motor Clockwise/Anticlockwise
*
*
* >>> Select Board "Generic ESP8266 Module" and Flash Size "1M (64K SPIFFS)" <<<
\*********************************************************************************************/

#elif MODULE == MOTOR_CAC // programming pins 6:3.3V 7:rx 8:tx 9:gnd of PSA-B
#define APP_NAME "Motor C/AC module"
#define APP_NAME "Motor C/AC Module"
#define MQTT_GRPTOPIC "motors" // [GroupTopic] MQTT Group topic
/*-------------------------------------------------------------------------------------------*/
#define LED_PIN 13 // GPIO 13 = Green/Blue Led (0 = On, 1 = Off) - Sonoff
Expand All @@ -271,12 +271,12 @@

/*********************************************************************************************\
* Electrodragon
*
*
* >>> Select Board "Generic ESP8266 Module" and Flash Size "1M (64K SPIFFS)" or "4M (1M SPIFFS)" <<<
\*********************************************************************************************/

#elif MODULE == ELECTRO_DRAGON // programming header 5V/3V/gnd/
#define APP_NAME "ElectroDragon module"
#define APP_NAME "ElectroDragon Module"
#define MQTT_GRPTOPIC "dragons" // [GroupTopic] MQTT Group topic
/*-------------------------------------------------------------------------------------------*/
#define LED_PIN 16 // GPIO 16 = Led (0 = Off, 1 = On)
Expand Down Expand Up @@ -309,7 +309,7 @@
// *** Option 2 - Use Adafruit DHT library - Select either Option 1 OR Option 2
// #define SEND_TELEMETRY_DHT2 // Enable sending temperature and humidity telemetry
/*-------------------------------------------------------------------------------------------*\
* I2C devices BMP085, BMP180, BMP280, BME280 and HTU21D
* I2C devices BH1750, BMP085, BMP180, BMP280, BME280 and HTU21D
\*-------------------------------------------------------------------------------------------*/
#define I2C_SDA_PIN 4 // GPIO 4 = I2C SDA (Sonoff_TH10A(16A)- Needs extra hardware)
#define I2C_SCL_PIN 14 // GPIO 14 = I2C SCL (Sonoff_TH10A(16A))
Expand Down
94 changes: 11 additions & 83 deletions sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const char HTTP_FORM_MQTT[] PROGMEM =
"<br/><b>Port</b> (" STR(MQTT_PORT) ")<br/><input id='ml' name='ml' length=5 placeholder='" STR(MQTT_PORT) "' value='{m2}'><br/>"
"<br/><b>Client Id</b> ({m0})<br/><input id='mc' name='mc' length=32 placeholder='" MQTT_CLIENT_ID "' value='{m3}'><br/>"
"<br/><b>User</b> (" MQTT_USER ")<br/><input id='mu' name='mu' length=32 placeholder='" MQTT_USER "' value='{m4}'><br/>"
// "<br/><b>Password</b> (" MQTT_PASS ")<br/><input id='mp' name='mp' length=32 placeholder='" MQTT_PASS "' value='{m5}'><br/>"
"<br/><b>Password</b><br/><input id='mp' name='mp' length=32 type='password' placeholder='" MQTT_PASS "' value='{m5}'><br/>"
"<br/><b>Topic</b> (" MQTT_TOPIC ")<br/><input id='mt' name='mt' length=32 placeholder='" MQTT_TOPIC" ' value='{m6}'><br/>";
#ifdef USE_DOMOTICZ
Expand Down Expand Up @@ -405,100 +404,29 @@ void handleRoot()
page += F("</tr></table><br/>");
}

String tpage = "";
#ifdef USE_POWERMONITOR
float ped, pi, pc;
uint16_t pe, pw, pu;
char ptemp[10];
hlw_readEnergy(0, ped, pe, pw, pu, pi, pc);
page += F("<table style='width:100%'>");
page += F("<tr><td>Voltage: </td><td>"); page += String(pu); page += F(" V</td></tr>");
dtostrf(pi, 1, 3, ptemp);
page += F("<tr><td>Current: </td><td>"); page += ptemp; page += F(" A</td></tr>");
page += F("<tr><td>Power: </td><td>"); page += String(pw); page += F(" W</td></tr>");
dtostrf(pc, 1, 2, ptemp);
page += F("<tr><td>Power Factor: </td><td>"); page += ptemp; page += F("</td></tr>");
dtostrf(ped, 1, 3, ptemp);
page += F("<tr><td>Energy Today: </td><td>"); page += ptemp; page += F(" kWh</td></tr>");
dtostrf((float)sysCfg.hlw_kWhyesterday / 100000000, 1, 3, ptemp);
page += F("<tr><td>Energy Yesterday: </td><td>"); page += ptemp; page += F(" kWh</td></tr>");
page += F("</table><br/>");
tpage += hlw_webPresent();
#endif // USE_POWERMONITOR

#ifdef SEND_TELEMETRY_DS18B20
// Needs TelePeriod to refresh data (Do not do it here as it takes too much time)
char stemp[10], sconv[10];
float st;
if (dsb_readTemp(TEMP_CONVERSION, st)) { // Check if read failed
snprintf_P(sconv, sizeof(sconv), PSTR("&deg;%c"), (TEMP_CONVERSION) ? 'F' : 'C');
page += F("<table style='width:100%'>");
dtostrf(st, 1, TEMP_RESOLUTION &3, stemp);
page += F("<tr><td>DSB Temperature: </td><td>"); page += stemp; page += sconv; page += F("</td></tr>");
page += F("</table><br/>");
}
tpage += dsb_webPresent();
#endif // SEND_TELEMETRY_DS18B20

#ifdef SEND_TELEMETRY_DS18x20
char xtemp[10], xconv[10];
float xt;
uint8_t xfl = 0, i;
snprintf_P(xconv, sizeof(xconv), PSTR("&deg;%c"), (TEMP_CONVERSION) ? 'F' : 'C');
for (i = 0; i < ds18x20_sensors(); i++) {
if (ds18x20_read(i, TEMP_CONVERSION, xt)) { // Check if read failed
if (!xfl) {
page += F("<table style='width:100%'>");
xfl = 1;
}
dtostrf(xt, 1, TEMP_RESOLUTION &3, xtemp);
page += F("<tr><td>DS"); page += String(i +1); page += F(" Temperature: </td><td>"); page += xtemp; page += xconv; page += F("</td></tr>");
}
}
if (xfl) page += F("</table><br/>");
tpage += ds18x20_webPresent();
#endif // SEND_TELEMETRY_DS18x20

#if defined(SEND_TELEMETRY_DHT) || defined(SEND_TELEMETRY_DHT2)
char dtemp[10], dconv[10];
float dt, dh;
if (dht_readTempHum(TEMP_CONVERSION, dt, dh)) { // Read temperature as Celsius (the default)
snprintf_P(dconv, sizeof(dconv), PSTR("&deg;%c"), (TEMP_CONVERSION) ? 'F' : 'C');
page += F("<table style='width:100%'>");
dtostrf(dt, 1, TEMP_RESOLUTION &3, dtemp);
page += F("<tr><td>DHT Temperature: </td><td>"); page += dtemp; page += dconv; page += F("</td></tr>");
dtostrf(dh, 1, HUMIDITY_RESOLUTION &3, dtemp);
page += F("<tr><td>DHT Humidity: </td><td>"); page += dtemp; page += F("%</td></tr>");
page += F("</table><br/>");
}
tpage += dht_webPresent();
#endif // SEND_TELEMETRY_DHT/2

#if defined(SEND_TELEMETRY_I2C)
char itemp[10], iconv[10];
snprintf_P(iconv, sizeof(iconv), PSTR("&deg;%c"), (TEMP_CONVERSION) ? 'F' : 'C');
if(htu_found()) {
float t_htu21 = htu21_readTemperature(TEMP_CONVERSION);
float h_htu21 = htu21_readHumidity();
h_htu21 = htu21_compensatedHumidity(h_htu21, t_htu21);
page += F("<table style='width:100%'>");
dtostrf(t_htu21, 1, TEMP_RESOLUTION &3, itemp);
page += F("<tr><td>HTU Temperature: </td><td>"); page += itemp; page += iconv; page += F("</td></tr>");
dtostrf(h_htu21, 1, HUMIDITY_RESOLUTION &3, itemp);
page += F("<tr><td>HTU Humidity: </td><td>"); page += itemp; page += F("%</td></tr>");
page += F("</table><br/>");
}
if(bmp_found()) {
double t_bmp = bmp_readTemperature(TEMP_CONVERSION);
double p_bmp = bmp_readPressure();
double h_bmp = bmp_readHumidity();
tpage += htu_webPresent();
tpage += bmp_webPresent();
tpage += bh1750_webPresent();
#endif // SEND_TELEMETRY_I2C
if (tpage.length() > 0) {
page += F("<table style='width:100%'>");
dtostrf(t_bmp, 1, TEMP_RESOLUTION &3, itemp);
page += F("<tr><td>BMP Temperature: </td><td>"); page += itemp; page += iconv; page += F("</td></tr>");
if (!strcmp(bmp_type(),"BME280")) {
dtostrf(h_bmp, 1, HUMIDITY_RESOLUTION &3, itemp);
page += F("<tr><td>BMP Humidity: </td><td>"); page += itemp; page += F("%</td></tr>");
}
dtostrf(p_bmp, 1, PRESSURE_RESOLUTION &3, itemp);
page += F("<tr><td>BMP Pressure: </td><td>"); page += itemp; page += F(" hPa</td></tr>");
page += tpage;
page += F("</table><br/>");
}
#endif // SEND_TELEMETRY_I2C

if (_httpflag == HTTP_ADMIN) {
page += FPSTR(HTTP_BTN_MENU1);
Expand Down
88 changes: 71 additions & 17 deletions sonoff/xsns_bmp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -383,26 +383,13 @@ double bmp_readHumidity(void)
return 0;
}

char* bmp_type()
{
return bmpstype;
}

uint8_t bmp_address()
{
return bmpaddr;
}

uint8_t bmp_found()
{
return bmptype;
}

boolean bmp_detect()
{
if (bmptype) return true;

char log[LOGSZ];
boolean success = false;

if (bmptype) return true;
bmpaddr = BMP_ADDR;
bmptype = i2c_read8(bmpaddr, BMP_REGISTER_CHIPID);
if (!bmptype) {
Expand All @@ -423,7 +410,74 @@ boolean bmp_detect()
success = bme280_calibrate();
snprintf_P(bmpstype, sizeof(bmpstype), PSTR("BME280"));
}
if (!success) bmptype = 0;
if (success) {
snprintf_P(log, sizeof(log), PSTR("I2C: %s found at address 0x%x"), bmpstype, bmpaddr);
addLog(LOG_LEVEL_DEBUG, log);
} else {
bmptype = 0;
}
return success;
}

/*********************************************************************************************\
* Presentation
\*********************************************************************************************/

void bmp_mqttPresent(char* stopic, uint16_t sstopic, char* svalue, uint16_t ssvalue, uint8_t* djson)
{
if (!bmptype) return;

char stemp1[10], stemp2[10], stemp3[10];

double t_bmp = bmp_readTemperature(TEMP_CONVERSION);
double p_bmp = bmp_readPressure();
double h_bmp = bmp_readHumidity();
dtostrf(t_bmp, 1, TEMP_RESOLUTION &3, stemp1);
dtostrf(p_bmp, 1, PRESSURE_RESOLUTION &3, stemp2);
dtostrf(h_bmp, 1, HUMIDITY_RESOLUTION &3, stemp3);
if (sysCfg.message_format == JSON) {
if (!strcmp(bmpstype,"BME280")) {
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s\":{\"Temperature\":\"%s\", \"Humidity\":\"%s\", \"Pressure\":\"%s\"}"),
svalue, bmpstype, stemp1, stemp3, stemp2);
} else {
snprintf_P(svalue, ssvalue, PSTR("%s, \"%s\":{\"Temperature\":\"%s\", \"Pressure\":\"%s\"}"),
svalue, bmpstype, stemp1, stemp2);
}
*djson = 1;
} else {
snprintf_P(stopic, sstopic, PSTR("%s/%s/%s/TEMPERATURE"), PUB_PREFIX2, sysCfg.mqtt_topic, bmpstype);
snprintf_P(svalue, ssvalue, PSTR("%s%s"), stemp1, (sysCfg.mqtt_units) ? (TEMP_CONVERSION) ? " F" : " C" : "");
mqtt_publish(stopic, svalue);
if (!strcmp(bmpstype,"BME280")) {
snprintf_P(stopic, sstopic, PSTR("%s/%s/%s/HUMIDITY"), PUB_PREFIX2, sysCfg.mqtt_topic, bmpstype);
snprintf_P(svalue, ssvalue, PSTR("%s%s"), stemp3, (sysCfg.mqtt_units) ? " %" : "");
mqtt_publish(stopic, svalue);
}
snprintf_P(stopic, sstopic, PSTR("%s/%s/%s/PRESSURE"), PUB_PREFIX2, sysCfg.mqtt_topic, bmpstype);
snprintf_P(svalue, ssvalue, PSTR("%s%s"), stemp2, (sysCfg.mqtt_units) ? " hPa" : "");
mqtt_publish(stopic, svalue);
}
}

String bmp_webPresent()
{
String page = "";
if (bmptype) {
char itemp[10], iconv[10];

snprintf_P(iconv, sizeof(iconv), PSTR("&deg;%c"), (TEMP_CONVERSION) ? 'F' : 'C');
double t_bmp = bmp_readTemperature(TEMP_CONVERSION);
double p_bmp = bmp_readPressure();
double h_bmp = bmp_readHumidity();
dtostrf(t_bmp, 1, TEMP_RESOLUTION &3, itemp);
page += F("<tr><td>BMP Temperature: </td><td>"); page += itemp; page += iconv; page += F("</td></tr>");
if (!strcmp(bmpstype,"BME280")) {
dtostrf(h_bmp, 1, HUMIDITY_RESOLUTION &3, itemp);
page += F("<tr><td>BMP Humidity: </td><td>"); page += itemp; page += F("%</td></tr>");
}
dtostrf(p_bmp, 1, PRESSURE_RESOLUTION &3, itemp);
page += F("<tr><td>BMP Pressure: </td><td>"); page += itemp; page += F(" hPa</td></tr>");
}
return page;
}
#endif //SEND_TELEMETRY_I2C
Loading

0 comments on commit 1d9447b

Please sign in to comment.