+ // Originally posted on the Arduino forum at http://arduino.cc/forum/index.php/topic,70705.0.html
+ // Originally offered to the i2cdevlib project at http://arduino.cc/forum/index.php/topic,68210.30.html
+
+ #define NBWIRE_BUFFER_LENGTH 32
+
+ class TwoWire {
+ private:
+ static uint8_t rxBuffer[];
+ static uint8_t rxBufferIndex;
+ static uint8_t rxBufferLength;
+
+ static uint8_t txAddress;
+ static uint8_t txBuffer[];
+ static uint8_t txBufferIndex;
+ static uint8_t txBufferLength;
+
+ // static uint8_t transmitting;
+ static void (*user_onRequest)(void);
+ static void (*user_onReceive)(int);
+ static void onRequestService(void);
+ static void onReceiveService(uint8_t*, int);
+
+ public:
+ TwoWire();
+ void begin();
+ void begin(uint8_t);
+ void begin(int);
+ void beginTransmission(uint8_t);
+ //void beginTransmission(int);
+ uint8_t endTransmission(uint16_t timeout=0);
+ void nbendTransmission(void (*function)(int)) ;
+ uint8_t requestFrom(uint8_t, int, uint16_t timeout=0);
+ //uint8_t requestFrom(int, int);
+ void nbrequestFrom(uint8_t, int, void (*function)(int));
+ void send(uint8_t);
+ void send(uint8_t*, uint8_t);
+ //void send(int);
+ void send(char*);
+ uint8_t available(void);
+ uint8_t receive(void);
+ void onReceive(void (*)(int));
+ void onRequest(void (*)(void));
+ };
+
+ #define TWI_READY 0
+ #define TWI_MRX 1
+ #define TWI_MTX 2
+ #define TWI_SRX 3
+ #define TWI_STX 4
+
+ #define TW_WRITE 0
+ #define TW_READ 1
+
+ #define TW_MT_SLA_NACK 0x20
+ #define TW_MT_DATA_NACK 0x30
+
+ #define CPU_FREQ 16000000L
+ #define TWI_FREQ 100000L
+ #define TWI_BUFFER_LENGTH 32
+
+ /* TWI Status is in TWSR, in the top 5 bits: TWS7 - TWS3 */
+
+ #define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))
+ #define TW_STATUS (TWSR & TW_STATUS_MASK)
+ #define TW_START 0x08
+ #define TW_REP_START 0x10
+ #define TW_MT_SLA_ACK 0x18
+ #define TW_MT_SLA_NACK 0x20
+ #define TW_MT_DATA_ACK 0x28
+ #define TW_MT_DATA_NACK 0x30
+ #define TW_MT_ARB_LOST 0x38
+ #define TW_MR_ARB_LOST 0x38
+ #define TW_MR_SLA_ACK 0x40
+ #define TW_MR_SLA_NACK 0x48
+ #define TW_MR_DATA_ACK 0x50
+ #define TW_MR_DATA_NACK 0x58
+ #define TW_ST_SLA_ACK 0xA8
+ #define TW_ST_ARB_LOST_SLA_ACK 0xB0
+ #define TW_ST_DATA_ACK 0xB8
+ #define TW_ST_DATA_NACK 0xC0
+ #define TW_ST_LAST_DATA 0xC8
+ #define TW_SR_SLA_ACK 0x60
+ #define TW_SR_ARB_LOST_SLA_ACK 0x68
+ #define TW_SR_GCALL_ACK 0x70
+ #define TW_SR_ARB_LOST_GCALL_ACK 0x78
+ #define TW_SR_DATA_ACK 0x80
+ #define TW_SR_DATA_NACK 0x88
+ #define TW_SR_GCALL_DATA_ACK 0x90
+ #define TW_SR_GCALL_DATA_NACK 0x98
+ #define TW_SR_STOP 0xA0
+ #define TW_NO_INFO 0xF8
+ #define TW_BUS_ERROR 0x00
+
+ //#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
+ //#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))
+
+ #ifndef sbi // set bit
+ #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
+ #endif // sbi
+
+ #ifndef cbi // clear bit
+ #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
+ #endif // cbi
+
+ extern TwoWire Wire;
+
+#endif // I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_NBWIRE
+
+#endif /* _I2CDEV_H_ */
diff --git a/lib/I2Cdevlib-Core/keywords.txt b/lib/I2Cdevlib-Core/keywords.txt
new file mode 100644
index 000000000..4132a06c3
--- /dev/null
+++ b/lib/I2Cdevlib-Core/keywords.txt
@@ -0,0 +1,38 @@
+#######################################
+# Syntax Coloring Map For I2Cdev
+#######################################
+
+#######################################
+# Datatypes (KEYWORD1)
+#######################################
+I2Cdev KEYWORD1
+
+#######################################
+# Methods and Functions (KEYWORD2)
+#######################################
+
+readBit KEYWORD2
+readBitW KEYWORD2
+readBits KEYWORD2
+readBitsW KEYWORD2
+readByte KEYWORD2
+readBytes KEYWORD2
+readWord KEYWORD2
+readWords KEYWORD2
+writeBit KEYWORD2
+writeBitW KEYWORD2
+writeBits KEYWORD2
+writeBitsW KEYWORD2
+writeByte KEYWORD2
+writeBytes KEYWORD2
+writeWord KEYWORD2
+writeWords KEYWORD2
+
+#######################################
+# Instances (KEYWORD2)
+#######################################
+
+#######################################
+# Constants (LITERAL1)
+#######################################
+
diff --git a/lib/I2Cdevlib-Core/library.json b/lib/I2Cdevlib-Core/library.json
new file mode 100644
index 000000000..d45609604
--- /dev/null
+++ b/lib/I2Cdevlib-Core/library.json
@@ -0,0 +1,13 @@
+{
+ "name": "I2Cdevlib-Core",
+ "keywords": "i2cdevlib, i2c",
+ "description": "The I2C Device Library (I2Cdevlib) is a collection of uniform and well-documented classes to provide simple and intuitive interfaces to I2C devices.",
+ "include": "Arduino/I2Cdev",
+ "repository":
+ {
+ "type": "git",
+ "url": "https://github.com/jrowberg/i2cdevlib.git"
+ },
+ "frameworks": "arduino",
+ "platforms": "atmelavr"
+}
diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino
index 9056069c4..64bd4da27 100644
--- a/sonoff/_releasenotes.ino
+++ b/sonoff/_releasenotes.ino
@@ -1,4 +1,11 @@
-/* 5.9.0 20171030
+/* 5.9.1 20171107
+ * Add external sensor function pointer interface to enable easy sensor addition
+ * Add support for ADS1115 to be enabled in user_config.h and needs libraries i2cdevlib-Core and i2cdevlib-ADS1115 (#338, #660)
+ * Fix Backup Configuration file download failure by defining proper file size (#1115)
+ * Fix Exception 26 and empty console screen after usage of command WakeupDuration (#1133)
+ * Fix some changed iTead web links in README.md (#1137)
+ *
+ * 5.9.0 20171030
* Rewrite code (partly) using Google C++ Style Guide (https://google.github.io/styleguide/cppguide.html)
* Rewrite code by using command lookup tables and javascript (client side) web page expansions
* Change HTML/CSS to enable nicer form field entry
diff --git a/sonoff/i18n.h b/sonoff/i18n.h
index 3269b3b40..ff4cdc0e1 100644
--- a/sonoff/i18n.h
+++ b/sonoff/i18n.h
@@ -77,8 +77,9 @@ const char S_JSON_COMMAND_INDEX_NVALUE[] PROGMEM = "{\"%s%d\":%d}";
const char S_JSON_COMMAND_INDEX_SVALUE[] PROGMEM = "{\"%s%d\":\"%s\"}";
const char S_JSON_COMMAND_INDEX_SVALUE_SVALUE[] PROGMEM = "{\"%s%d\":\"%s%s\"}";
-const char JSON_SNS_TEMPHUM[] PROGMEM =
- "%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s}";
+const char JSON_SNS_TEMPHUM[] PROGMEM = "%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s}";
+
+const char S_LOG_I2C_FOUND_AT[] PROGMEM = D_LOG_I2C "%s " D_FOUND_AT " 0x%x";
const char S_LOG_HTTP[] PROGMEM = D_LOG_HTTP;
const char S_LOG_WIFI[] PROGMEM = D_LOG_WIFI;
@@ -113,6 +114,13 @@ const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = {
static const char kMonthNames[] = D_MONTH3LIST;
// webserver.ino
+#ifdef USE_WEBSERVER
+const char HTTP_SNS_TEMP[] PROGMEM = "%s{s}%s " D_TEMPERATURE "{m}%s°%c{e}"; // {s} = , {m} = | , {e} = |
+const char HTTP_SNS_HUM[] PROGMEM = "%s{s}%s " D_HUMIDITY "{m}%s%{e}"; // {s} = , {m} = | , {e} = |
+const char HTTP_SNS_PRESSURE[] PROGMEM = "%s{s}%s " D_PRESSURE "{m}%s " D_UNIT_PRESSURE "{e}"; // {s} = , {m} = | , {e} = |
+const char HTTP_SNS_SEAPRESSURE[] PROGMEM = "%s{s}%s " D_PRESSUREATSEALEVEL "{m}%s " D_UNIT_PRESSURE "{e}"; // {s} = , {m} = | , {e} = |
+const char HTTP_SNS_ANALOG[] PROGMEM = "%s{s}%s " D_ANALOG_INPUT "%d{m}%d{e}"; // {s} = , {m} = | , {e} = |
+
const char S_MAIN_MENU[] PROGMEM = D_MAIN_MENU;
const char S_CONFIGURATION[] PROGMEM = D_CONFIGURATION;
const char S_CONFIGURE_MODULE[] PROGMEM = D_CONFIGURE_MODULE;
@@ -128,5 +136,6 @@ const char S_FIRMWARE_UPGRADE[] PROGMEM = D_FIRMWARE_UPGRADE;
const char S_CONSOLE[] PROGMEM = D_CONSOLE;
const char S_INFORMATION[] PROGMEM = D_INFORMATION;
const char S_RESTART[] PROGMEM = D_RESTART;
+#endif // USE_WEBSERVER
#endif // _I18N_H_
\ No newline at end of file
diff --git a/sonoff/language/de-DE.h b/sonoff/language/de-DE.h
index 0574ab2e5..2dffab394 100644
--- a/sonoff/language/de-DE.h
+++ b/sonoff/language/de-DE.h
@@ -216,7 +216,7 @@
#define D_SET_BAUDRATE_TO "Baudrate eingestell auf"
#define D_RECEIVED_TOPIC "erhaltenes topic"
#define D_DATA_SIZE "Datengröße"
-#define D_ANALOG_INPUT0 "Analog0"
+#define D_ANALOG_INPUT "Analog"
#define D_FINGERPRINT "TLS-Fingerabdruck wird verifiziert..."
#define D_TLS_CONNECT_FAILED_TO "TLS-Verbindung fehlgeschlagen an"
diff --git a/sonoff/language/en-GB.h b/sonoff/language/en-GB.h
index a621ae753..695ac4301 100644
--- a/sonoff/language/en-GB.h
+++ b/sonoff/language/en-GB.h
@@ -216,7 +216,7 @@
#define D_SET_BAUDRATE_TO "Set Baudrate to"
#define D_RECEIVED_TOPIC "Received Topic"
#define D_DATA_SIZE "Data Size"
-#define D_ANALOG_INPUT0 "Analog0"
+#define D_ANALOG_INPUT "Analog"
#define D_FINGERPRINT "Verify TLS fingerprint..."
#define D_TLS_CONNECT_FAILED_TO "TLS Connect failed to"
diff --git a/sonoff/language/nl-NL.h b/sonoff/language/nl-NL.h
index 38a28f543..03e925839 100644
--- a/sonoff/language/nl-NL.h
+++ b/sonoff/language/nl-NL.h
@@ -216,7 +216,7 @@
#define D_SET_BAUDRATE_TO "Zet baudrate op"
#define D_RECEIVED_TOPIC "Ontvangen topic"
#define D_DATA_SIZE "Data lengte"
-#define D_ANALOG_INPUT0 "Analoog0"
+#define D_ANALOG_INPUT "Analoog"
#define D_FINGERPRINT "Controleer TLS vingerafdruk..."
#define D_TLS_CONNECT_FAILED_TO "TLS Verbinding mislukt naar"
diff --git a/sonoff/language/pl-PL.h b/sonoff/language/pl-PL.h
index 46f0d08f8..f37ccfaa7 100644
--- a/sonoff/language/pl-PL.h
+++ b/sonoff/language/pl-PL.h
@@ -216,7 +216,7 @@
#define D_SET_BAUDRATE_TO "Ustaw szybkosc transmisji na"
#define D_RECEIVED_TOPIC "Otrzymany temat"
#define D_DATA_SIZE "Wielkosc danych"
-#define D_ANALOG_INPUT0 "Wej_analogowe"
+#define D_ANALOG_INPUT "Wej_analogowe"
#define D_FINGERPRINT "Weryfikuj odcisk TLS..."
#define D_TLS_CONNECT_FAILED_TO "Nieudane polaczenie TLS do"
diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h
index 603ba86f4..dc3882854 100644
--- a/sonoff/sonoff.h
+++ b/sonoff/sonoff.h
@@ -90,6 +90,8 @@ typedef unsigned long power_t; // Power (Relay) type
#define APP_BAUDRATE 115200 // Default serial baudrate
#define MAX_STATUS 11 // Max number of status lines
+#define XSNS_MAX 20 // Max number of allowed Xsns External Sensors (Update xsns_interface.ino if changed)
+
/*********************************************************************************************\
* Enumeration
\*********************************************************************************************/
@@ -110,6 +112,7 @@ enum Ws2812Color {WS_RED, WS_GREEN, WS_BLUE};
enum LightTypes {LT_BASIC, LT_PWM1, LT_PWM2, LT_PWM3, LT_PWM4, LT_PWM5, LT_PWM6, LT_PWM7, LT_NU8, LT_NU9, LT_NU10, LT_WS2812, LT_RGBW, LT_RGBWC};
enum LichtSubtypes {LST_NONE, LST_SINGLE, LST_COLDWARM, LST_RGB, LST_RGBW, LST_RGBWC};
enum LichtSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MAX};
+enum XsnsFunctions {FUNC_XSNS_INIT, FUNC_XSNS_PREP, FUNC_XSNS_JSON_APPEND, FUNC_XSNS_MQTT_SHOW, FUNC_XSNS_WEB};
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino
index cc20d5af0..dd2dbf375 100644
--- a/sonoff/sonoff.ino
+++ b/sonoff/sonoff.ino
@@ -25,7 +25,7 @@
- Select IDE Tools - Flash Size: "1M (no SPIFFS)"
====================================================*/
-#define VERSION 0x05090000 // 5.9.0
+#define VERSION 0x05090100 // 5.9.1
// Location specific includes
#include "sonoff.h" // Enumaration used in user_config.h
@@ -183,6 +183,8 @@ uint8_t light_type = 0; // Light types
boolean mdns_begun = false;
+uint8_t xsns_present = 0; // Number of External Sensors found
+boolean (*xsns_func_ptr[XSNS_MAX])(byte); // External Sensor Function Pointers for simple implementation of sensors
char version[16]; // Version string from VERSION define
char my_hostname[33]; // Composed Wifi hostname
char mqtt_client[33]; // Composed MQTT Clientname
@@ -1757,9 +1759,8 @@ void PublishStatus(uint8_t payload)
}
if ((0 == payload) || (10 == payload)) {
- uint8_t djson = 0;
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS10_SENSOR "\":"));
- MqttShowSensor(&djson);
+ MqttShowSensor();
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "10"));
}
@@ -1789,62 +1790,23 @@ void MqttShowState()
mqtt_data, Settings.sta_active +1, Settings.sta_ssid[Settings.sta_active], WifiGetRssiAsQuality(WiFi.RSSI()), WiFi.BSSIDstr().c_str());
}
-void MqttShowSensor(uint8_t* djson)
+boolean MqttShowSensor()
{
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s{\"" D_TIME "\":\"%s\""), mqtt_data, GetDateAndTime().c_str());
+ int json_data_start = strlen(mqtt_data);
for (byte i = 0; i < MAX_SWITCHES; i++) {
if (pin[GPIO_SWT1 +i] < 99) {
boolean swm = ((FOLLOW_INV == Settings.switchmode[i]) || (PUSHBUTTON_INV == Settings.switchmode[i]) || (PUSHBUTTONHOLD_INV == Settings.switchmode[i]));
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_SWITCH "%d\":\"%s\""), mqtt_data, i +1, GetStateText(swm ^ lastwallswitch[i]));
- *djson = 1;
}
}
- MqttShowCounter(djson);
-#ifndef USE_ADC_VCC
- if (pin[GPIO_ADC0] < 99) {
- snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_ANALOG_INPUT0 "\":%d"), mqtt_data, GetAdc0());
- *djson = 1;
- }
-#endif
- if (SONOFF_SC == Settings.module) {
- MqttShowSonoffSC(djson);
- }
- if (pin[GPIO_DSB] < 99) {
-#ifdef USE_DS18B20
- MqttShowDs18b20(djson);
-#endif // USE_DS18B20
-#ifdef USE_DS18x20
- MqttShowDs18x20(djson);
-#endif // USE_DS18x20
- }
-#ifdef USE_DHT
- if (dht_flg) {
- MqttShowDht(djson);
- }
-#endif // USE_DHT
-#ifdef USE_I2C
- if (i2c_flg) {
-#ifdef USE_SHT
- MqttShowSht(djson);
-#endif // USE_SHT
-#ifdef USE_HTU
- MqttShowHtu(djson);
-#endif // USE_HTU
-#ifdef USE_BMP
- MqttShowBmp(djson);
-#endif // USE_BMP
-#ifdef USE_BH1750
- MqttShowBh1750(djson);
-#endif // USE_BH1750
-#ifdef USE_VEML6070
- MqttShowVeml6070(djson);
-#endif // USE_VEML6070
-}
-#endif // USE_I2C
+ XsnsCall(FUNC_XSNS_JSON_APPEND);
+ boolean json_data_available = (strlen(mqtt_data) - json_data_start);
if (strstr_P(mqtt_data, PSTR(D_TEMPERATURE))) {
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_TEMPERATURE_UNIT "\":\"%c\""), mqtt_data, TempUnit());
}
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
+ return json_data_available;
}
/********************************************************************************************/
@@ -1897,39 +1859,7 @@ void PerformEverySecond()
if (Settings.tele_period) {
tele_period++;
if (tele_period == Settings.tele_period -1) {
- if (pin[GPIO_DSB] < 99) {
-#ifdef USE_DS18B20
- Ds18b20ReadTempPrep();
-#endif // USE_DS18B20
-#ifdef USE_DS18x20
- Ds18x20Search(); // Check for changes in sensors number
- Ds18x20Convert(); // Start Conversion, takes up to one second
-#endif // USE_DS18x20
- }
-#ifdef USE_DHT
- if (dht_flg) {
- DhtReadPrep();
- }
-#endif // USE_DHT
-#ifdef USE_I2C
- if (i2c_flg) {
-#ifdef USE_SHT
- ShtDetect();
-#endif // USE_SHT
-#ifdef USE_HTU
- HtuDetect();
-#endif // USE_HTU
-#ifdef USE_BMP
- BmpDetect();
-#endif // USE_BMP
-#ifdef USE_BH1750
- Bh1750Detect();
-#endif // USE_BH1750
-#ifdef USE_VEML6070
- Veml6070Detect();
-#endif // USE_VEML6070
-}
-#endif // USE_I2C
+ XsnsCall(FUNC_XSNS_PREP);
}
if (tele_period >= Settings.tele_period) {
tele_period = 0;
@@ -1938,16 +1868,12 @@ void PerformEverySecond()
MqttShowState();
MqttPublishPrefixTopic_P(2, PSTR(D_RSLT_STATE));
- uint8_t djson = 0;
mqtt_data[0] = '\0';
- MqttShowSensor(&djson);
- if (djson) {
+ if (MqttShowSensor()) {
MqttPublishPrefixTopic_P(2, PSTR(D_RSLT_SENSOR), Settings.flag.mqtt_sensor_retain);
}
- if (hlw_flg) {
- MqttShowHlw8012(1);
- }
+ XsnsCall(FUNC_XSNS_MQTT_SHOW);
}
}
@@ -2684,24 +2610,9 @@ void GpioInit()
#endif // USE_IR_RECEIVE
#endif // USE_IR_REMOTE
- CounterInit();
-
hlw_flg = ((pin[GPIO_HLW_SEL] < 99) && (pin[GPIO_HLW_CF1] < 99) && (pin[GPIO_HLW_CF] < 99));
- if (hlw_flg) {
- HlwInit();
- }
-#ifdef USE_DHT
- if (dht_flg) {
- DhtInit();
- }
-#endif // USE_DHT
-
-#ifdef USE_DS18x20
- if (pin[GPIO_DSB] < 99) {
- Ds18x20Init();
- }
-#endif // USE_DS18x20
+ XSnsInit();
}
extern "C" {
diff --git a/sonoff/support.ino b/sonoff/support.ino
index f48e2d1de..aab885334 100644
--- a/sonoff/support.ino
+++ b/sonoff/support.ino
@@ -757,6 +757,17 @@ int32_t I2cRead24(uint8_t addr, uint8_t reg)
return I2cRead(addr, reg, 3);
}
+void I2cWrite8v(uint8_t addr, uint8_t val)
+{
+ byte x = I2C_RETRY_COUNTER;
+
+ do {
+ Wire.beginTransmission((uint8_t)addr); // start transmission to device
+ Wire.write(val); // write data
+ x--;
+ } while (Wire.endTransmission(true) != 0 && x != 0); // end transmission
+}
+
void I2cWrite8(uint8_t addr, uint8_t reg, uint8_t val)
{
byte x = I2C_RETRY_COUNTER;
@@ -1136,16 +1147,6 @@ char TempUnit()
return (Settings.flag.temperature_conversion) ? 'F' : 'C';
}
-uint16_t GetAdc0()
-{
- uint16_t alr = 0;
- for (byte i = 0; i < 32; i++) {
- alr += analogRead(A0);
- delay(1);
- }
- return alr >> 5;
-}
-
double FastPrecisePow(double a, double b)
{
// https://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/
@@ -1233,8 +1234,66 @@ int GetCommandCode(char* destination, size_t destination_size, const char* needl
return result;
}
+#ifndef USE_ADC_VCC
+/*********************************************************************************************\
+ * ADC support
+\*********************************************************************************************/
+
+void AdcShow(boolean json)
+{
+ uint16_t analog = 0;
+ for (byte i = 0; i < 32; i++) {
+ analog += analogRead(A0);
+ delay(1);
+ }
+ analog >>= 5;
+
+ if (json) {
+ snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_ANALOG_INPUT "0\":%d"), mqtt_data, analog);
+#ifdef USE_WEBSERVER
+ } else {
+ snprintf_P(mqtt_data, sizeof(mqtt_data), HTTP_SNS_ANALOG, mqtt_data, "", 0, analog);
+#endif // USE_WEBSERVER
+ }
+}
+
+/*********************************************************************************************\
+ * Interface
+\*********************************************************************************************/
+
+#define XSNS_02
+
+boolean Xsns02(byte function)
+{
+ boolean result = false;
+
+ if (pin[GPIO_ADC0] < 99) {
+ switch (function) {
+// case FUNC_XSNS_INIT:
+// break;
+// case FUNC_XSNS_PREP:
+// break;
+ case FUNC_XSNS_JSON_APPEND:
+ AdcShow(1);
+ break;
+#ifdef USE_WEBSERVER
+ case FUNC_XSNS_WEB:
+ AdcShow(0);
+ break;
+#endif // USE_WEBSERVER
+ }
+ }
+ return result;
+}
+#endif // USE_ADC_VCC
+
/*********************************************************************************************\
* Syslog
+ *
+ * Example:
+ * snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_LOG "Any value %d"), value);
+ * AddLog(LOG_LEVEL_DEBUG);
+ *
\*********************************************************************************************/
void Syslog()
diff --git a/sonoff/user_config.h b/sonoff/user_config.h
index 671b07cea..ad8faf8f0 100644
--- a/sonoff/user_config.h
+++ b/sonoff/user_config.h
@@ -163,14 +163,15 @@
// -- Sensor code selection -----------------------
#define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices
-//#define USE_DS18x20 // Optional using OneWire library for multiple DS18B20 and/or DS18S20 (+2k code)
+//#define USE_DS18x20 // Optional for multiple DS18B20 and/or DS18S20 sensors using library OneWire (+2k code)
#define USE_I2C // I2C using library wire (+10k code, 0.2k mem) - Disable by //
+ #define USE_SHT // Add I2C emulating code for SHT1X sensor
+ #define USE_HTU // Add I2C code for HTU21/SI7013/SI7020/SI7021 sensor
+ #define USE_BMP // Add I2C code for BMP/BME280 sensor
#define USE_BH1750 // Add I2C code for BH1750 sensor
// #define USE_VEML6070 // Add I2C code for VEML6070 sensor (+0.5k code)
- #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_ADS1115 // Add I2C code for ADS1x15 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
#define USE_IR_REMOTE // Send IR remote commands using library IRremoteESP8266 and ArduinoJson (+3k code, 0.3k mem)
// #define USE_IR_HVAC // Support for HVAC system using IR (+2k code)
diff --git a/sonoff/webserver.ino b/sonoff/webserver.ino
index d8f6dbfb9..6764a9cde 100644
--- a/sonoff/webserver.ino
+++ b/sonoff/webserver.ino
@@ -60,7 +60,8 @@ const char HTTP_HEAD[] PROGMEM =
"x=new XMLHttpRequest();"
"x.onreadystatechange=function(){"
"if(x.readyState==4&&x.status==200){"
- "document.getElementById('l1').innerHTML=x.responseText;"
+ "var s=x.responseText.replace(/{s}/g,\"\").replace(/{m}/g,\" | \").replace(/{e}/g,\" |
\").replace(/{t}/g,\"%'>%s " D_TEMPERATURE " | %s°%c | ";
-const char HTTP_SNS_HUM[] PROGMEM =
- "%s " D_HUMIDITY " | %s% |
";
-const char HTTP_SNS_PRESSURE[] PROGMEM =
- "%s " D_PRESSURE " | %s " D_UNIT_PRESSURE " |
";
-const char HTTP_SNS_PRESSUREATSEALEVEL[] PROGMEM =
- "%s " D_PRESSUREATSEALEVEL " | %s " D_UNIT_PRESSURE " |
";
-const char HTTP_SNS_LIGHT[] PROGMEM =
- "%s " D_LIGHT " | %d% |
";
-const char HTTP_SNS_NOISE[] PROGMEM =
- "%s " D_NOISE " | %d% |
";
-const char HTTP_SNS_DUST[] PROGMEM =
- "%s " D_AIR_QUALITY " | %d% |
";
const char HTTP_END[] PROGMEM =
""
"