From ad0203e106be6ed42e860b59dd06cfc52c769d1d Mon Sep 17 00:00:00 2001 From: richonguzman Date: Fri, 10 Feb 2023 07:56:22 -0300 Subject: [PATCH] first-beta1 --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 5 ++ .vscode/extensions.json | 10 +++ include/README | 39 ++++++++++ lib/README | 46 ++++++++++++ platformio.ini | 19 +++++ src/Lora_APRS_iGate_DIY.cpp | 143 ++++++++++++++++++++++++++++++++++++ src/iGate_config.h | 13 ++++ test/README | 11 +++ 9 files changed, 286 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 include/README create mode 100644 lib/README create mode 100644 platformio.ini create mode 100644 src/Lora_APRS_iGate_DIY.cpp create mode 100644 src/iGate_config.h create mode 100644 test/README diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3a00a3ae49457b242a3ad0b91fa6d12e40d10ede GIT binary patch literal 6148 zcmeHKy-ve05I(m7DiBhI7#JAx1c*+op$bn>u_DwTl|ndcKLX&g8EX%oK6!zg~be}6mntfWUx ze;vU#)?p(q|LteapGRlB#ppu55e=#3^X(*>Pe)w7qr3g@Q=@sAY;?v~jQV_sm=y1M zOdaITz30-p8*@27zVc_xb6s^8#eH6`D`G3E0BSZ{Wy_%SqJStM3gim#{t%)uMiw)J zdh0-^j{v{`Zf&^MdpOe)Z%Dtp9GCLR9Jj*Bd222DCC&5U_0v$7`? zWh;&f^>9*=LFq*SQNUNAY;LPu|4){m|NSJn69q(pf2Dv5;znG@BiY(ocsQ=LA=)__ p8;{Ej>J)Ug9P0}%#d~Pl5DWPN7+K5=!UK~Z0WE`cqQIXj@B_ZnpRE7@ literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,10 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/include/README b/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..6debab1 --- /dev/null +++ b/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..f75fbe2 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,19 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 +lib_deps = + sandeepmistry/LoRa@^0.8.0 +platform_packages = + platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git \ No newline at end of file diff --git a/src/Lora_APRS_iGate_DIY.cpp b/src/Lora_APRS_iGate_DIY.cpp new file mode 100644 index 0000000..efdd215 --- /dev/null +++ b/src/Lora_APRS_iGate_DIY.cpp @@ -0,0 +1,143 @@ +#include +#include +#include +#include "iGate_config.h" + + +#define DBM 20 //20 serian 100mW # con otro mas potente serian 8=100mA y 20=1000W(1W) + +// SPI LoRa Radio +#define LORA_SCK 5 // GPIO5 - SX1276 SCK +#define LORA_MISO 19 // GPIO19 - SX1276 MISO +#define LORA_MOSI 27 // GPIO27 - SX1276 MOSI +#define LORA_CS 18 // GPIO18 - SX1276 CS ---> NSS +#define LORA_RST 14 // GPIO14 - SX1276 RST +#define LORA_IRQ 26 // GPIO26 - SX1276 IRQ ---->DIO0 + + +WiFiClient espClient; +int status = WL_IDLE_STATUS; + +void setup_lora() { + Serial.println("Set LoRa pins!"); + SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); + LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ); + + long freq = 433775000; + Serial.print("frequency: "); + Serial.println(String(freq)); + if (!LoRa.begin(freq)) { + Serial.println("Starting LoRa failed!"); + while (true) { + } + } + LoRa.setSpreadingFactor(12); + LoRa.setSignalBandwidth(125000); + LoRa.setCodingRate4(5); + LoRa.enableCrc(); + LoRa.setTxPower(20); + Serial.println("LoRa init done!"); +} + +void setup_wifi() { + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + delay(100); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); + Serial.print("\nConnecting to '"); Serial.print(WIFI_SSID); Serial.println("' WiFi ..."); + while (WiFi.status() != WL_CONNECTED) { + Serial.print('.'); + delay(1000); + } + Serial.print("Connected as "); + Serial.println(WiFi.localIP()); +} + +void setup() { + Serial.begin(115200); + setup_wifi(); + btStop(); + setup_lora(); + + Serial.println(""); + Serial.println("Starting iGate\n"); +} + +void procesa_y_sube_APRS_IS(String mensaje) { + String packet_para_APRS_IS = ""; + String callsign_y_path_tracker = ""; + String gps_info_tracker; + + int posicion_dos_puntos = mensaje.indexOf(':'); + callsign_y_path_tracker = mensaje.substring(3, posicion_dos_puntos); + gps_info_tracker = mensaje.substring(posicion_dos_puntos); + packet_para_APRS_IS = callsign_y_path_tracker + ",qAO," + callsign_igate + gps_info_tracker + "\n"; + //Serial.print("Mensaje APRS_IS : "); + //Serial.println(packet_para_APRS_IS); + //packet = "CD2RXU-9>APLT00,qAO,CD2RXU-10:=" + LAT + "/" + LON + ">" + "\n"; + + delay(200); + int count = 0; + String aprsauth; + Serial.println("Conectando a APRS-IS"); + while (!espClient.connect(SERVER.c_str(), APRSPORT) && count < 20) { + Serial.println("Didn't connect with server: " + String(SERVER) + " APRSPORT: " + String(APRSPORT)); + delay(1000); + espClient.stop(); + espClient.flush(); + Serial.println("Run client.stop"); + Serial.println("Trying to connect with server: " + String(SERVER) + " APRSPORT: " + String(APRSPORT)); + count++; + Serial.println("Try: " + String(count)); + } + if (count == 20) { + Serial.println("Tried: " + String(count) + " don't send the packet!"); + } else { + Serial.println("Connected with server: " + String(SERVER) + " APRSPORT: " + String(APRSPORT)); + while (espClient.connected()) { + delay(1000); + //Serial.println("Run client.connected()"); + + //aprsauth = "user " + USER + " pass " + PAS + "\n"; + aprsauth = "user " + callsign_igate + " pass " + passcode_igate + "\n"; //info igate + espClient.write(aprsauth.c_str()); + delay(500); + //Serial.println("Send client.write=" + aprsauth); + + espClient.write(packet_para_APRS_IS.c_str()); + delay(500); + //Serial.println("Send espClient.write = " + packet_para_APRS_IS); + Serial.println("Packet uploaded =)\n"); + espClient.stop(); + espClient.flush(); + //Serial.println("(Telnet client disconnect)\n"); + } + } +} + +void valida_y_procesa_packet(String mensaje) { + String packetStart = ""; + Serial.print("MENSAJE RECIBIDO!!! "); + Serial.print("(Validando inicio ---> "); + packetStart = mensaje.substring(0, 3); + if (packetStart == "\x3c\xff\x01") { + Serial.println("Packet Valido)"); + procesa_y_sube_APRS_IS(mensaje); + } else { + Serial.println("Packet NO Valido)"); + } +} + +void loop() { + String mensaje_recibido = ""; + bool valida_inicio; + int packetSize = LoRa.parsePacket(); + if (packetSize) { + while (LoRa.available()) { + int inChar = LoRa.read(); + mensaje_recibido += (char)inChar; + } + //Serial.println("Mensaje Recibido : " + String(mensaje_recibido)); + valida_y_procesa_packet(mensaje_recibido); + } +} \ No newline at end of file diff --git a/src/iGate_config.h b/src/iGate_config.h new file mode 100644 index 0000000..5f73a92 --- /dev/null +++ b/src/iGate_config.h @@ -0,0 +1,13 @@ +#ifndef IGATE_CONFIG_H_ +#define IGATE_CONFIG_H_ + +#define WIFI_SSID "Richon" +#define WIFI_PASSWORD "k4fPnmg5qnyf" + +String callsign_igate = "CD2RXU-10"; +String passcode_igate = "23201"; + +const String SERVER = "brazil.aprs2.net"; // write the address of the aprs server +const int APRSPORT = 14579; // write the aprs server APRSPORT + +#endif \ No newline at end of file diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Test Runner and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html