4
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
- #define PPP_MODEM_RST 0
18
- #define PPP_MODEM_RST_LOW true // active LOW
19
- #define PPP_MODEM_TX 2
20
- #define PPP_MODEM_RX 19
21
- #define PPP_MODEM_RTS -1
22
- #define PPP_MODEM_CTS -1
23
- #define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_NONE
24
- #define PPP_MODEM_MODEL PPP_MODEM_SIM800
25
-
26
- static bool ppp_connected = false ;
17
+ // #define PPP_MODEM_RST 0
18
+ // #define PPP_MODEM_RST_LOW true //active LOW
19
+ // #define PPP_MODEM_TX 2
20
+ // #define PPP_MODEM_RX 19
21
+ // #define PPP_MODEM_RTS -1
22
+ // #define PPP_MODEM_CTS -1
23
+ // #define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_NONE
24
+ // #define PPP_MODEM_MODEL PPP_MODEM_SIM800
27
25
28
26
void onEvent (arduino_event_id_t event, arduino_event_info_t info)
29
27
{
@@ -36,26 +34,16 @@ void onEvent(arduino_event_id_t event, arduino_event_info_t info)
36
34
break ;
37
35
case ARDUINO_EVENT_PPP_GOT_IP:
38
36
Serial.println (" PPP Got IP" );
39
- Serial.println (PPP);
40
- ppp_connected = true ;
41
- break ;
42
- case ARDUINO_EVENT_PPP_GOT_IP6:
43
- Serial.println (" PPP Got IPv6" );
44
- Serial.println (PPP);
45
37
break ;
46
38
case ARDUINO_EVENT_PPP_LOST_IP:
47
39
Serial.println (" PPP Lost IP" );
48
- ppp_connected = false ;
49
40
break ;
50
41
case ARDUINO_EVENT_PPP_DISCONNECTED:
51
42
Serial.println (" PPP Disconnected" );
52
- ppp_connected = false ;
53
43
break ;
54
44
case ARDUINO_EVENT_PPP_STOP:
55
45
Serial.println (" PPP Stopped" );
56
- ppp_connected = false ;
57
46
break ;
58
-
59
47
default :
60
48
break ;
61
49
}
@@ -79,22 +67,28 @@ void testClient(const char * host, uint16_t port) {
79
67
80
68
void setup () {
81
69
Serial.begin (115200 );
70
+
71
+ // Listen for modem events
82
72
Network.onEvent (onEvent);
73
+
74
+ // Configure the modem
83
75
PPP.setApn (PPP_MODEM_APN);
84
76
PPP.setPin (PPP_MODEM_PIN);
85
77
PPP.setResetPin (PPP_MODEM_RST, PPP_MODEM_RST_LOW);
86
78
PPP.setPins (PPP_MODEM_TX, PPP_MODEM_RX, PPP_MODEM_RTS, PPP_MODEM_CTS, PPP_MODEM_FC);
79
+
87
80
Serial.println (" Starting the modem. It might take a while!" );
88
81
PPP.begin (PPP_MODEM_MODEL);
89
82
90
- Serial.print (" Name: " ); Serial.println (PPP.moduleName ());
83
+ Serial.print (" Manufacturer: " ); Serial.println (PPP.cmd (" AT+CGMI" , 10000 ));
84
+ Serial.print (" Model: " ); Serial.println (PPP.moduleName ());
91
85
Serial.print (" IMEI: " ); Serial.println (PPP.IMEI ());
92
86
93
87
bool attached = PPP.attached ();
94
88
if (!attached){
95
89
int i=0 ;
96
90
unsigned int s = millis ();
97
- Serial.print (" Waiting to attach " );
91
+ Serial.print (" Waiting to connect to network " );
98
92
while (!attached && ((++i) < 600 )){
99
93
Serial.print (" ." );
100
94
delay (100 );
@@ -112,18 +106,25 @@ void setup() {
112
106
Serial.print (" IMSI: " ); Serial.println (PPP.IMSI ());
113
107
Serial.print (" RSSI: " ); Serial.println (PPP.RSSI ());
114
108
int ber = PPP.BER ();
115
- Serial. print ( " BER: " ); Serial. println (ber);
116
- if ( ber){
109
+ if (ber > 0 ){
110
+ Serial. print ( " BER: " ); Serial. println ( ber);
117
111
Serial.print (" NetMode: " ); Serial.println (PPP.networkMode ());
118
112
}
119
113
120
- // PPP.mode(ESP_MODEM_MODE_DATA); // Data ONLY mode
121
- PPP.mode (ESP_MODEM_MODE_CMUX); // Data and Commands mode
114
+ 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 )){
117
+ Serial.println (" Failed to connect to internet!" );
118
+ } else {
119
+ Serial.println (" Connected to internet!" );
120
+ }
121
+ } else {
122
+ Serial.println (" Failed to connect to network!" );
122
123
}
123
124
}
124
125
125
126
void loop () {
126
- if (ppp_connected ) {
127
+ if (PPP. connected () ) {
127
128
testClient (" google.com" , 80 );
128
129
}
129
130
delay (20000 );
0 commit comments