-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathinput.cpp
63 lines (56 loc) · 1.93 KB
/
input.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
/*
* -------------------------------------------------------------------
* EmonESP Serial to Emoncms gateway
* -------------------------------------------------------------------
* Adaptation of Chris Howells OpenEVSE ESP Wifi
* by Trystan Lea, Glyn Hudson, OpenEnergyMonitor
* All adaptation GNU General Public License as below.
*
* -------------------------------------------------------------------
*
* This file is part of OpenEnergyMonitor.org project.
* EmonESP 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, or (at your option)
* any later version.
* EmonESP 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 EmonESP; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "emonesp.h"
#include "input.h"
String input_string="";
String last_datastr="";
boolean input_get(String& data)
{
boolean gotData = false;
// If data from test API e.g `http://<IP-ADDRESS>/input?string=CT1:3935,CT2:325,T1:12.5,T2:16.9,T3:11.2,T4:34.7`
if(input_string.length() > 0) {
data = input_string;
input_string = "";
gotData = true;
}
// If data received on serial
else if (Serial.available()) {
// Could check for string integrity here
data = Serial.readStringUntil('\n');
gotData = true;
}
if(gotData)
{
// Get rid of any whitespace, newlines etc
data.trim();
if(data.length() > 0) {
DEBUG.printf("Got '%s'\n", data.c_str());
last_datastr = data;
} else {
gotData = false;
}
}
return gotData;
}