-
Notifications
You must be signed in to change notification settings - Fork 2
/
lock.ino
64 lines (46 loc) · 1007 Bytes
/
lock.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
/*
* LOCK
* Maxime MOREILLON
*
* Board type: Wemos D1 Mini
*
*/
// Libraries
#include "IotKernel.h"
#include <Servo.h>
// IoT Kernel params
#define DEVICE_TYPE "lock"
#define DEVICE_FIRMWARE_VERSION "0.2.7"
// Pin mapping
#define SERVO_PIN D2
#define UNLOCK_LED_PIN D7
#define LOCK_LED_PIN D8
#define BUTTON_PIN D6 // D6
// Servo
#define SERVO_UNLOCK_ANGLE 140
#define SERVO_NEUTRAL_ANGLE 90
#define SERVO_LOCK_ANGLE 20
//#define SERVO_DELAY 1
#define SERVO_INCREMENT 2
// MQTT
#define MQTT_COMMAND_TOPIC "lock/command"
#define MQTT_STATUS_TOPIC "lock/status"
IotKernel iot_kernel(DEVICE_TYPE,DEVICE_FIRMWARE_VERSION);
Servo servo;
boolean servo_unlock_request, servo_lock_request;
char* lock_status = "UNKNOWN";
void setup() {
// IO init
pinMode(UNLOCK_LED_PIN,OUTPUT);
pinMode(LOCK_LED_PIN,OUTPUT);
button_init();
servo_setup();
iot_kernel.init();
MQTT_config();
web_server_config();
}
void loop() {
iot_kernel.loop();
button_read();
handle_servo();
}