sim7600test.ino
3.63 KB
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
/******************************************************************************
* HTTPS testing sketch for Freematics ONE+ with SIM7600
* https://freematics.com/products/freematics-one-plus/
* Developed by Stanley Huang, distributed under BSD license
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
#include <FreematicsCell.h>
#define PIN_BEE_UART_RXD 16
#define PIN_BEE_UART_TXD 17
#define PIN_BEE_PWR 27
// testing URL: https://hub.freematics.com/test
#define SERVER_HOST "hub.freematics.com"
#define SERVER_PORT 443
#define SERVER_PATH "/test"
#define CELL_APN ""
#define CONN_TIMEOUT 5000
HTTPClientSIM7600 net;
int errors = 0;
bool init_net()
{
Serial.print("Init cellular module...");
if (net.begin()) {
Serial.print(net.deviceName());
Serial.println(" OK");
} else {
Serial.println("NO");
return false;
}
Serial.print("IMEI:");
Serial.println(net.IMEI);
if (net.checkSIM()) {
Serial.println("SIM Card OK");
} else {
Serial.println("No SIM Card");
}
Serial.print("Registering on network...");
if (net.setup(CELL_APN)) {
Serial.println("OK");
} else {
Serial.println("NO");
return false;
}
String op = net.getOperatorName();
if (op.length()) {
Serial.print("Operator:");
Serial.println(op);
}
Serial.print("Obtaining IP address...");
String ip = net.getIP();
if (ip) {
Serial.println(ip);
} else {
Serial.println("N/A");
}
int signal = net.getSignal();
if (signal) {
Serial.print("RSSI:");
Serial.print(signal);
Serial.println("dBm");
}
Serial.print("Init HTTPS stack...");
if (net.open()) {
Serial.println("OK");
} else {
Serial.println("NO");
}
return true;
}
void setup()
{
Serial.begin(115200);
// start serial communication with cellular module
net.xbBegin(115200, PIN_BEE_UART_RXD, PIN_BEE_UART_TXD);
// initialize cellular module
while (!init_net());
}
void loop()
{
if (errors > 10) {
// re-initialize cellular module
net.end();
if (init_net()) {
Serial.println("OK");
errors = 0;
} else {
Serial.println("NO");
delay(3000);
return;
}
}
// connect to HTTP server
if (net.state() != HTTP_CONNECTED) {
Serial.print("Connecting...");
if (net.open(SERVER_HOST, SERVER_PORT)) {
Serial.println("OK");
} else {
Serial.println("failed");
net.close();
errors++;
return;
}
}
// send HTTP request
Serial.print("Sending request...");
if (!net.send(METHOD_GET, SERVER_PATH, true)) {
Serial.println("failed");
net.close();
errors++;
return;
} else {
Serial.println("OK");
}
// receive HTTP response
Serial.print("Receiving...");
char *response;
int bytes;
response = net.receive(&bytes);
if (response) {
Serial.println("OK");
Serial.println("-----HTTP RESPONSE-----");
Serial.println(response);
Serial.println("-----------------------");
errors = 0;
} else {
Serial.println("failed");
net.close();
errors++;
}
Serial.println("Waiting 5 seconds...");
delay(5000);
}