Skip to content

Commit

Permalink
v3.2.12
Browse files Browse the repository at this point in the history
3.2.12 20170126
* Add command Sleep 0 - 250 mSec for optional light sleep mode to lower
energy consumption (#272)
*   (Expect overall button/key/switch misses and wrong values on Sonoff
Pow)
* Add Hue brightness extension (#281)
*
* 3.2.11 20170126
* Add confirmation before Restart via webpage
* Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT
during web upload
* Fix LedPower status after button press (#279)
  • Loading branch information
arendst committed Jan 26, 2017
1 parent 9ccf9e8 commit 85f8eef
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-MQTT-OTA-Arduino - TASMOTA
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.2.11** - See ```sonoff/_releasenotes.ino``` for change information.
Current version is **3.2.12** - See ```sonoff/_releasenotes.ino``` for change information.

<img alt="Sonoff" src="https://github.com/arendst/arendst.github.io/blob/master/media/sonoffbasic.jpg" width="250" align="right" />
See [Wiki](https://github.com/arendst/Sonoff-MQTT-OTA-Arduino/wiki) for more information.<br />
Expand Down
Binary file modified api/arduino/sonoff.ino.bin
Binary file not shown.
7 changes: 6 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/* 3.2.11 20170126
/* 3.2.12 20170126
* Add command Sleep 0 - 250 mSec for optional light sleep mode to lower energy consumption (#272)
* (Expect overall button/key/switch misses and wrong values on Sonoff Pow)
* Add Hue brightness extension (#281)
*
* 3.2.11 20170126
* Add confirmation before Restart via webpage
* Fix possible ESP8285 flash problem by updating Flash Chip Mode to DOUT during web upload
* Fix LedPower status after button press (#279)
Expand Down
19 changes: 16 additions & 3 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* ====================================================
*/

#define VERSION 0x03020B00 // 3.2.11
#define VERSION 0x03020C00 // 3.2.12

#define SONOFF 1 // Sonoff, Sonoff RF, Sonoff SV, Sonoff Dual, Sonoff TH, S20 Smart Socket, 4 Channel
#define SONOFF_POW 9 // Sonoff Pow
Expand Down Expand Up @@ -330,6 +330,7 @@ struct SYSCFG {
char switch_topic[33];
byte mqtt_switch_retain;
uint8_t mqtt_enabled;
uint8_t sleep;
} sysCfg;

struct TIME_T {
Expand Down Expand Up @@ -501,6 +502,7 @@ void CFG_DefaultSet()
sysCfg.switchmode = SWITCH_MODE;
sysCfg.blinktime = APP_BLINKTIME;
sysCfg.blinkcount = APP_BLINKCOUNT;
sysCfg.sleep = APP_SLEEP;

strlcpy(sysCfg.domoticz_in_topic, DOMOTICZ_IN_TOPIC, sizeof(sysCfg.domoticz_in_topic));
strlcpy(sysCfg.domoticz_out_topic, DOMOTICZ_OUT_TOPIC, sizeof(sysCfg.domoticz_out_topic));
Expand Down Expand Up @@ -714,6 +716,9 @@ void CFG_Delta()
sysCfg.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
sysCfg.mqtt_enabled = MQTT_USE;
}
if (sysCfg.version < 0x03020C00) { // 3.2.12 - Add parameter
sysCfg.sleep = APP_SLEEP;
}

sysCfg.version = VERSION;
}
Expand Down Expand Up @@ -1284,6 +1289,13 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Model\":%d}"), sysCfg.model);
}
else if (!strcmp(type,"SLEEP")) {
if ((data_len > 0) && (payload >= 0) && (payload < 251)) {
sysCfg.sleep = payload;
restartflag = 2;
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Sleep\":\"%d%s\"}"), sysCfg.sleep, (sysCfg.mqtt_units) ? " mS" : "");
}
else if (!strcmp(type,"UPGRADE") || !strcmp(type,"UPLOAD")) {
if ((data_len > 0) && (payload == 1)) {
otaflag = 3;
Expand Down Expand Up @@ -1641,7 +1653,6 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
break;
}
blinks = 0;
// uint8_t led = sysCfg.ledstate &8;
setLed(sysCfg.ledstate &8);
}
snprintf_P(svalue, sizeof(svalue), PSTR("{\"LedPower\":\"%s\"}"), (sysCfg.ledstate &8) ? MQTT_STATUS_ON : MQTT_STATUS_OFF);
Expand Down Expand Up @@ -1872,7 +1883,7 @@ void mqttDataCb(char* topic, byte* data, unsigned int data_len)
}
if (type == NULL) {
blinks = 201;
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Commands1\":\"Status, SaveData, SaveSate, Upgrade, Otaurl, Restart, Reset, WifiConfig, Seriallog, Syslog, LogHost, LogPort, SSId1, SSId2, Password1, Password2, AP%s\"}"), (!grpflg) ? ", Hostname" : "");
snprintf_P(svalue, sizeof(svalue), PSTR("{\"Commands1\":\"Status, SaveData, SaveSate, Sleep, Upgrade, Otaurl, Restart, Reset, WifiConfig, Seriallog, Syslog, LogHost, LogPort, SSId1, SSId2, Password1, Password2, AP%s\"}"), (!grpflg) ? ", Hostname" : "");
if (sysCfg.message_format != JSON) json2legacy(stopic, svalue);
mqtt_publish(stopic, svalue);

