Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 49872bf

Browse files
committedApr 9, 2024
Add example sketch
1 parent b6bdcbb commit 49872bf

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed
 
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include <PPP.h>
2+
3+
#define PPP_MODEM_APN "internet"
4+
#define PPP_MODEM_PIN "0000" // or NULL
5+
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
15+
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;
27+
28+
void onEvent(arduino_event_id_t event, arduino_event_info_t info)
29+
{
30+
switch (event) {
31+
case ARDUINO_EVENT_PPP_START:
32+
Serial.println("PPP Started");
33+
break;
34+
case ARDUINO_EVENT_PPP_CONNECTED:
35+
Serial.println("PPP Connected");
36+
break;
37+
case ARDUINO_EVENT_PPP_GOT_IP:
38+
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+
break;
46+
case ARDUINO_EVENT_PPP_LOST_IP:
47+
Serial.println("PPP Lost IP");
48+
ppp_connected = false;
49+
break;
50+
case ARDUINO_EVENT_PPP_DISCONNECTED:
51+
Serial.println("PPP Disconnected");
52+
ppp_connected = false;
53+
break;
54+
case ARDUINO_EVENT_PPP_STOP:
55+
Serial.println("PPP Stopped");
56+
ppp_connected = false;
57+
break;
58+
59+
default:
60+
break;
61+
}
62+
}
63+
64+
void testClient(const char * host, uint16_t port) {
65+
NetworkClient client;
66+
if (!client.connect(host, port)) {
67+
Serial.println("Connection Failed");
68+
return;
69+
}
70+
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
71+
while (client.connected() && !client.available());
72+
while (client.available()) {
73+
client.read();//Serial.write(client.read());
74+
}
75+
76+
Serial.println("Connection Success");
77+
client.stop();
78+
}
79+
80+
void setup() {
81+
Serial.begin(115200);
82+
Network.onEvent(onEvent);
83+
PPP.setApn(PPP_MODEM_APN);
84+
PPP.setPin(PPP_MODEM_PIN);
85+
PPP.setResetPin(PPP_MODEM_RST, PPP_MODEM_RST_LOW);
86+
PPP.setPins(PPP_MODEM_TX, PPP_MODEM_RX, PPP_MODEM_RTS, PPP_MODEM_CTS, PPP_MODEM_FC);
87+
Serial.println("Starting the modem. It might take a while!");
88+
PPP.begin(PPP_MODEM_MODEL);
89+
90+
Serial.print("Name: "); Serial.println(PPP.moduleName());
91+
Serial.print("IMEI: "); Serial.println(PPP.IMEI());
92+
93+
bool attached = PPP.attached();
94+
if(!attached){
95+
int i=0;
96+
unsigned int s = millis();
97+
Serial.print("Waiting to attach ");
98+
while(!attached && ((++i) < 600)){
99+
Serial.print(".");
100+
delay(100);
101+
attached = PPP.attached();
102+
}
103+
Serial.print((millis() - s) / 1000.0, 1);
104+
Serial.println("s");
105+
attached = PPP.attached();
106+
}
107+
108+
Serial.print("Attached: "); Serial.println(attached);
109+
Serial.print("State: "); Serial.println(PPP.radioState());
110+
if(attached){
111+
Serial.print("Operator: "); Serial.println(PPP.operatorName());
112+
Serial.print("IMSI: "); Serial.println(PPP.IMSI());
113+
Serial.print("RSSI: "); Serial.println(PPP.RSSI());
114+
int ber = PPP.BER();
115+
Serial.print("BER: "); Serial.println(ber);
116+
if(ber){
117+
Serial.print("NetMode: "); Serial.println(PPP.networkMode());
118+
}
119+
120+
// PPP.mode(ESP_MODEM_MODE_DATA); // Data ONLY mode
121+
PPP.mode(ESP_MODEM_MODE_CMUX); // Data and Commands mode
122+
}
123+
}
124+
125+
void loop() {
126+
if (ppp_connected) {
127+
testClient("google.com", 80);
128+
}
129+
delay(20000);
130+
}

‎libraries/PPP/src/PPP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ bool PPPClass::begin(ppp_modem_model_t model){
236236
} else {
237237
pinMode(_pin_rst, OUTPUT);
238238
}
239-
digitalWrite(25, !_pin_rst_act_low);
239+
digitalWrite(_pin_rst, !_pin_rst_act_low);
240240
delay(200);
241-
digitalWrite(25, _pin_rst_act_low);
241+
digitalWrite(_pin_rst, _pin_rst_act_low);
242242
delay(200);
243243
}
244244

0 commit comments

Comments
 (0)
Please sign in to comment.