-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio.ino
90 lines (83 loc) · 2.99 KB
/
radio.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
// =======================================================================================
// ---- Receives Temperature from remote RF12B transmitter ----
// =======================================================================================
static boolean __radioOn=false;
#ifdef RFM12B_PRESENT
void receiveTemp() {
if (!Settings.RadioEnabled) return;
if (isInMenu) return;
if ((alarmState[0]==AS_SOUNDING) || (alarmState[1]==AS_SOUNDING)) return;
if (wave.isplaying) return;
//if (isInQMenu) return;
if (!__radioOn) {
radio.Wakeup(); // Turn on Radio
__radioOn=true;
//putstring_nl ("Radio Wake up!");
}
if ( ((millis()-last_RF) > 900000 ) || last_RF==0) plot (31,0,RED); //Indicate that temp hasn't been received in over 15 min
//else if ( (millis()-last_RF) > 5000 ) plot (31,0,BLACK); //Hide indicator
else plot (31,0,BLACK); //Hide indicator
char tempC[3];
char humidity[3];
digitalWrite(SS_SD,HIGH); // Disable SD Card / Audio
if (radio.ReceiveComplete())
{
if (radio.CRCPass())
{
//Serial.println (now());
//putstring_nl ("Receiving Temp...");
last_RF=millis();
plot (31,0,GREEN); //Plot Indicator dot (radio signal was received)
//Serial.println (radio.GetDataLen());
/*
for (byte i = 0; i < *radio.DataLen; i++) {//can also use radio.GetDataLen() if you don't like pointers
// Serial.print((char)radio.Data[i]);
Serial.println (i);
if (i==2) ; // Do nothing, it's comma separating temp and humidity
else {
if (i<3) tempC[i]=(char)radio.Data[i]; //Fill char array with temp.
else {// Now we getting humidity
humidity[i]=(char)radio.Data[i];
}
} // end Else
} // end For
*/
if (*radio.DataLen > 2) { // Make sure received data is not empty
// First 2 characters transmitted are temperature, 3rd is comma, and rest is humidity
tempC[0]=(char)radio.Data[0];
tempC[1]=(char)radio.Data[1];
humidity[0]=(char)radio.Data[3];
humidity[1]=(char)radio.Data[4];
extTemp = atol(tempC); // Assign external Temp variable Integer number
extHum = atol(humidity); // Assign external Temp variable Integer number
}
//Serial.print ("Temp: "); Serial.println (extTemp);
//Serial.print ("Humidity: "); Serial.println (extHum);
if (radio.ACKRequested())
{
radio.SendACK();
//Serial.print(" - ACK sent");
}
}
//else
//Serial.print("BAD-CRC");
//Serial.println();
}
}
#endif
// ==================================================
// -- Turns off radio and keeps track of it's status
void turnOffRadio() {
#ifdef RFM12B_PRESENT
if (!Settings.RadioEnabled) return;
//radio.Sleep();
if (__radioOn) {
radio.Sleep();
__radioOn=false;
//putstring_nl ("Radio Sleep!");
delay (5);
}
#else
return; // no radio
#endif
}