forked from patience4711/read-APSystems-YC600-QS1-DS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZIGBEE_POLLING.ino
57 lines (45 loc) · 1.82 KB
/
ZIGBEE_POLLING.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
void polling(int which) {
polled[which]=false; //nothing is displayed on webpage
if(zigbeeUp == 0)
{
if(diagNose) ws.textAll("skipping poll, coordinator down!"); //
return;
}
if(diagNose) ws.textAll("polling"); //
char pollCmd[67] = {0};
char ecu_id_reverse[13];
ECU_REVERSE().toCharArray(ecu_id_reverse, 13);
snprintf(pollCmd, sizeof(pollCmd), "2401%s1414060001000F13%sFBFB06BB000000000000C1FEFE", Inv_Prop[which].invID, ecu_id_reverse);
//add checksum done in sendZigbee
delayMicroseconds(250);
if(diagNose) ws.textAll("zb send poll cmd inverter " + String(which));
sendZB(pollCmd);
//we are going to analyze this
//if message is empty or not a correct answer, this is decided in decodePollAnswer
errorCode = decodePollAnswer(which);
switch( errorCode )
{
case 0:
polled[which] = true;
yield();
mqttPoll(which); //
yield();
break;
default:
if(diagNose) ws.textAll("polling failed " + String(errorCode));
}
}
// ****************************************************************************************
// wait a certain time to see if there is something avalable
// ****************************************************************************************
bool waitSerialAvailable() // wait untill something 's available
{
unsigned long wait = millis();
while ( !Serial.available() )
{
if ( millis() - wait > 2000) return false; // return false after 2000 milis time out
}
// if we are here there is something available
delay(500);
return true;
}