1
1
#include < PPP.h>
2
2
3
- #define PPP_MODEM_APN " internet"
4
- #define PPP_MODEM_PIN " 0000" // or NULL
3
+ #define PPP_MODEM_APN " internet"
4
+ #define PPP_MODEM_PIN " 0000" // or NULL
5
5
6
6
// WaveShare SIM7600 HW Flow Control
7
- #define PPP_MODEM_RST 25
8
- #define PPP_MODEM_RST_LOW false // active HIGH
9
- #define PPP_MODEM_TX 21
10
- #define PPP_MODEM_RX 22
11
- #define PPP_MODEM_RTS 26
12
- #define PPP_MODEM_CTS 27
13
- #define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_HW
14
- #define PPP_MODEM_MODEL PPP_MODEM_SIM7600
7
+ #define PPP_MODEM_RST 25
8
+ #define PPP_MODEM_RST_LOW false // active HIGH
9
+ #define PPP_MODEM_TX 21
10
+ #define PPP_MODEM_RX 22
11
+ #define PPP_MODEM_RTS 26
12
+ #define PPP_MODEM_CTS 27
13
+ #define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_HW
14
+ #define PPP_MODEM_MODEL PPP_MODEM_SIM7600
15
15
16
16
// SIM800 basic module with just TX,RX and RST
17
17
// #define PPP_MODEM_RST 0
23
23
// #define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_NONE
24
24
// #define PPP_MODEM_MODEL PPP_MODEM_SIM800
25
25
26
- void onEvent (arduino_event_id_t event, arduino_event_info_t info)
27
- {
26
+ void onEvent (arduino_event_id_t event, arduino_event_info_t info) {
28
27
switch (event) {
29
28
case ARDUINO_EVENT_PPP_START:
30
29
Serial.println (" PPP Started" );
@@ -49,16 +48,17 @@ void onEvent(arduino_event_id_t event, arduino_event_info_t info)
49
48
}
50
49
}
51
50
52
- void testClient (const char * host, uint16_t port) {
51
+ void testClient (const char * host, uint16_t port) {
53
52
NetworkClient client;
54
53
if (!client.connect (host, port)) {
55
54
Serial.println (" Connection Failed" );
56
55
return ;
57
56
}
58
57
client.printf (" GET / HTTP/1.1\r\n Host: %s\r\n\r\n " , host);
59
- while (client.connected () && !client.available ());
58
+ while (client.connected () && !client.available ())
59
+ ;
60
60
while (client.available ()) {
61
- client.read ();// Serial.write(client.read());
61
+ client.read (); // Serial.write(client.read());
62
62
}
63
63
64
64
Serial.println (" Connection Success" );
@@ -70,7 +70,7 @@ void setup() {
70
70
71
71
// Listen for modem events
72
72
Network.onEvent (onEvent);
73
-
73
+
74
74
// Configure the modem
75
75
PPP.setApn (PPP_MODEM_APN);
76
76
PPP.setPin (PPP_MODEM_PIN);
@@ -80,16 +80,19 @@ void setup() {
80
80
Serial.println (" Starting the modem. It might take a while!" );
81
81
PPP.begin (PPP_MODEM_MODEL);
82
82
83
- Serial.print (" Manufacturer: " ); Serial.println (PPP.cmd (" AT+CGMI" , 10000 ));
84
- Serial.print (" Model: " ); Serial.println (PPP.moduleName ());
85
- Serial.print (" IMEI: " ); Serial.println (PPP.IMEI ());
86
-
83
+ Serial.print (" Manufacturer: " );
84
+ Serial.println (PPP.cmd (" AT+CGMI" , 10000 ));
85
+ Serial.print (" Model: " );
86
+ Serial.println (PPP.moduleName ());
87
+ Serial.print (" IMEI: " );
88
+ Serial.println (PPP.IMEI ());
89
+
87
90
bool attached = PPP.attached ();
88
- if (!attached){
89
- int i= 0 ;
91
+ if (!attached) {
92
+ int i = 0 ;
90
93
unsigned int s = millis ();
91
94
Serial.print (" Waiting to connect to network" );
92
- while (!attached && ((++i) < 600 )){
95
+ while (!attached && ((++i) < 600 )) {
93
96
Serial.print (" ." );
94
97
delay (100 );
95
98
attached = PPP.attached ();
@@ -98,22 +101,29 @@ void setup() {
98
101
Serial.println (" s" );
99
102
attached = PPP.attached ();
100
103
}
101
-
102
- Serial.print (" Attached: " ); Serial.println (attached);
103
- Serial.print (" State: " ); Serial.println (PPP.radioState ());
104
- if (attached){
105
- Serial.print (" Operator: " ); Serial.println (PPP.operatorName ());
106
- Serial.print (" IMSI: " ); Serial.println (PPP.IMSI ());
107
- Serial.print (" RSSI: " ); Serial.println (PPP.RSSI ());
104
+
105
+ Serial.print (" Attached: " );
106
+ Serial.println (attached);
107
+ Serial.print (" State: " );
108
+ Serial.println (PPP.radioState ());
109
+ if (attached) {
110
+ Serial.print (" Operator: " );
111
+ Serial.println (PPP.operatorName ());
112
+ Serial.print (" IMSI: " );
113
+ Serial.println (PPP.IMSI ());
114
+ Serial.print (" RSSI: " );
115
+ Serial.println (PPP.RSSI ());
108
116
int ber = PPP.BER ();
109
- if (ber > 0 ){
110
- Serial.print (" BER: " ); Serial.println (ber);
111
- Serial.print (" NetMode: " ); Serial.println (PPP.networkMode ());
117
+ if (ber > 0 ) {
118
+ Serial.print (" BER: " );
119
+ Serial.println (ber);
120
+ Serial.print (" NetMode: " );
121
+ Serial.println (PPP.networkMode ());
112
122
}
113
-
123
+
114
124
Serial.println (" Switching to data mode..." );
115
- PPP.mode (ESP_MODEM_MODE_CMUX); // Data and Command mixed mode
116
- if (!PPP.waitStatusBits (ESP_NETIF_CONNECTED_BIT, 1000 )){
125
+ PPP.mode (ESP_MODEM_MODE_CMUX); // Data and Command mixed mode
126
+ if (!PPP.waitStatusBits (ESP_NETIF_CONNECTED_BIT, 1000 )) {
117
127
Serial.println (" Failed to connect to internet!" );
118
128
} else {
119
129
Serial.println (" Connected to internet!" );
0 commit comments