From a7e83d8220b73b1f4576ff94eed0ecd7b1962840 Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Mon, 19 Aug 2024 07:40:52 -1000 Subject: [PATCH] 9_1: Add example 9_1_PPP_Google for Arduino v3 --- .../9_1_PPP_Google/9_1_PPP_Google.ino | 156 ++++++++++++++++++ Example_Sketches/9_1_PPP_Google/makefile | 137 +++++++++++++++ 2 files changed, 293 insertions(+) create mode 100644 Example_Sketches/9_1_PPP_Google/9_1_PPP_Google.ino create mode 100644 Example_Sketches/9_1_PPP_Google/makefile diff --git a/Example_Sketches/9_1_PPP_Google/9_1_PPP_Google.ino b/Example_Sketches/9_1_PPP_Google/9_1_PPP_Google.ino new file mode 100644 index 0000000..bfccf14 --- /dev/null +++ b/Example_Sketches/9_1_PPP_Google/9_1_PPP_Google.ino @@ -0,0 +1,156 @@ +#include + +#define PPP_MODEM_APN "internet" +#define PPP_MODEM_PIN NULL // Personal Identification Number: String in double quotes + +// Power control +#define PWREN 32 + +// LARA pins +#define LARA_RST 26 // Using the power pin as reset +#define LARA_TX 13 +#define LARA_RX 14 +#define LARA_RTS -1 +#define LARA_CTS -1 + +// LARA R6001D no flow control +#define PPP_MODEM_RST_LOW false //active HIGH +#define PPP_MODEM_FC ESP_MODEM_FLOW_CONTROL_NONE +#define PPP_MODEM_MODEL PPP_MODEM_GENERIC + +void onEvent(arduino_event_id_t event, arduino_event_info_t info) +{ + IPAddress ipv4; + + 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: + ipv4 = PPP.localIP(); + Serial.print("PPP Got IP: "); + Serial.print(ipv4); + Serial.println(); + 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; + static bool suppressOutput = false; + if (!client.connect(host, port)) + { + Serial.printf("Connection to %s:%d failed!\r\n", host, port); + return; + } + client.printf("GET / HTTP/1.1\r\nHost: %s\r\n\r\n", host); + while (client.connected() && !client.available()); + Serial.printf("Connection to %s:%d successful\r\n", host, port); + int bytesRead = 0; + while (client.available()) + { + client.read(); + if (!suppressOutput) + Serial.write(client.read()); + bytesRead += 1; + } + if (!suppressOutput) + Serial.println(); + suppressOutput = true; + + Serial.printf("Read %d bytes from %s\r\n", bytesRead, host); + 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(LARA_RST, PPP_MODEM_RST_LOW); + PPP.setPins(LARA_TX, LARA_RX, LARA_RTS, LARA_CTS, PPP_MODEM_FC); + + // Now enable the 3.3V regulators for the GNSS and LARA + pinMode(PWREN, OUTPUT); + digitalWrite(PWREN, HIGH); + + 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("google.com", 80); + } + delay(20000); +} diff --git a/Example_Sketches/9_1_PPP_Google/makefile b/Example_Sketches/9_1_PPP_Google/makefile new file mode 100644 index 0000000..6e6a9ef --- /dev/null +++ b/Example_Sketches/9_1_PPP_Google/makefile @@ -0,0 +1,137 @@ +###################################################################### +# makefile +# +# Builds the example +###################################################################### + +########## +# Source files +########## + +EXAMPLE_SKETCH=9_1_PPP_Google + +EXECUTABLES += example + +PARTITION_CSV_FILE=RTKEverywhere + +ifeq ($(OS),Windows_NT) +# Windows NT utilities +CLEAR=cls +COPY=copy +DELETE=rmdir /s +DIR_LISTING=dir +TERMINAL_APP= +TERMINAL_PARAMS= + +# Windows NT generic paths +USER_DIRECTORY_PATH=C:\Users\$(USERNAME) +ARDUINO_LIBRARY_PATH=$(USER_DIRECTORY_PATH)\Documents\Arduino\libraries +HOME_BOARD_PATH=$(USER_DIRECTORY_PATH)\AppData\Local\Arduino15\packages\esp32 +PATCH_SRC_PATH=Patch\ + +# Windows NT patch source paths +PARTITION_SRC_PATH=..\$(PARTITION_CSV_FILE).csv +PATCH_SRC_PATH=Patch\ + +# Windows NT patch destination paths +BLE_PATCH_DST_PATH=$(ARDUINO_LIBRARY_PATH)\ESP32_BleSerial\src\ +MBED_LIB_DEST_PATH=$(HOME_BOARD_PATH)\tools\esp32-arduino-libs\${{ env.ESP_IDF }}\esp32/lib\ +PARTITION_DST_PATH=$(HOME_BOARD_PATH)\hardware\esp32\$(ESP_CORE_VERSION)\tools\partitions\$(PARTITION_CSV_FILE).csv + +else +# Linux utilities +CLEAR=clear +COPY=cp +DELETE=rm -Rf +DIR_LISTING=ls +TERMINAL_APP=minicom +TERMINAL_PARAMS=-b 115200 -8 -D /dev/ttyUSB0 < /dev/tty + +# Linux generic paths +USER_DIRECTORY_PATH=~ +ARDUINO_LIBRARY_PATH=$(USER_DIRECTORY_PATH)/Arduino/libraries +ESP_IDF_PATH=$(HOME_BOARD_PATH)/tools/esp32-arduino-libs +HOME_BOARD_PATH=$(USER_DIRECTORY_PATH)/.arduino15/packages/esp32 + +# Linux patch source paths +PARTITION_SRC_PATH=../$(PARTITION_CSV_FILE).csv +PATCH_SRC_PATH=Patch/ + +# Linux patch destination paths +BLE_PATCH_DST_PATH=$(ARDUINO_LIBRARY_PATH)/ESP32_BleSerial/src/ +MBED_LIB_DEST_PATH=$(ESP_IDF_PATH)/$(ESP_IDF_VERSION)/esp32/lib/ +PARTITION_DST_PATH=$(HOME_BOARD_PATH)/hardware/esp32/$(ESP_CORE_VERSION)/tools/partitions/$(PARTITION_CSV_FILE).csv + +endif + +########## +# Buid all the sources - must be first +########## + +.PHONY: all + +all: $(EXECUTABLES) + +########## +# Add ESP32 board support +########## + +.PHONY: arduino-config + +arduino-config: + arduino-cli config init --overwrite --additional-urls "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json,https://espressif.github.io/arduino-esp32/package_esp32_dev_index.json" + +########## +# Build an example +########## + +.PHONY: example + +example: build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin + +DEBUG_LEVEL=none +#DEBUG_LEVEL=debug + +build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin: $(EXAMPLE_SKETCH).ino makefile + $(CLEAR) + arduino-cli compile --fqbn "esp32:esp32:esp32":DebugLevel=$(DEBUG_LEVEL),PSRAM=enabled $< \ + --warnings default \ + --build-property build.partitions=$(PARTITION_CSV_FILE) \ + --build-property upload.maximum_size=6291456 \ + --build-property "compiler.cpp.extra_flags=-MMD -c \"-DPOINTPERFECT_TOKEN=$(POINTPERFECT_TOKEN)\" \"-DFIRMWARE_VERSION_MAJOR=$(FIRMWARE_VERSION_MAJOR)\" \"-DFIRMWARE_VERSION_MINOR=$(FIRMWARE_VERSION_MINOR)\" \"-DENABLE_DEVELOPER=$(ENABLE_DEVELOPER)\"" \ + --export-binaries + +########## +# Upload the example +########## + +ESPTOOL_PATH=~/Arduino/hardware/espressif/esp32/tools/esptool +TERMINAL_PORT="/dev/ttyUSB0" +BOOT_LOADER_PATH=~/SparkFun/SparkFun_RTK_Firmware_Uploader/RTK_Firmware_Uploader/resource + +.PHONY: upload + +upload: build/esp32.esp32.esp32/$(EXAMPLE_SKETCH).ino.bin + python3 $(ESPTOOL_PATH)/esptool.py \ + --chip esp32 \ + --port $(TERMINAL_PORT) \ + --baud 921600 \ + --before default_reset \ + --after hard_reset \ + write_flash \ + --flash_mode dio \ + --flash_freq 80m \ + --flash_size detect \ + --compress \ + 0x1000 $(BOOT_LOADER_PATH)/RTK_Surveyor.ino.bootloader.bin \ + 0x8000 $(BOOT_LOADER_PATH)/RTK_Surveyor_Partitions_16MB.bin \ + 0xe000 $(BOOT_LOADER_PATH)/boot_app0.bin \ + 0x10000 $< + $(TERMINAL_APP) $(TERMINAL_PARAMS) + +########## +# Clean up the example +########## + +clean: + $(DELETE) build