Revision | fb1963284ac1e29034dd58db957318f192637a66 (tree) |
---|---|
Zeit | 2018-11-21 23:02:55 |
Autor | kazuhiro_kondow <simauma.circus@gmai...> |
Commiter | kazuhiro_kondow |
The event that the Curl command could not be issued from LG 01 to the server via Bridge resolved
@@ -6,18 +6,15 @@ | ||
6 | 6 | Then send the value to Database Server |
7 | 7 | */ |
8 | 8 | |
9 | -#include <SPI.h> | |
10 | 9 | #include <RH_RF95.h> |
11 | -#include <Bridge.h> | |
12 | -#include <RTClib.h> | |
13 | -#include <String.h> | |
14 | 10 | #include <Process.h> |
15 | 11 | |
16 | 12 | // Objects |
17 | 13 | RH_RF95 rf95; |
18 | 14 | |
19 | 15 | #define BAUDRATE 115200 |
20 | -const char* const PostUrl = "http://shimauma-circus.sakura.ne.jp/webapp/iot/dataentry -X POST -d \"data="; | |
16 | +#define MAX_DATA_SIZE 50 | |
17 | +const char* const PostUrl = "http://shimauma-circus.sakura.ne.jp/webapp/iot/dataentry"; | |
21 | 18 | uint16_t crcdata = 0; |
22 | 19 | uint16_t recCRCData = 0; |
23 | 20 | float frequency = 920.0; |
@@ -31,19 +28,12 @@ void runCurl(const char*param); | ||
31 | 28 | |
32 | 29 | void setup() |
33 | 30 | { |
34 | - // Bridge takes about two seconds to start up | |
35 | - // it can be helpful to use the on-board LED | |
36 | - // as an indicator for when it has initialized | |
37 | - pinMode(A2, OUTPUT); | |
38 | - digitalWrite(A2, LOW); | |
39 | - Bridge.begin(BAUDRATE); | |
40 | - digitalWrite(A2, HIGH); | |
41 | 31 | |
32 | + Bridge.begin(BAUDRATE); | |
42 | 33 | Console.begin(); |
43 | 34 | |
44 | 35 | // wait for a serial connection |
45 | - while (!Console) | |
46 | - ; | |
36 | + while (!Console); | |
47 | 37 | |
48 | 38 | // Setup rf95 |
49 | 39 | if (!rf95.init()) |
@@ -61,11 +51,11 @@ void setup() | ||
61 | 51 | void loop() |
62 | 52 | { |
63 | 53 | //receive data buffer |
64 | - uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; | |
54 | + uint8_t buf[MAX_DATA_SIZE]; | |
65 | 55 | //data buffer length |
66 | 56 | uint8_t len = sizeof(buf); |
67 | 57 | //post data buffer |
68 | - char postdata[RH_RF95_MAX_MESSAGE_LEN] = {'\0'}; | |
58 | + char postdata[MAX_DATA_SIZE] = {'\0'}; | |
69 | 59 | |
70 | 60 | // Listen Data from LoRa Node |
71 | 61 | if (rf95.waitAvailableTimeout(2000)) |
@@ -87,12 +77,10 @@ void loop() | ||
87 | 77 | } |
88 | 78 | Console.println(""); |
89 | 79 | |
90 | - snprintf(postdata,RH_RF95_MAX_MESSAGE_LEN,"%s",PostUrl); | |
91 | 80 | for (int i = 0; i < len; i++) |
92 | 81 | { |
93 | 82 | snprintf(postdata,RH_RF95_MAX_MESSAGE_LEN,"%s%02x",postdata,buf[i]); |
94 | 83 | } |
95 | - snprintf(postdata,RH_RF95_MAX_MESSAGE_LEN,"%s%s",postdata,"\""); | |
96 | 84 | Console.println(postdata); |
97 | 85 | runCurl(postdata); |
98 | 86 |
@@ -184,17 +172,26 @@ boolean rcvSensorData(uint8_t *buf,uint8_t *len) | ||
184 | 172 | } |
185 | 173 | |
186 | 174 | void runCurl(const char*param) { |
187 | - Process p; | |
188 | - p.begin("curl"); | |
189 | - p.addParameter(param); | |
190 | - p.run(); | |
191 | - | |
192 | - while (p.available() > 0) { | |
193 | - char c = p.read(); | |
194 | - Console.print(c); | |
195 | - } | |
196 | - Console.println(""); | |
197 | - Console.println("Process is not available!"); | |
198 | - | |
199 | - Console.flush(); | |
175 | + Process process; | |
176 | + char mbuffer[100] = {'\0'}; | |
177 | + snprintf(mbuffer,100,"data=%s",param); | |
178 | + Console.print(mbuffer); | |
179 | + | |
180 | + process.begin("curl"); | |
181 | + process.addParameter(PostUrl); | |
182 | + process.addParameter("-i"); | |
183 | + process.addParameter("-X"); | |
184 | + process.addParameter("POST"); | |
185 | + process.addParameter("-d"); | |
186 | + process.addParameter(mbuffer); | |
187 | + process.run(); | |
188 | + | |
189 | + while (process.available() > 0) { | |
190 | + char c = process.read(); | |
191 | + Console.print(c); | |
192 | + } | |
193 | + Console.println(""); | |
194 | + Console.println("Process is not available!"); | |
195 | + | |
196 | + Console.flush(); | |
200 | 197 | } |
@@ -1,8 +1,18 @@ | ||
1 | -#include<Process.h> | |
1 | +#include <Process.h> | |
2 | + | |
2 | 3 | #define BAUDRATE 115200 |
4 | + | |
5 | +// Objects | |
6 | +Process process; | |
7 | + | |
8 | +const char* const PostUrl = "http://shimauma-circus.sakura.ne.jp/webapp/iot/dataentry"; | |
9 | + | |
10 | +// ProtType | |
11 | +void runCurl(const char*param); | |
12 | + | |
3 | 13 | void setup() { |
4 | - // put your setup code here, to run once: | |
5 | 14 | |
15 | + // put your setup code here, to run once: | |
6 | 16 | // Bridge startup |
7 | 17 | pinMode(A2, OUTPUT); |
8 | 18 | digitalWrite(A2, LOW); |
@@ -17,23 +27,34 @@ void setup() { | ||
17 | 27 | } |
18 | 28 | |
19 | 29 | void loop() { |
20 | - // put your main code here, to run repeatedly: | |
21 | - runCurl("http://10.130.1.209:80/pythontest.py"); | |
30 | + runCurl("sendTestData"); | |
22 | 31 | while(1); |
32 | + | |
23 | 33 | } |
24 | 34 | |
25 | 35 | void runCurl(const char*param) { |
26 | - Process p; | |
27 | - p.begin("curl"); | |
28 | - p.addParameter(param); | |
29 | - p.run(); | |
36 | + char mbuffer[100] = {'\0'}; | |
37 | + snprintf(mbuffer,100,"data=%s",param); | |
38 | + Console.print(mbuffer); | |
39 | + | |
40 | + process.begin("curl"); | |
41 | + process.addParameter(PostUrl); | |
42 | + process.addParameter("-i"); | |
43 | + process.addParameter("-X"); | |
44 | + process.addParameter("POST"); | |
45 | + process.addParameter("-d"); | |
46 | + process.addParameter(mbuffer); | |
47 | + process.run(); | |
30 | 48 | |
31 | - while (p.available() > 0) { | |
32 | - char c = p.read(); | |
49 | + while (process.available() > 0) { | |
50 | + char c = process.read(); | |
33 | 51 | Console.print(c); |
34 | - } | |
35 | - Console.println(""); | |
36 | - Console.println("Process is not available!"); | |
37 | - | |
38 | - Console.flush(); | |
39 | -} | |
52 | + } | |
53 | + Console.println(""); | |
54 | + Console.println("Process is not available!"); | |
55 | + | |
56 | + Console.flush(); | |
57 | +} | |
58 | + | |
59 | + | |
60 | + |