Skip to content

Commit

Permalink
Added elite lte ppp example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Aug 17, 2024
1 parent dd5933b commit d208084
Show file tree
Hide file tree
Showing 5 changed files with 631 additions and 0 deletions.
130 changes: 130 additions & 0 deletions examples/PPP_Basic/PPP_Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include <Arduino.h>
#if ESP_ARDUINO_VERSION < ESP_ARDUINO_VERSION_VAL(3,0,4)
#error This sketch can only run on esp32 core version 3.0.0 and above
void setup() {}
void loop() {}
#else
#include <PPP.h>
#include "utilities.h"

#define PPP_MODEM_APN "You APN"
#define PPP_MODEM_PIN "0000" // or NULL

// SIM7600/A7670 basic module with just TX,RX and RST
#define PPP_MODEM_RST MODEM_PWRKEY_PIN
#define PPP_MODEM_RST_LOW false //active LOW
#define PPP_MODEM_RST_DELAY 200
#define PPP_MODEM_TX MODEM_TX_PIN
#define PPP_MODEM_RX MODEM_RX_PIN
#define PPP_MODEM_RTS -1
#define PPP_MODEM_CTS -1
#define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_NONE
#define PPP_MODEM_MODEL PPP_MODEM_SIM7600

void onEvent(arduino_event_id_t event, arduino_event_info_t info)
{
switch (event) {
case ARDUINO_EVENT_PPP_START: Serial.println("PPP Started"); break;
case ARDUINO_EVENT_PPP_CONNECTED: Serial.println("PPP Connected"); break;
case ARDUINO_EVENT_PPP_GOT_IP: Serial.println("PPP Got IP"); break;
case ARDUINO_EVENT_PPP_LOST_IP: Serial.println("PPP Lost IP"); break;
case ARDUINO_EVENT_PPP_DISCONNECTED: Serial.println("PPP Disconnected"); break;
case ARDUINO_EVENT_PPP_STOP: Serial.println("PPP Stopped"); break;
default: break;
}
}

void testClient(const char *host, uint16_t port)
{
NetworkClient client;
if (!client.connect(host, port)) {
Serial.println("Connection Failed");
return;
}
client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host);
while (client.connected() && !client.available());
while (client.available()) {
Serial.write(client.read());
}

Serial.println("Connection Success");
client.stop();
}

void setup()
{
Serial.begin(115200);

// Listen for modem events
Network.onEvent(onEvent);

// Configure the modem
PPP.setApn(PPP_MODEM_APN);
PPP.setPin(PPP_MODEM_PIN);
PPP.setResetPin(PPP_MODEM_RST, PPP_MODEM_RST_LOW, PPP_MODEM_RST_DELAY);
PPP.setPins(PPP_MODEM_TX, PPP_MODEM_RX, PPP_MODEM_RTS, PPP_MODEM_CTS, PPP_MODEM_FC);

Serial.println("Starting the modem. It might take a while!");
PPP.begin(PPP_MODEM_MODEL);

Serial.print("Manufacturer: ");
Serial.println(PPP.cmd("AT+CGMI", 10000));
Serial.print("Model: ");
Serial.println(PPP.moduleName());
Serial.print("IMEI: ");
Serial.println(PPP.IMEI());

bool attached = PPP.attached();
if (!attached) {
int i = 0;
unsigned int s = millis();
Serial.print("Waiting to connect to network");
while (!attached && ((++i) < 600)) {
Serial.print(".");
delay(100);
attached = PPP.attached();
}
Serial.print((millis() - s) / 1000.0, 1);
Serial.println("s");
attached = PPP.attached();
}

Serial.print("Attached: ");
Serial.println(attached);
Serial.print("State: ");
Serial.println(PPP.radioState());
if (attached) {
Serial.print("Operator: ");
Serial.println(PPP.operatorName());
Serial.print("IMSI: ");
Serial.println(PPP.IMSI());
Serial.print("RSSI: ");
Serial.println(PPP.RSSI());
int ber = PPP.BER();
if (ber > 0) {
Serial.print("BER: ");
Serial.println(ber);
Serial.print("NetMode: ");
Serial.println(PPP.networkMode());
}

Serial.println("Switching to data mode...");
PPP.mode(ESP_MODEM_MODE_CMUX); // Data and Command mixed mode
if (!PPP.waitStatusBits(ESP_NETIF_CONNECTED_BIT, 1000)) {
Serial.println("Failed to connect to internet!");
} else {
Serial.println("Connected to internet!");
}
} else {
Serial.println("Failed to connect to network!");
}
}

void loop()
{
if (PPP.connected()) {
testClient("baidu.com", 80);
}
delay(20000);
}
#endif
49 changes: 49 additions & 0 deletions examples/PPP_Basic/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Capture log

```bash
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xb (SPI_FAST_FLASH_BOOT)
Saved PC:0x40379a82
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x109c
load:0x403c9700,len:0x4
load:0x403c9704,len:0xb50
load:0x403cc700,len:0x2fd0
entry 0x403c98ac
Starting the modem. It might take a while!
PPP Started
Manufacturer: INCORPORATED
Model: A7670E-FASE
IMEI: 8622xxxxxxxxx
Waiting to connect to network......0.7s
Attached: 1
State: 1
Operator: 46001
IMSI: 460013XXXXXXXX
RSSI: 99
BER: 99
NetMode: 8
Switching to data mode...
PPP Got IP
PPP Connected
Connected to internet!
HTTP/1.1 200 OK
Date: Sat, 17 Aug 2024 07:10:04 GMT
Server: Apache
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
ETag: "51-47cf7e6ee8400"
Accept-Ranges: bytes
Content-Length: 81
Cache-Control: max-age=86400
Expires: Sun, 18 Aug 2024 07:10:04 GMT
Connection: Keep-Alive
Content-Type: text/html

<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
Connection Success

```
148 changes: 148 additions & 0 deletions examples/PPP_Basic/utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

