Added SD card support and started Lora support

This commit is contained in:
Dionysus 2024-06-05 20:04:40 -04:00
parent 4b4be4c9db
commit 68b86a1d6d
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
4 changed files with 131 additions and 1 deletions

76
src/apps/LoRa.cpp Normal file
View File

@ -0,0 +1,76 @@
#include <RadioLib.h>
#include "pins.h"
SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
bool setupRadio() {
digitalWrite(BOARD_SDCARD_CS, HIGH);
digitalWrite(RADIO_CS_PIN, HIGH);
digitalWrite(BOARD_TFT_CS, HIGH);
SPI.end();
SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD
int state = radio.begin(RADIO_FREQ);
if (state == RADIOLIB_ERR_NONE) {
Serial.println("Start Radio success!");
} else {
Serial.print("Start Radio failed,code:");
Serial.println(state);
return false;
}
if (radio.setFrequency(RADIO_FREQ) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("Selected frequency is invalid for this module!"));
return false;
}
if (radio.setBandwidth(125.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
Serial.println(F("Selected bandwidth is invalid for this module!"));
return false;
}
if (radio.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
Serial.println(F("Selected spreading factor is invalid for this module!"));
return false;
}
if (radio.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
Serial.println(F("Selected coding rate is invalid for this module!"));
return false;
}
if (radio.setSyncWord(0xAB) != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to set sync word!"));
return false;
}
// set output power to 10 dBm (accepted range is -17 - 22 dBm)
if (radio.setOutputPower(17) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("Selected output power is invalid for this module!"));
return false;
}
// set over current protection limit to 140 mA (accepted range is 45 - 140 mA) (set value to 0 to disable overcurrent protection)
if (radio.setCurrentLimit(140) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) {
Serial.println(F("Selected current limit is invalid for this module!"));
return false;
}
// set LoRa preamble length to 15 symbols (accepted range is 0 - 65535)
if (radio.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
return false;
}
if (radio.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
Serial.println(F("Selected CRC is invalid for this module!"));
return false;
}
// set the function that will be called when new packet is received
//radio.setDio1Action(setFlag);
return true;
}

42
src/apps/gotify.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <ArduinoWebsockets.h>
using namespace websockets;
WebsocketsClient gotifyClient;
const char* gotify_server = "ws://your.gotify.server.com/stream"; // Use ws:// or wss:// based on your server configuration
const char* gotify_token = "your_gotify_app_token";
// Reconnection parameters
unsigned long lastAttemptTime = 0;
const unsigned long reconnectInterval = 60000; // 1 minute
void onMessageCallback(WebsocketsMessage message) {
Serial.println("Gotify Notification:");
Serial.println(message.data());
}
void connectToGotify() {
String url = String(gotify_server) + "?token=" + gotify_token;
gotifyClient.onMessage(onMessageCallback);
gotifyClient.connect(url);
if (gotifyClient.available()) {
Serial.println("Connected to Gotify WebSocket");
} else {
Serial.println("Failed to connect to Gotify WebSocket");
}
}
void checkGotifyWebSocket() {
if (!gotifyClient.available()) {
unsigned long currentTime = millis();
if (currentTime - lastAttemptTime > reconnectInterval) {
Serial.println("Attempting to reconnect to Gotify WebSocket...");
lastAttemptTime = currentTime;
connectToGotify();
}
} else {
gotifyClient.poll();
}
}

View File

@ -136,6 +136,16 @@ void setup() {
digitalWrite(TFT_BL, HIGH);
setBrightness(8); // Set the screen brightness to 50%
// Give power to the SD card
pinMode(BOARD_SDCARD_CS, OUTPUT);
digitalWrite(BOARD_SDCARD_CS, HIGH);
pinMode(BOARD_SPI_MISO, INPUT_PULLUP);
SPI.begin(BOARD_SPI_SCK, BOARD_SPI_MISO, BOARD_SPI_MOSI); //SD
// Turn on power to the radio
pinMode(RADIO_CS_PIN, OUTPUT);
digitalWrite(RADIO_CS_PIN, HIGH);
// Start the I2C bus for the keyboard
Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL);

View File

@ -58,4 +58,6 @@
#define CONV_FACTOR 1.8 // Conversion factor for the ADC to voltage conversion
#define READS 20 // Number of readings for averaging
#define LILYGO_KB_SLAVE_ADDRESS 0x55
#define LILYGO_KB_SLAVE_ADDRESS 0x55
#define RADIO_FREQ 903.0