Browse Source

Merged in webfrank2/espurna/master (pull request #15)

New analog module to read raw value from A0 pin

Approved-by: Xose Pérez
fastled
Francesco Boscarino 7 years ago
committed by Xose Pérez
parent
commit
7e066239b5
6 changed files with 88 additions and 0 deletions
  1. +54
    -0
      code/espurna/analog.ino
  2. +7
    -0
      code/espurna/config/hardware.h
  3. +8
    -0
      code/espurna/config/sensors.h
  4. +6
    -0
      code/espurna/espurna.ino
  5. +5
    -0
      code/html/index.html
  6. +8
    -0
      code/platformio.ini

+ 54
- 0
code/espurna/analog.ino View File

@ -0,0 +1,54 @@
/*
ANALOG MODULE
Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#if ENABLE_ANALOG
int _analog = 0;
// -----------------------------------------------------------------------------
// ANALOG
// -----------------------------------------------------------------------------
double getAnalog() {
return _analog;
}
void analogSetup() {
//pinMode(0, INPUT);
}
void analogLoop() {
// Check if we should read new data
static unsigned long 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();
// Send MQTT messages
mqttSend(getSetting("analogTmpTopic", ANALOG_TOPIC).c_str(), String(_analog).c_str());
// Send to Domoticz
#if ENABLE_DOMOTICZ
// domoticzSend("dczTmpIdx", 0, _analog);
#endif
// Update websocket clients
char buffer[100];
sprintf_P(buffer, PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), _analog);
wsSend(buffer);
}
}
#endif

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

@ -35,6 +35,13 @@
#define LED1_PIN 2
#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)
#define MANUFACTURER "WEMOS"


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

@ -25,6 +25,14 @@
#define HUMIDITY_DRY 2
#define HUMIDITY_WET 3
//--------------------------------------------------------------------------------
// Analog sensor
// Enable support by passing ENABLE_ANALOG=1 build flag
//--------------------------------------------------------------------------------
#define ANALOG_UPDATE_INTERVAL 60000
#define ANALOG_TOPIC "/analog"
//--------------------------------------------------------------------------------
// DS18B20 temperature sensor
// Enable support by passing ENABLE_DS18B20=1 build flag


+ 6
- 0
code/espurna/espurna.ino View File

@ -184,6 +184,9 @@ void setup() {
#if ENABLE_DS18B20
dsSetup();
#endif
#if ENABLE_ANALOG
analogSetup();
#endif
#if ENABLE_DHT
dhtSetup();
#endif
@ -221,6 +224,9 @@ void loop() {
#if ENABLE_DS18B20
dsLoop();
#endif
#if ENABLE_ANALOG
analogLoop();
#endif
#if ENABLE_DHT
dhtLoop();
#endif


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

@ -178,6 +178,11 @@
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="mqttStatus" readonly />
</div>
<div class="pure-g module module-analog">
<label class="pure-u-1 pure-u-sm-1-4" for="analogValue">Analog</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="analogValue" readonly />
</div>
<div class="pure-g module module-ds">
<label class="pure-u-1 pure-u-sm-1-4" for="dsTmp">Temperature (<span id="tmpUnit"></span>)</label>
<input class="pure-u-1 pure-u-sm-3-4" type="text" name="dsTmp" readonly />


+ 8
- 0
code/platformio.ini View File

@ -31,6 +31,14 @@ lib_deps =
lib_ignore =
# ------------------------------------------------------------------------------
[env:d1-analog]
platform = espressif8266
framework = arduino
board = d1_mini
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
extra_script = pio_hooks.py
build_flags = ${common.build_flags} -DD1_MINI -DENABLE_DS18B20=1 -DDS_PIN=14 -DENABLE_ADC_VCC=0 -DMQTT_USE_ASYNC=0 -DENABLE_ANALOG=1 -DNOWSAUTH
[env:d1-debug]
platform = espressif8266


Loading…
Cancel
Save