/
pipa-espressif.ino
207 lines (138 loc) · 5.45 KB
/
pipa-espressif.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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Hiveeyes Pipa Datalogger
A software spike to submit data using native WiFi on Espressif chips.
Copyright (C) 2015-2016 Clemens Gruber <clemens@hiveeyes.org>
Copyright (C) 2015-2016 Richard Pobering <richard@hiveeyes.org>
Copyright (C) 2015-2021 Andreas Motl <andreas@hiveeyes.org>
<https://hiveeyes.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see:
<http://www.gnu.org/licenses/gpl-3.0.txt>,
or write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-------------------------------------------------------------------------
This is an Arduino sketch for the Hiveeyes bee monitoring system.
The purpose is to collect vital data of a bee hive and transmit it
to the data collection server.
The sensor data could be temperature (DS18B20), humidity (BME280)
or a load cell (H30A with HX711). Other sensors can easily be added.
After the sensor data is collected, it gets serialized to JSON,
which will be the transmitted in the body of a HTTP POST request.
The creation of this code is strongly influenced by other projects,
so credits goes to them.
Feel free to adapt this code to your own needs.
-------------------------------------------------------------------------
Futher informations can be obtained at:
hiveeyes https://hiveeyes.org/
documentation https://hiveeyes.org/docs/system/
repository https://github.com/hiveeyes/
open hive http://open-hive.org/
-------------------------------------------------------------------------
*/
// ******************************************
// User configuration
// ******************************************
// Communication
// =============
// Telemetry
// ---------
#define HE_API_URL "http://swarm.hiveeyes.org/api-notls/"
#define HE_USER "testdrive"
#define HE_SITE "area-42"
#define HE_HIVE "pipa-espwifi-01"
// Sensors
// =======
// TODO: No sensors yet. This is just a telemetry demo program.
// ******************************************
// Developer configuration
// ******************************************
// Debugging
// ---------
/*
#define DEBUG
#define DEBUG_RADIO
#define DEBUG_FLASH
#define DEBUG_SENSORS
#define DEBUG_SERIAL
#define DEBUG_ENCODE
*/
// ******************************************
// Modules
// ******************************************
// Libraries
// ---------
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
#include <Terkin.h> // https://github.com/hiveeyes/arduino/tree/main/libraries/Terkin
#include <Hiveeyes.h> // https://github.com/hiveeyes/arduino/tree/main/libraries/Hiveeyes
#include <OpenHive.h> // https://github.com/hiveeyes/arduino/tree/main/libraries/OpenHive
#include <Wire.h> // Arduino
// Imports
// -------
using namespace Terkin;
using namespace Hiveeyes;
using namespace OpenHive;
// ******************************************
// Sensors
// ******************************************
// ******************************************
// Main program
// ******************************************
// Main telemetry API
TelemetryNode *telemetry;
// Forward declarations
TelemetryNode& setup_telemetry_esphttp_json();
// Setup function
void setup() {
// Telemetry setup
#if USE_ESPHTTP_JSON
telemetry = &setup_telemetry_esphttp_json();
#endif
// Sensor setup
// FIXME: No sensors yet. This is just a telemetry demo program.
}
// Main loop
void loop() {
// 1. Read sensors
// Collect basic sensor data
// TODO: No sensors yet. This is just a telemetry demo program.
JsonObject& data_basic = openhive_sensors.read_demo();
// Collect sensor data from temperature array
// TODO: No sensors yet. This is just a telemetry demo program.
JsonObject& data_temparray = openhive_temparray.read_demo();
// 2. Transmit data
// Transmit telemetry data to data collection server
telemetry->transmit(data_basic);
telemetry->transmit(data_temparray);
// TODO: Start sleeping cycle, see "node-rfm69-beradio.ino"
delay(5000);
}
/**
*
* Setup function for initializing a TelemetryNode instance
* with appropriate components in individual setups.
*
* Here, the machinery is instructed to
* communicate using WiFi on an Espressif device.
*
**/
#if USE_ESPHTTP_JSON
TelemetryNode& setup_telemetry_esphttp_json() {
/* Setup telemetry client with pluggable components */
// Transmitter
ESPHTTPTransmitter transmitter;
// Telemetry manager
TelemetryManager manager(transmitter, HE_API_URL);
// Telemetry node
HiveeyesNodeAddress address(HE_USER, HE_SITE, HE_HIVE);
TelemetryNode node(manager, address);
return node;
}
#endif