first-beta1

This commit is contained in:
richonguzman 2023-02-10 07:56:22 -03:00
parent 62b7fb961d
commit ad0203e106
9 changed files with 286 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

10
.vscode/extensions.json vendored Normal file
View file

@ -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"
]
}

39
include/README Normal file
View file

@ -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

46
lib/README Normal file
View file

@ -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 <Foo.h>
#include <Bar.h>
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

19
platformio.ini Normal file
View file

@ -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

143
src/Lora_APRS_iGate_DIY.cpp Normal file
View file

@ -0,0 +1,143 @@
#include <SPI.h>
#include <LoRa.h>
#include <WiFi.h>
#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);
}
}

13
src/iGate_config.h Normal file
View file

@ -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

11
test/README Normal file
View file

@ -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