Skip to content

Commit

Permalink
v4.0.6
Browse files Browse the repository at this point in the history
4.0.6 20170316
* Fix to better find device by Wifi hostname
* Fix compile error when some I2C devices are disabled
* Add (experimental) support for SHT1X emulating I2C (#97)
* Add ADC to ElectroDragon (#203)
* Add support for Sonoff Dev (#206)
  • Loading branch information
arendst committed Mar 16, 2017
1 parent 7aebdbb commit c4cdd44
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Sonoff-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 **4.0.5** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.
Current version is **4.0.6** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/master/sonoff/_releasenotes.ino) for change information.

- This version provides all (Sonoff) modules in one file and starts up with Sonoff Basic.
- Once uploaded select module using the configuration webpage or the commands ```Modules``` and ```Module```.
Expand All @@ -24,6 +24,7 @@ The following devices are supported:
- [iTead Slampher](http://sonoff.itead.cc/en/products/residential/slampher-rf)
- [iTead Sonoff Touch](http://sonoff.itead.cc/en/products/residential/sonoff-touch)
- [iTead Sonoff Led](http://sonoff.itead.cc/en/products/appliances/sonoff-led)
- [iTead Sonoff Dev](https://www.itead.cc/sonoff-dev.html)
- [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/)
Expand Down
Binary file modified api/arduino/sonoff.ino.bin
Binary file not shown.
9 changes: 8 additions & 1 deletion sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
/* 4.0.5 20170314
/* 4.0.6 20170316
* Fix to better find device by Wifi hostname
* Fix compile error when some I2C devices are disabled
* Add (experimental) support for SHT1X emulating I2C (#97)
* Add ADC to ElectroDragon (#203)
* Add support for Sonoff Dev (#206)
*
* 4.0.5 20170314
* Add command Status 11 to show power status with Vcc if define USE_ADC_VCC is enabled (default)
* Add ADC input to Sonoff SV and Wemos D1 mini - Needs recompile with define USE_ADC_VCC disabled (#137)
* Add MQTT host:port to timeout message (#199)
Expand Down
25 changes: 12 additions & 13 deletions sonoff/sonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

//#define ALLOW_MIGRATE_TO_V3
#ifdef ALLOW_MIGRATE_TO_V3
#define VERSION 0x03091C00 // 3.9.28
#define VERSION 0x03091D00 // 3.9.29
#else
#define VERSION 0x04000500 // 4.0.5
#define VERSION 0x04000600 // 4.0.6
#endif // ALLOW_MIGRATE_TO_V3

enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
Expand Down Expand Up @@ -149,7 +149,7 @@ enum butt_t {PRESSED, NOT_PRESSED};
#error "MQTT_MAX_PACKET_SIZE is too small in libraries/PubSubClient/src/PubSubClient.h, increase it to at least 427"
#endif

#include <Ticker.h> // RTC
#include <Ticker.h> // RTC, HLW8012, OSWatch
#include <ESP8266WiFi.h> // MQTT, Ota, WifiManager
#include <ESP8266HTTPClient.h> // MQTT, Ota
#include <ESP8266httpUpdate.h> // Ota
Expand Down Expand Up @@ -1528,6 +1528,9 @@ void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)
#endif // USE_DHT
#ifdef USE_I2C
if (i2c_flg) {
#ifdef USE_SHT
sht_mqttPresent(svalue, ssvalue, djson);
#endif // USE_SHT
#ifdef USE_HTU
htu_mqttPresent(svalue, ssvalue, djson);
#endif // USE_HTU
Expand All @@ -1544,13 +1547,6 @@ void sensors_mqttPresent(char* svalue, uint16_t ssvalue, uint8_t* djson)

/********************************************************************************************/

void every_second_cb()
{
// 1 second rtc interrupt routine
// Keep this code small (every_second is to large - it'll trip exception)

}

void every_second()
{
char svalue[MESSZ];
Expand Down Expand Up @@ -1605,6 +1601,9 @@ void every_second()
#endif // USE_DHT
#ifdef USE_I2C
if (i2c_flg) {
#ifdef USE_SHT
sht_detect();
#endif // USE_SHT
#ifdef USE_HTU
htu_detect();
#endif // USE_HTU
Expand Down Expand Up @@ -2053,7 +2052,7 @@ void GPIO_init()

#ifdef USE_I2C
i2c_flg = ((pin[GPIO_I2C_SCL] < 99) && (pin[GPIO_I2C_SDA] < 99));
if (i2c_flg) Wire.begin(pin[GPIO_I2C_SDA],pin[GPIO_I2C_SCL]);
if (i2c_flg) Wire.begin(pin[GPIO_I2C_SDA], pin[GPIO_I2C_SCL]);
#endif // USE_I2C

#ifdef USE_WS2812
Expand Down Expand Up @@ -2123,7 +2122,7 @@ void setup()
} else {
snprintf_P(Hostname, sizeof(Hostname)-1, sysCfg.hostname);
}
WIFI_Connect(Hostname);
WIFI_Connect();

getClient(MQTTClient, sysCfg.mqtt_client, sizeof(MQTTClient));

Expand Down Expand Up @@ -2151,7 +2150,7 @@ void setup()
}
blink_powersave = power;

rtc_init(every_second_cb);
rtc_init();

snprintf_P(log, sizeof(log), PSTR("APP: Project %s %s (Topic %s, Fallback %s, GroupTopic %s) Version %s"),
PROJECT, sysCfg.friendlyname[0], sysCfg.mqtt_topic, MQTTClient, sysCfg.mqtt_grptopic, Version);
Expand Down
18 changes: 17 additions & 1 deletion sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum module_t {
EXS_RELAY,
WION,
WEMOS,
SONOFF_DEV,
MAXMODULE };

/********************************************************************************************/
Expand Down Expand Up @@ -308,7 +309,7 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_USER, // GPIO14 Optional sensor
GPIO_USER, // GPIO15 Optional sensor
GPIO_LED1, // GPIO16 Green/Blue Led (1 = On, 0 = Off)
0
GPIO_ADC0 // ADC0 A0 Analog input
},
{ "EXS Relay", // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266)
// Module Pin 1 VCC 3V3, Module Pin 6 GND
Expand Down Expand Up @@ -352,6 +353,21 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
GPIO_USER, // GPIO15 D8
GPIO_USER, // GPIO16 D0 Wemos Wake
GPIO_ADC0 // ADC0 A0 Analog input
},
{ "Sonoff Dev", // Sonoff Dev (ESP8266)
GPIO_KEY1, // GPIO00 E-FW Button
GPIO_USER, // GPIO01 TX Serial RXD and Optional sensor
0, // GPIO02
GPIO_USER, // GPIO03 RX Serial TXD and Optional sensor
GPIO_USER, // GPIO04 Optional sensor
GPIO_USER, // GPIO05 Optional sensor
0, 0, 0, 0, 0, 0, // Flash connection
GPIO_USER, // GPIO12
GPIO_LED1_INV, // GPIO13 BLUE LED
GPIO_USER, // GPIO14 Optional sensor
0, // GPIO15
0, // GPIO16
GPIO_ADC0 // ADC0 A0 Analog input
}
};

16 changes: 3 additions & 13 deletions sonoff/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ void WIFI_begin(uint8_t flag)
#ifdef USE_STATIC_IP_ADDRESS
WiFi.config(ipadd, ipgat, ipsub, ipdns); // Set static IP
#endif // USE_STATIC_IP_ADDRESS
WiFi.hostname(Hostname);
WiFi.begin(sysCfg.sta_ssid[sysCfg.sta_active], sysCfg.sta_pwd[sysCfg.sta_active]);
snprintf_P(log, sizeof(log), PSTR("Wifi: Connecting to AP%d %s in mode 11%c as %s..."),
sysCfg.sta_active +1, sysCfg.sta_ssid[sysCfg.sta_active], PhyMode[WiFi.getPhyMode() & 0x3], Hostname);
Expand Down Expand Up @@ -417,10 +418,9 @@ int WIFI_State()
return state;
}

void WIFI_Connect(char *Hostname)
void WIFI_Connect()
{
WiFi.persistent(false); // Solve possible wifi init errors
WiFi.hostname(Hostname);
_wifistatus = 0;
_wifiretry = WIFI_RETRY_SEC;
_wificounter = 1;
Expand Down Expand Up @@ -591,8 +591,6 @@ static const char monthNames[] = "JanFebMarAprMayJunJulAugSepOctNovDec";

uint32_t utctime = 0, loctime = 0, dsttime = 0, stdtime = 0, ntptime = 0, midnight = 1451602800;

rtcCallback rtcCb = NULL;

String getBuildDateTime()
{
// "2017-03-07T11:08:02"
Expand Down Expand Up @@ -821,21 +819,13 @@ void rtc_second()
midnight = loctime;
}
rtcTime.Year += 1970;
if (rtcCb) rtcCb();
}

void rtc_init(rtcCallback cb)
void rtc_init()
{
rtcCb = cb;

// sntp_setservername(0, (char*)NTP_SERVER1);
// sntp_setservername(1, (char*)NTP_SERVER2);
// sntp_setservername(2, (char*)NTP_SERVER3);

sntp_setservername(0, sysCfg.ntp_server[0]);
sntp_setservername(1, sysCfg.ntp_server[1]);
sntp_setservername(2, sysCfg.ntp_server[2]);

sntp_stop();
sntp_set_timezone(0); // UTC time
sntp_init();
Expand Down
1 change: 1 addition & 0 deletions sonoff/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
#define USE_BH1750 // Add I2C code for BH1750 sensor
#define USE_BMP // Add I2C code for BMP/BME280 sensor
#define USE_HTU // Add I2C code for HTU21/SI7013/SI7020/SI7021 sensor
#define USE_SHT // Add I2C emulating code for SHT1X sensor

#define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+4k code, 0.3k mem)

Expand Down
9 changes: 9 additions & 0 deletions sonoff/webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,18 @@ void handleAjax2()
#endif // USE_DHT
#ifdef USE_I2C
if (i2c_flg) {
#ifdef USE_SHT
tpage += sht_webPresent();
#endif
#ifdef USE_HTU
tpage += htu_webPresent();
#endif
#ifdef USE_BMP
tpage += bmp_webPresent();
#endif
#ifdef USE_BH1750
tpage += bh1750_webPresent();
#endif
}
#endif // USE_I2C
String page = "";
Expand Down
Loading

0 comments on commit c4cdd44

Please sign in to comment.