#pragma once

// Product Link : https://www.lilygo.cc/products/t-internet-poe
// #define LILYGO_T_INTERNET_POE

// Product Link : https://www.lilygo.cc/products/t-poe-pro
// #define LILYGO_T_ETH_POE_PRO

// Product Link : https://www.lilygo.cc/products/t-internet-com
// #define LILYGO_T_INTER_COM

// Product Link : https://www.lilygo.cc/products/t-eth-lite?variant=43120880746677
// #define LILYGO_T_ETH_LITE_ESP32

// Product Link : https://www.lilygo.cc/products/t-eth-lite?variant=43120880779445
// #define LILYGO_T_ETH_LITE_ESP32S3

// Product Link : N.A
#define LILYGO_T_ETH_ELITE_ESP32S3

#if defined(LILYGO_T_INTERNET_POE)
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
#define ETH_ADDR 0
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_RESET_PIN 5
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define SD_MISO_PIN 2
#define SD_MOSI_PIN 15
#define SD_SCLK_PIN 14
#define SD_CS_PIN 13

#elif defined(LILYGO_T_ETH_POE_PRO)
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_ADDR 0
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT
#define ETH_RESET_PIN 5
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define SD_MISO_PIN 12
#define SD_MOSI_PIN 13
#define SD_SCLK_PIN 14
#define SD_CS_PIN 15
#define TFT_DC 2
#define RS485_TX 32
#define RS485_RX 33

#elif defined(LILYGO_T_INTER_COM)
#define ETH_TYPE ETH_PHY_LAN8720
#define ETH_ADDR 0
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_OUT
#define ETH_RESET_PIN 4
#define ETH_MDC_PIN 23
#define ETH_MDIO_PIN 18
#define SD_MISO_PIN 2
#define SD_MOSI_PIN 15
#define SD_SCLK_PIN 14
#define SD_CS_PIN 13
#define MODEM_RX_PIN 35
#define MODEM_TX_PIN 33
#define MODEM_PWRKEY_PIN 32
#define RGBLED_PIN 12

#elif defined(LILYGO_T_ETH_LITE_ESP32)
#define ETH_TYPE ETH_PHY_RTL8201
#define ETH_ADDR 0
#define ETH_CLK_MODE ETH_CLOCK_GPIO0_IN
#define ETH_RESET_PIN -1
#define ETH_MDC_PIN 23
#define ETH_POWER_PIN 12
#define ETH_MDIO_PIN 18
#define SD_MISO_PIN 34
#define SD_MOSI_PIN 13
#define SD_SCLK_PIN 14
#define SD_CS_PIN 5

#elif defined(LILYGO_T_ETH_LITE_ESP32S3)
#define ETH_MISO_PIN 11
#define ETH_MOSI_PIN 12
#define ETH_SCLK_PIN 10
#define ETH_CS_PIN 9
#define ETH_INT_PIN 13
#define ETH_RST_PIN 14
#define ETH_ADDR 1
#define SD_MISO_PIN 5
#define SD_MOSI_PIN 6
#define SD_SCLK_PIN 7
#define SD_CS_PIN 42


#define IR_FILTER_NUM 46
#elif defined(LILYGO_T_ETH_ELITE_ESP32S3)

#define ETH_MISO_PIN 47
#define ETH_MOSI_PIN 21
#define ETH_SCLK_PIN 48
#define ETH_CS_PIN 45
#define ETH_INT_PIN 14
#define ETH_RST_PIN -1
#define ETH_ADDR 1

#define SPI_MISO_PIN 9
#define SPI_MOSI_PIN 11
#define SPI_SCLK_PIN 10

#define SD_MISO_PIN SPI_MISO_PIN
#define SD_MOSI_PIN SPI_MOSI_PIN
#define SD_SCLK_PIN SPI_SCLK_PIN
#define SD_CS_PIN 12

#define I2C_SDA_PIN 17
#define I2C_SCL_PIN 18

#define RADIO_MISO_PIN SPI_MISO_PIN
#define RADIO_MOSI_PIN SPI_MOSI_PIN
#define RADIO_SCLK_PIN SPI_SCLK_PIN
#define RADIO_CS_PIN 40
#define RADIO_RST_PIN 46
// #define RADIO_DIO1_PIN 16
#define RADIO_IRQ_PIN 8
#define RADIO_BUSY_PIN 16

#define ADC_BUTTONS_PIN 7

#define MODEM_RX_PIN 4
#define MODEM_TX_PIN 6
#define MODEM_DTR_PIN 5
#define MODEM_RI_PIN 1
#define MODEM_PWRKEY_PIN 3

#define GPS_RX_PIN 39
#define GPS_TX_PIN 42

#define LED_PIN 38

#else
#error "Use ArduinoIDE, please open the macro definition corresponding to the board above <utilities.h>"
#endif









Loading

0 comments on commit d208084

Please sign in to comment.