sforkowany z mirror/meshtastic-firmware
add beginnings of mesh radio
rodzic
cdb7153071
commit
2529189a08
|
@ -16,13 +16,13 @@ board = ttgo-t-beam
|
|||
framework = arduino
|
||||
|
||||
; note: we add src to our include search path so that lmic_project_config can override
|
||||
build_flags = -Wall -Wextra -Wno-missing-field-initializers -O3 -Wl,-Map,.pio/build/esp32/output.map -D CFG_us915 -D CFG_sx1276_radio
|
||||
build_flags = -Wall -Wextra -Wno-missing-field-initializers -O3 -Wl,-Map,.pio/build/esp32/output.map
|
||||
; -DLOG_LOCAL_LEVEL=ESP_LOG_DEBUG -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
|
||||
|
||||
monitor_speed = 115200
|
||||
|
||||
lib_deps =
|
||||
https://github.com/mcci-catena/arduino-lmic
|
||||
RadioHead
|
||||
TinyGPSPlus
|
||||
ESP8266_SSD1306
|
||||
AXP202X_Library
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
#include <SPI.h>
|
||||
#include <RH_RF95.h>
|
||||
|
||||
#include "MeshRadio.h"
|
||||
#include "configuration.h"
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_RF95 rf95(NSS_GPIO, DIO0_GPIO);
|
||||
|
||||
// Change to 434.0 or other frequency, must match RX's freq!
|
||||
#define RF95_FREQ 915.0
|
||||
|
||||
|
||||
void mesh_init() {
|
||||
pinMode(RESET_GPIO, OUTPUT);
|
||||
digitalWrite(RESET_GPIO, HIGH);
|
||||
|
||||
|
||||
// manual reset
|
||||
digitalWrite(RESET_GPIO, LOW);
|
||||
delay(10);
|
||||
digitalWrite(RESET_GPIO, HIGH);
|
||||
delay(10);
|
||||
|
||||
while (!rf95.init()) {
|
||||
Serial.println("LoRa radio init failed");
|
||||
Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("LoRa radio init OK!");
|
||||
|
||||
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
|
||||
if (!rf95.setFrequency(RF95_FREQ)) {
|
||||
Serial.println("setFrequency failed");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
|
||||
|
||||
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
|
||||
|
||||
// The default transmitter power is 13dBm, using PA_BOOST.
|
||||
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
|
||||
// you can set transmitter powers from 5 to 23 dBm:
|
||||
rf95.setTxPower(23, false);
|
||||
}
|
||||
|
||||
|
||||
int16_t packetnum = 0; // packet counter, we increment per xmission
|
||||
|
||||
void mesh_loop()
|
||||
{
|
||||
delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
|
||||
Serial.println("Transmitting..."); // Send a message to rf95_server
|
||||
|
||||
char radiopacket[20] = "Hello World # ";
|
||||
itoa(packetnum++, radiopacket+13, 10);
|
||||
Serial.print("Sending "); Serial.println(radiopacket);
|
||||
radiopacket[19] = 0;
|
||||
|
||||
Serial.println("Sending...");
|
||||
delay(10);
|
||||
rf95.send((uint8_t *)radiopacket, 20);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
void mesh_init();
|
||||
void mesh_loop();
|
|
@ -25,34 +25,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <lmic.h>
|
||||
void ttn_register(void (*callback)(uint8_t message));
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Version
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define APP_NAME "TTN MAP-TRACK"
|
||||
#define APP_VERSION "1.1.0"
|
||||
#define APP_NAME "meshtastic-esp32"
|
||||
#define APP_VERSION "0.0.1"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Configuration
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Select which T-Beam board is being used. Only uncomment one.
|
||||
// #define T_BEAM_V07 // AKA Rev0 (first board released)
|
||||
#define T_BEAM_V10 // AKA Rev1 (second board released)
|
||||
|
||||
// Select the payload format. Change on TTN as well. Only uncomment one.
|
||||
#define PAYLOAD_USE_FULL
|
||||
// #define PAYLOAD_USE_CAYENNE
|
||||
|
||||
// If using a single-channel gateway, uncomment this next option and set to your gateway's channel
|
||||
//#define SINGLE_CHANNEL_GATEWAY 0
|
||||
|
||||
// If you are having difficulty sending messages to TTN after the first successful send,
|
||||
// uncomment the next option and experiment with values (~ 1 - 5)
|
||||
//#define CLOCK_ERROR 5
|
||||
|
||||
#define DEBUG_PORT Serial // Serial debug port
|
||||
#define SERIAL_BAUD 115200 // Serial debug baud rate
|
||||
|
@ -60,10 +46,6 @@ void ttn_register(void (*callback)(uint8_t message));
|
|||
#define SEND_INTERVAL (5 * 60 * 1000) // Sleep for these many millis
|
||||
#define MESSAGE_TO_SLEEP_DELAY 5000 // Time after message before going to sleep
|
||||
#define LOGO_DELAY 5000 // Time to show logo on first boot
|
||||
#define LORAWAN_PORT 10 // Port the messages will be sent to
|
||||
#define LORAWAN_CONFIRMED_EVERY 0 // Send confirmed message every these many messages (0 means never)
|
||||
#define LORAWAN_SF DR_SF10 // Spreading factor (recommended DR_SF7 for ttn network map purposes, DR_SF10 works for slow moving trackers)
|
||||
#define LORAWAN_ADR 0 // Enable ADR
|
||||
#define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found
|
||||
|
||||
// If not defined, we will wait for lock forever
|
||||
|
@ -95,10 +77,7 @@ void ttn_register(void (*callback)(uint8_t message));
|
|||
#define I2C_SDA 21
|
||||
#define I2C_SCL 22
|
||||
|
||||
#if defined(T_BEAM_V07)
|
||||
#define LED_PIN 14
|
||||
#define BUTTON_PIN 39
|
||||
#elif defined(T_BEAM_V10)
|
||||
#if defined(T_BEAM_V10)
|
||||
#define BUTTON_PIN 38
|
||||
#endif
|
||||
|
||||
|
@ -116,10 +95,7 @@ void ttn_register(void (*callback)(uint8_t message));
|
|||
#define GPS_BAUDRATE 9600
|
||||
#define USE_GPS 1
|
||||
|
||||
#if defined(T_BEAM_V07)
|
||||
#define GPS_RX_PIN 12
|
||||
#define GPS_TX_PIN 15
|
||||
#elif defined(T_BEAM_V10)
|
||||
#if defined(T_BEAM_V10)
|
||||
#define GPS_RX_PIN 34
|
||||
#define GPS_TX_PIN 12
|
||||
#endif
|
||||
|
@ -134,8 +110,6 @@ void ttn_register(void (*callback)(uint8_t message));
|
|||
#define NSS_GPIO 18
|
||||
#if defined(T_BEAM_V10)
|
||||
#define RESET_GPIO 14
|
||||
#else
|
||||
#define RESET_GPIO 23
|
||||
#endif
|
||||
#define DIO0_GPIO 26
|
||||
#define DIO1_GPIO 33 // Note: not really used on this board
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// This sketch supports EU868 and US915
|
||||
|
||||
// The Arduino-LMIC library by MCCI Catena is set to US915,
|
||||
// these settings have to be copied over the ones in the
|
||||
// lmic_project_config.h file in the library,
|
||||
// inside the project_config folder.
|
||||
|
||||
// Make sure only one of the following is defined (CFG_us915 or CFG_eu868)
|
||||
#define CFG_us915 1
|
||||
//#define CFG_eu868 1
|
||||
|
||||
// DO NOT modify this
|
||||
#define CFG_sx1276_radio 1
|
15
src/main.ino
15
src/main.ino
|
@ -26,6 +26,7 @@
|
|||
#include <TinyGPS++.h>
|
||||
#include <Wire.h>
|
||||
#include "BluetoothUtil.h"
|
||||
#include "MeshRadio.h"
|
||||
|
||||
#ifdef T_BEAM_V10
|
||||
#include "axp20x.h"
|
||||
|
@ -39,14 +40,6 @@ bool axp192_found = false;
|
|||
|
||||
bool packetSent, packetQueued;
|
||||
|
||||
#if defined(PAYLOAD_USE_FULL)
|
||||
// includes number of satellites and accuracy
|
||||
static uint8_t txBuffer[10];
|
||||
#elif defined(PAYLOAD_USE_CAYENNE)
|
||||
// CAYENNE DF
|
||||
static uint8_t txBuffer[11] = {0x03, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
#endif
|
||||
|
||||
// deep sleep support
|
||||
RTC_DATA_ATTR int bootCount = 0;
|
||||
esp_sleep_source_t wakeCause; // the reason we booted this time
|
||||
|
@ -63,7 +56,8 @@ void doDeepSleep(uint64_t msecToWake)
|
|||
// esp_wifi_stop();
|
||||
|
||||
screen_off(); // datasheet says this will draw only 10ua
|
||||
LMIC_shutdown(); // cleanly shutdown the radio
|
||||
|
||||
// FIXME, shutdown radio headinterups before powering off device
|
||||
|
||||
if(axp192_found) {
|
||||
// turn on after initial testing with real hardware
|
||||
|
@ -271,11 +265,14 @@ void setup() {
|
|||
}
|
||||
|
||||
initBLE("KHBT Test"); // FIXME, use a real name based on the macaddr
|
||||
|
||||
mesh_init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
gps_loop();
|
||||
screen_loop();
|
||||
mesh_loop();
|
||||
loopBLE();
|
||||
|
||||
if(packetSent) {
|
||||
|
|
Ładowanie…
Reference in New Issue