Expand Down Expand Up @@ -2875,4 +2886,6 @@ void loop()
if (Serial.available()) serial();

yield();

if (sysCfg.sleep) delay(sysCfg.sleep);
}
1 change: 1 addition & 0 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ void WIFI_begin(uint8_t flag)
}
WiFi.disconnect();
WiFi.mode(WIFI_STA); // Disable AP mode
if (sysCfg.sleep) wifi_set_sleep_type(LIGHT_SLEEP_T); // Allow light sleep during idle times
// if (WiFi.getPhyMode() != WIFI_PHY_MODE_11N) WiFi.setPhyMode(WIFI_PHY_MODE_11N);
if (!WiFi.getAutoConnect()) WiFi.setAutoConnect(true);
// WiFi.setAutoReconnect(true);
Expand Down
1 change: 1 addition & 0 deletions sonoff/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
#define APP_POWERON_STATE 3 // [PowerOnState] Power On Relay state (0 = Off, 1 = On, 2 = Toggle Saved state, 3 = Saved state)
#define APP_BLINKTIME 10 // [BlinkTime] Time in 0.1 Sec to blink/toggle power for relay 1
#define APP_BLINKCOUNT 10 // [BlinkCount] Number of blinks (0 = 32000)
#define APP_SLEEP 0 // [Sleep] Sleep time to lower energy consumption (0 = Off, 1 - 250 mSec)

#define TEMP_CONVERSION 0 // Convert temperature to (0 = Celsius or 1 = Fahrenheit)
#define TEMP_RESOLUTION 1 // Maximum number of decimals (0 - 3) showing sensor Temperature
Expand Down
52 changes: 42 additions & 10 deletions sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ const char HUE_DESCRIPTION_XML[] PROGMEM =
const char HUE_LIGHT_STATUS_JSON[] PROGMEM =
"{\"state\":"
"{\"on\":{state},"
"\"bri\":0,"
"\"hue\":0,"
"\"sat\":0,"
"\"bri\":{b},"
"\"hue\":{h},"
"\"sat\":{s},"
"\"effect\":\"none\","
"\"ct\":0,"
"\"alert\":\"none\","
Expand All @@ -287,6 +287,9 @@ const char HUE_LIGHT_STATUS_JSON[] PROGMEM =
"\"uniqueid\":\"{j2}\","
"\"swversion\":\"66012040\""
"}";

const char HUE_LIGHT_RESPONSE_JSON[] PROGMEM =
"{\"success\":{\"{api}/{id}/{cmd}\":{res}}}";
#endif // USE_HUE_EMULATION

