Browse Source

Send analog value to domoticz

fastled
Xose Pérez 7 years ago
parent
commit
18ec85da55
9 changed files with 90 additions and 70 deletions
  1. +15
    -10
      code/espurna/analog.ino
  2. +1
    -0
      code/espurna/config/arduino.h
  3. +0
    -7
      code/espurna/config/hardware.h
  4. +8
    -2
      code/espurna/config/sensors.h
  5. +1
    -1
      code/espurna/config/version.h
  6. BIN
      code/espurna/data/index.html.gz
  7. +50
    -50
      code/espurna/static/index.html.gz.h
  8. +9
    -0
      code/espurna/web.ino
  9. +6
    -0
      code/html/index.html

+ 15
- 10
code/espurna/analog.ino View File

@ -14,12 +14,18 @@ int _analog = 0;
// ANALOG // ANALOG
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
double getAnalog() {
return _analog;
unsigned int getAnalog() {
return analogRead(ANALOG_PIN);
} }
void analogSetup() { void analogSetup() {
//pinMode(0, INPUT);
pinMode(ANALOG_PIN, INPUT);
apiRegister("/api/analog", "analog", [](char * buffer, size_t len) {
snprintf(buffer, len, "%d", getAnalog());
});
} }
void analogLoop() { void analogLoop() {
@ -28,23 +34,22 @@ void analogLoop() {
static unsigned long last_update = 0; static unsigned long last_update = 0;
if ((millis() - last_update > ANALOG_UPDATE_INTERVAL) || (last_update == 0)) { if ((millis() - last_update > ANALOG_UPDATE_INTERVAL) || (last_update == 0)) {
_analog = analogRead(0);
DEBUG_MSG_P(PSTR("[ANALOG] Value: %d\n"), _analog);
last_update = millis(); last_update = millis();
unsigned int analog = getAnalog();
DEBUG_MSG_P(PSTR("[ANALOG] Value: %d\n"), analog);
// Send MQTT messages // Send MQTT messages
mqttSend(getSetting("analogTmpTopic", ANALOG_TOPIC).c_str(), String(_analog).c_str());
mqttSend(getSetting("analogTopic", ANALOG_TOPIC).c_str(), String(analog).c_str());
// Send to Domoticz // Send to Domoticz
#if ENABLE_DOMOTICZ #if ENABLE_DOMOTICZ
// domoticzSend("dczTmpIdx", 0, _analog);
domoticzSend("dczAnaIdx", 0, String(analog).c_str());
#endif #endif
// Update websocket clients // Update websocket clients
char buffer[100]; char buffer[100];
sprintf_P(buffer, PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), _analog);
sprintf_P(buffer, PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), analog);
wsSend(buffer); wsSend(buffer);
} }


+ 1
- 0
code/espurna/config/arduino.h View File

@ -54,3 +54,4 @@
//#define ENABLE_FAUXMO 0 //#define ENABLE_FAUXMO 0
//#define ENABLE_NOFUSS 1 //#define ENABLE_NOFUSS 1
//#define ENABLE_DOMOTICZ 0 //#define ENABLE_DOMOTICZ 0
//#define ENABLE_ANALOG 1

+ 0
- 7
code/espurna/config/hardware.h View File

@ -35,13 +35,6 @@
#define LED1_PIN 2 #define LED1_PIN 2
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
#elif defined(D1_MINI)
#define MANUFACTURER "WEMOS"
#define DEVICE "D1_MINI"
#define LED1_PIN 2
#define LED1_PIN_INVERSE 1
#elif defined(D1_RELAYSHIELD) #elif defined(D1_RELAYSHIELD)
#define MANUFACTURER "WEMOS" #define MANUFACTURER "WEMOS"


+ 8
- 2
code/espurna/config/sensors.h View File

@ -30,8 +30,14 @@
// Enable support by passing ENABLE_ANALOG=1 build flag // Enable support by passing ENABLE_ANALOG=1 build flag
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "/analog"
#define ANALOG_PIN 0
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "/analog"
#if ENABLE_ANALOG
#undef ENABLE_ADC_VCC
#define ENABLE_ADC_VCC 0
#endif
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// DS18B20 temperature sensor // DS18B20 temperature sensor


+ 1
- 1
code/espurna/config/version.h View File

@ -1,4 +1,4 @@
#define APP_NAME "ESPurna" #define APP_NAME "ESPurna"
#define APP_VERSION "1.6.9"
#define APP_VERSION "1.7.0b"
#define APP_AUTHOR "xose.perez@gmail.com" #define APP_AUTHOR "xose.perez@gmail.com"
#define APP_WEBSITE "http://tinkerman.cat" #define APP_WEBSITE "http://tinkerman.cat"

BIN
code/espurna/data/index.html.gz View File


+ 50
- 50
code/espurna/static/index.html.gz.h
File diff suppressed because it is too large
View File


+ 9
- 0
code/espurna/web.ino View File

@ -453,6 +453,10 @@ void _wsStart(uint32_t client_id) {
root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt(); root["dczCurrentIdx"] = getSetting("dczCurrentIdx").toInt();
#endif #endif
#if ENABLE_ANALOG
root["dczAnaIdx"] = getSetting("dczAnaIdx").toInt();
#endif
#if ENABLE_POW #if ENABLE_POW
root["dczPowIdx"] = getSetting("dczPowIdx").toInt(); root["dczPowIdx"] = getSetting("dczPowIdx").toInt();
root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt(); root["dczEnergyIdx"] = getSetting("dczEnergyIdx").toInt();
@ -491,6 +495,11 @@ void _wsStart(uint32_t client_id) {
root["emonRatio"] = getSetting("emonRatio", EMON_CURRENT_RATIO); root["emonRatio"] = getSetting("emonRatio", EMON_CURRENT_RATIO);
#endif #endif
#if ENABLE_ANALOG
root["analogVisible"] = 1;
root["analogValue"] = getAnalog();
#endif
#if ENABLE_POW #if ENABLE_POW
root["powVisible"] = 1; root["powVisible"] = 1;
root["powActivePower"] = getActivePower(); root["powActivePower"] = getActivePower();


+ 6
- 0
code/html/index.html View File

@ -519,6 +519,12 @@
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div> <div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div> </div>
<div class="pure-g module module-analog">
<label class="pure-u-1 pure-u-sm-1-4" for="dczAnaIdx">Analog IDX</label>
<div class="pure-u-1 pure-u-sm-1-8"><input class="pure-u-sm-23-24" name="dczAnaIdx" type="number" min="0" tabindex="39" data="0" /></div>
<div class="pure-u-1 pure-u-sm-5-8 hint center">Set to 0 to disable notifications.</div>
</div>
<div id="idxs"> <div id="idxs">
</div> </div>


Loading…
Cancel
Save