Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

  1. /*
  2. ANALOG MODULE
  3. Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
  4. */
  5. #if ENABLE_ANALOG
  6. int _analog = 0;
  7. // -----------------------------------------------------------------------------
  8. // ANALOG
  9. // -----------------------------------------------------------------------------
  10. double getAnalog() {
  11. return _analog;
  12. }
  13. void analogSetup() {
  14. //pinMode(0, INPUT);
  15. }
  16. void analogLoop() {
  17. // Check if we should read new data
  18. static unsigned long last_update = 0;
  19. if ((millis() - last_update > ANALOG_UPDATE_INTERVAL) || (last_update == 0)) {
  20. _analog = analogRead(0);
  21. DEBUG_MSG_P(PSTR("[ANALOG] Value: %d\n"), _analog);
  22. last_update = millis();
  23. // Send MQTT messages
  24. mqttSend(getSetting("analogTmpTopic", ANALOG_TOPIC).c_str(), String(_analog).c_str());
  25. // Send to Domoticz
  26. #if ENABLE_DOMOTICZ
  27. // domoticzSend("dczTmpIdx", 0, _analog);
  28. #endif
  29. // Update websocket clients
  30. char buffer[100];
  31. sprintf_P(buffer, PSTR("{\"analogVisible\": 1, \"analogValue\": %d}"), _analog);
  32. wsSend(buffer);
  33. }
  34. }
  35. #endif