#define DNS_PORT 53
Expand Down Expand Up @@ -1339,6 +1342,13 @@ void hue_lights(String path)
response.replace("{state}", (power & (0x01 << (i-1))) ? "true" : "false");
response.replace("{j1}", sysCfg.friendlyname[i-1]);
response.replace("{j2}", hue_deviceId(i));
#ifdef USE_WS2812
ws2812_replaceHSB(&response);
#else
response.replace("{h}", "0");
response.replace("{s}", "0");
response.replace("{b}", "0");
#endif // USE_WS2812
}
response += "}";
webServer->send(200, "application/json", response);
Expand All @@ -1349,8 +1359,11 @@ void hue_lights(String path)
path.remove(path.indexOf("/state")); // Remove /state
device = atoi(path.c_str());
if ((device < 1) || (device > Maxdevice)) device = 1;
response = "{\"success\":{\"/lights/";
response += device;
response = "[";
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
response.replace("{api}", "/lights");
response.replace("{id}", String(device));
response.replace("{cmd}", "state/on");
if (webServer->args() == 1)
{
String json = webServer->arg(0);
Expand All @@ -1360,20 +1373,32 @@ void hue_lights(String path)
if (json.indexOf("false") >= 0) // false -> turn device off
{
do_cmnd_power(device, 0);
response +="/state/on\": false";
response.replace("{res}", "false");
}
else if(json.indexOf("true") >= 0) // true -> Turn device on
{
do_cmnd_power(device, 1);
response +="/state/on\": true";
response.replace("{res}", "true");
}
else
{
response +="/state/on\": ";
response += (power & (0x01 << (device-1))) ? "true" : "false";
response.replace("{res}", (power & (0x01 << (device-1))) ? "true" : "false");
}
}
response += "}}";
#ifdef USE_WS2812
if ((tmp=json.indexOf("\"bri\":")) >= 0)
{
tmp=atoi(json.substring(tmp+6).c_str());
ws2812_changeBrightness(tmp);
response += ",";
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
response.replace("{api}", "/lights");
response.replace("{id}", String(device));
response.replace("{cmd}", "state/bri");
response.replace("{res}", String(tmp));
}
#endif // USE_WS2812
response += "]";
webServer->send(200, "application/json", response);
}
else webServer->send(406, "application/json", "{}");
Expand All @@ -1387,6 +1412,13 @@ void hue_lights(String path)
response.replace("{state}", (power & (0x01 << (device -1))) ? "true" : "false");
response.replace("{j1}", sysCfg.friendlyname[device -1]);
response.replace("{j2}", hue_deviceId(device));
#ifdef USE_WS2812
ws2812_replaceHSB(&response);
#else
response.replace("{h}", "0");
response.replace("{s}", "0");
response.replace("{b}", "0");
#endif // USE_WS2812
webServer->send(200, "application/json", response);
}
else webServer->send(406, "application/json", "{}");
Expand Down
28 changes: 27 additions & 1 deletion sonoff/xdrv_ws2812.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ POSSIBILITY OF SUCH DAMAGE.
NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> *strip = NULL;
#endif // USE_WS2812_DMA

#define COLOR_SATURATION 254.0f

struct wsColor {
uint8_t red, green, blue;
};
Expand Down Expand Up @@ -147,12 +149,36 @@ void ws2812_setColor(uint16_t led, char* colstr)
sysCfg.ws_red = (uint8_t)fmyRed;
sysCfg.ws_green = (uint8_t)fmyGrn;
sysCfg.ws_blue = (uint8_t)fmyBlu;

lany = 1;
}
}
}

void ws2812_replaceHSB(String *response)
{
ws2812_setDim(sysCfg.ws_dimmer);
HsbColor hsb=HsbColor(dcolor);
response->replace("{h}", String((uint16_t)(65535.0f * hsb.H)));
response->replace("{s}", String((uint8_t)(COLOR_SATURATION * hsb.S)));
response->replace("{b}", String((uint8_t)(COLOR_SATURATION * hsb.B)));
}

void ws2812_changeBrightness(uint8_t bri)
{
char rgb[7];

//sysCfg.ws_ledtable=1; // Switch on Gamma Correction for "natural" brightness controll
ws2812_setDim(sysCfg.ws_dimmer);
HsbColor hsb = HsbColor(dcolor);
if (!bri) bri=1;
if (bri==255) bri=252;
hsb.B=(float)(bri/COLOR_SATURATION);
RgbColor tmp = RgbColor(hsb);
sprintf(rgb,"%02X%02X%02X", tmp.R, tmp.G, tmp.B);
ws2812_setColor(0,rgb);
}

void ws2812_getColor(uint16_t led, char* svalue, uint16_t ssvalue)
{
RgbColor mcolor;
Expand Down

0 comments on commit 85f8eef

Please sign in to comment.