-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappSpecific.cpp
More file actions
159 lines (145 loc) · 5.81 KB
/
appSpecific.cpp
File metadata and controls
159 lines (145 loc) · 5.81 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Remote433 specific functions
//
// s60sc 2025
#include "appGlobals.h"
/************************ webServer callbacks *************************/
bool updateAppStatus(const char* variable, const char* value, bool fromUser) {
// update vars from configs and browser input
bool res = true;
int intVal = atoi(value);
if (fromUser && !strncmp(variable, "dooya", 5)) sendUserCmd(atoi(variable + 5));
else if (!strcmp(variable, "aopMode")) opMode = (opModes)(intVal + 1); // add one for correct index
else if (!strcmp(variable, "aRxPin")) rxPin = intVal;
else if (!strcmp(variable, "bTxPin")) txPin = intVal;
else if (!strcmp(variable, "cLedPin")) ledPin = intVal;
else if (!strcmp(variable, "extendPin")) extendPin = intVal;
else if (!strcmp(variable, "stopPin")) stopPin = intVal;
else if (!strcmp(variable, "retractPin")) retractPin = intVal;
else if (!strcmp(variable, "lightPin")) lightPin = intVal;
else if (!strcmp(variable, "p2Pin")) p2Pin = intVal;
else if (!strcmp(variable, "bpulseLen")) pulseLen = intVal;
else if (!strcmp(variable, "fsyncHighPulses")) syncHighPulses = intVal;
else if (!strcmp(variable, "esyncLowPulses")) syncLowPulses = intVal;
else if (!strcmp(variable, "dlongSignalPulse")) longSignalPulse = intVal;
else if (!strcmp(variable, "cshortSignalPulse")) shortSignalPulse = intVal;
else if (!strcmp(variable, "abitLen")) bitLen = intVal;
else if (!strcmp(variable, "gmsgGap")) msgGap = intVal;
else if (!strcmp(variable, "hminSignal")) minSignal = intVal;
else if (!strcmp(variable, "deviceId")) strncpy(deviceId, value, 24);
else if (!strcmp(variable, "channelData")) strncpy(channelData, value, 8);
else if (!strcmp(variable, "stopCmd")) strncpy(commandBits[STOP_ACTION], value, 8);
else if (!strcmp(variable, "retractCmd")) strncpy(commandBits[RETRACT1], value, 8);
else if (!strcmp(variable, "extendCmd")) strncpy(commandBits[EXTEND1], value, 8);
else if (!strcmp(variable, "ledCmd")) strncpy(commandBits[TOGGLE_LED1], value, 8);
else if (!strcmp(variable, "p2Cmd")) strncpy(commandBits[P2_COMMAND], value, 8);
return res;
}
void appSpecificWsBinHandler(uint8_t* wsMsg, size_t wsMsgLen) {
LOG_ERR("Unexpected websocket binary frame");
}
void appSpecificWsHandler(const char* wsMsg) {
// message from web socket
int wsLen = strlen(wsMsg) - 1;
switch ((char)wsMsg[0]) {
case 'X':
break;
case 'H':
// keepalive heartbeat, return status
break;
case 'S':
// status request
buildJsonString(wsLen); // required config number
logPrint("%s\n", jsonBuff);
break;
case 'U':
// update or control request
memcpy(jsonBuff, wsMsg + 1, wsLen); // remove 'U'
parseJson(wsLen);
break;
case 'K':
// kill websocket connection
killSocket();
break;
default:
LOG_WRN("unknown command %c", (char)wsMsg[0]);
break;
}
}
void buildAppJsonString(bool filter) {
// build app specific part of json string
char* p = jsonBuff + 1;
*p = 0;
}
esp_err_t appSpecificWebHandler(httpd_req_t *req, const char* variable, const char* value) {
return ESP_FAIL;
}
esp_err_t appSpecificSustainHandler(httpd_req_t* req) {
return ESP_OK;
}
void externalAlert(const char* subject, const char* message) {
// alert any configured external servers
}
bool appDataFiles() {
// callback from setupAssist.cpp, for any app specific files
return true;
}
void doAppPing() {
// if daily alarm occurs
if (checkAlarm()) {}
}
void OTAprereq() {
stopPing();
}
/************** default app configuration **************/
const char* appConfig = R"~(
restart~~99~T~na
ST_SSID~~0~T~Wifi SSID name
ST_Pass~~0~T~Wifi SSID password
ST_ip~~0~T~Static IP address
ST_gw~~0~T~Router IP address
ST_sn~255.255.255.0~0~T~Router subnet
ST_ns1~~0~T~DNS server
ST_ns2~~0~T~Alt DNS server
AP_Pass~~0~T~AP Password
AP_ip~~0~T~AP IP Address if not 192.168.4.1
AP_sn~~0~T~AP subnet
AP_gw~~0~T~AP gateway
allowAP~1~0~C~Allow simultaneous AP
timezone~GMT0~0~T~Timezone string: tinyurl.com/TZstring
logType~0~99~N~Output log selection
Auth_Name~~0~T~Optional user name for web page login
Auth_Pass~~0~T~Optional user name for web page password
formatIfMountFailed~0~0~C~Format file system on failure
wifiTimeoutSecs~30~0~N~WiFi connect timeout (secs)
alarmHour~4~99~N~Hour of day for daily actions
usePing~1~0~C~Use ping
aopMode~2~2~S:DOOYA_RX:UNKNOWN_RX:DOOYA_TX:CUSTOM_TX~Protocol mode
dooya1~Extend~2~A~Extend canopy
dooya3~Stop~2~A~Stop canopy
dooya4~Retract~2~A~Retract canopy
dooya6~LED~2~A~Toggle canopy LEDs on / off
dooya8~P2~2~A~Programming remote
aRxPin~1~3~N~Interrupt pin connected to receiver
bTxPin~1~3~N~Output pin connected to transmitter
cLedPin~8~3~N~Pin to display HIGH / LOW pulses
extendPin~3~3~N~Pin to issue Extend command
stopPin~9~3~N~Pin to issue Stop command
retractPin~4~3~N~Pin to issue Retract command
lightPin~10~3~N~Pin to issue Lights command
p2pin~7~3~N~Pin to issue P2 command
deviceId~001011000101011010100000~4~L~24 bit ID of device being controlled
channelData~01110001~4~L~8 bit Channel number
stopCmd~01010101~4~L~8 bit Stop command
retractCmd~00110011~4~L~8 bit Retract command
extendCmd~00010001~4~L~8 bit Extend command
ledCmd~00001111~4~L~8 bit Lights toggle command
p2Cmd~11001100~4~L~8 bit P2 command
bpulseLen~350~5~N~Pulse length in microseconds
fsyncHighPulses~13~5~N~Number of high pulse durations in sync message
esyncLowPulses~4~5~N~Number of low pulse durations in sync message
dlongSignalPulse~2~5~N~Number of pulse durations in long data bit
cshortSignalPulse~1~5~N~Number of pulse durations in short data bit
abitLen~48~5~N~Total data bits in message
gmsgGap~8~5~N~Separation in millis between each message
hminSignal~50~5~N~Signals in micros below this value are spurious
)~";