-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrf24weather_net-noexit-multi.cpp
142 lines (124 loc) · 4.2 KB
/
rf24weather_net-noexit-multi.cpp
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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "../RF24/RF24.h"
#include "./RF24Network.h"
#include <unistd.h>
unsigned int microseconds;
using namespace std;
// init network
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ);
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
RF24Network network(radio);
const uint16_t this_node = 0;
// define struct for char array
struct payload_t
{
char readings[32];
};
int main(int argc, char** argv)
{
// init radio
radio.begin();
delay(5);
// radio.printDetails();
network.begin(90, this_node);
radio.setDataRate(RF24_250KBPS);
radio.setPALevel(RF24_PA_MAX);
while(1)
{
// pump network
network.update();
while (network.available())
{
// get payload
RF24NetworkHeader header;
payload_t payload;
network.read(header,&payload,sizeof(payload));
// get time - can be passed to time.localtime()
time_t rawtime;
time (&rawtime);
if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '2'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather02.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '3'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather03.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '4'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather04.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '5'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather05.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '6'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather06.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '7'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather07.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '8'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather08.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else if ( (payload.readings[0] == '0') &&
(payload.readings[1] == '1'))
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather01.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
else
{
ofstream myfile;
myfile.open ("/dev/shm/rf24weather-no.txt");
myfile << payload.readings << ',' << rawtime << endl;
myfile.close();
}
// write to file and close
// ofstream myfile;
// myfile.open ("/dev/shm/rf24weather.txt");
// myfile << payload.readings << ',' << rawtime << endl;
// myfile.close();
//exit (0);
}
// pause for 5mins to reduce cpu/disk load
// sleep(1);
usleep (500);
}
return 0;
}