-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonoffator.ino
80 lines (62 loc) · 1.85 KB
/
sonoffator.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Sonoffator
// The Cave 2018, https://thecave.cz, https://github.com/thecavecz/
// Licensed under MIT License
//
//
// Dead simple firmware for Sonoff switches - just HTTP server, button handler and OTA. Suitable for HomeBridge integration
//
// Tested with ESP Arduino cores 2.3.0 and 2.4.2
//
// Using WiFiManager and OneButton libraries
//
//
// Flash with
// Generic ESP8266 module, Flash mode DIO, Flash size 1M (no or 64k SPIFFS), 80MHz CPU, 40MHz flash
//
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <ArduinoOTA.h>
#include <OneButton.h>
#include <Ticker.h>
#include <TaskScheduler.h>
#include <MQTT.h>
// MQTT credentials
#define MQTT_HOST "192.168.85.1"
#define MQTT_PORT 1883
#define MQTT_USER ""
#define MQTT_PASS ""
// uncomment this if you want to measure temperature with DS18B20
//#define TEMP_ENABLED 1
#define TEMP_INTERVAL 60000UL
#define TEMP_MAX_SENSORS 4
// uncomment this if you want to measure analog values
//#define ADC_ENABLED 1
#define ADC_INTERVAL 60000UL
// This pin assignment works for Sonoff Basic and Sonoff S20/S26
#define PIN_LED 13
#define PIN_BTN 0
#define PIN_OUTPUT 12
#define PIN_TEMP 14
#define PIN_ADC A0
// uncomment if LED is on when pin is HIGH
//#define LED_ACTIVE_HIGH 1
// uncomment if you want to use timed switchoff
//#define TIMER_ENABLED 1
// Logging over Serial
#define LOG_ENABLED 1
#define WIFI_AP_NAME "sonoffator-"
#define MQTT_CLIENT_ID "sonoffator-%s"
#define MQTT_RECONNECT_INTERVAL 10000UL
#define MQTT_PREFIX "hb/sonoffator-%s/"
#define MQTT_ONLINE_TOPIC "online"
#define MQTT_IP_TOPIC "ip"
#define MQTT_NAME_TOPIC "name"
#define MQTT_TOPIC_STATE "state"
#define MQTT_TOPIC_SET "set"
#define MQTT_TOPIC_TEMP "temp"
#define MQTT_TOPIC_ADC "adc/0"
#define MQTT_TOPIC_TIMER "timer"
#define MQTT_TOPIC_TIMER_REMAIN "timerRemaining"
Scheduler scheduler;
String chipId = String(ESP.getChipId(), HEX);