-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.ino
96 lines (80 loc) · 2.28 KB
/
remote.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <arduino_homekit_server.h>
#include "homekit-operation.h"
// Connections with NodeMCU board
// Label Pin Description
// D0 GPIO-16 Built-in led
// D1 GPIO-5 Remote control line
// D3 GPIO-0 Flash button
constexpr int BuiltInLedPin = 16; // D0
const char *ssid = "YourWiFiSsid";
const char *password = "WiFiPassword";
void setup()
{
Serial.begin(115200);
Serial.setRxBufferSize(32);
Serial.setDebugOutput(false);
pinMode(BuiltInLedPin, OUTPUT);
WiFi.mode(WIFI_STA);
WiFi.persistent(false);
WiFi.disconnect(false);
WiFi.setAutoReconnect(true);
WiFi.begin(ssid, password);
printf("\n");
printf("SketchSize: %d B\n", ESP.getSketchSize());
printf("FreeSketchSpace: %d B\n", ESP.getFreeSketchSpace());
printf("FlashChipSize: %d B\n", ESP.getFlashChipSize());
printf("FlashChipRealSize: %d B\n", ESP.getFlashChipRealSize());
printf("FlashChipSpeed: %d\n", ESP.getFlashChipSpeed());
printf("SdkVersion: %s\n", ESP.getSdkVersion());
printf("FullVersion: %s\n", ESP.getFullVersion().c_str());
printf("CpuFreq: %dMHz\n", ESP.getCpuFreqMHz());
printf("FreeHeap: %d B\n", ESP.getFreeHeap());
printf("ResetInfo: %s\n", ESP.getResetInfo().c_str());
printf("ResetReason: %s\n", ESP.getResetReason().c_str());
DEBUG_HEAP();
homekit_setup();
DEBUG_HEAP();
blinkInternalLed(200, 3);
}
void loop()
{
homekit_loop();
delay(5);
}
void blinkInternalLed(int intervalMs, int count)
{
for (int i = 0; i < count; i++)
{
builtInLedSet(true);
delay(intervalMs);
builtInLedSet(false);
delay(intervalMs);
}
}
void builtInLedSet(bool on)
{
digitalWrite(BuiltInLedPin, on);
}
//==============================
// Homekit setup and loop
//==============================
uint32_t next_heap_millis = 0;
void homekit_setup()
{
accessory_init();
uint8_t mac[WL_MAC_ADDR_LENGTH];
WiFi.macAddress(mac);
arduino_homekit_setup(&config);
}
void homekit_loop()
{
arduino_homekit_loop();
uint32_t time = millis();
if (time > next_heap_millis)
{
INFO("heap: %d, sockets: %d", ESP.getFreeHeap(), arduino_homekit_connected_clients_count());
next_heap_millis = time + 5000;
}
}