Hello everyone, I need to communicate 3 Arduino nanos wirelessly. 1st and 2nd arduinos will communicate with ESP-01, 2nd and 3rd arduinos will communicate with LoRa E32433T20D. My problem occurs at this point. " On the 2nd Arduino, both ESP-01 and LoRa E32433T20D do not work at the same time. ESP-01 does not respond to AT commands while LoRa E32433T20D is transferring data. I am trying to run both modules via SoftwareSerial. I would be very happy if someone who has worked on this subject before can help.
Which doesn't fully support multiple ports. Read the documentation.
Using more than one SoftwareSerial is not recommended.
You can use SoftwareSerial on the one port and HardwareSerial on the another. But it would be better take the board with more than one Serial port instead of Nano - for example Mega or Nano Every
why not use devices with Built in WiFi such as ESP8266 devices or even ESP32 - the ESP32 supports hardware serial for communication with the Lora device
Can I use Arduino Nano iot 33? Does it support LoRa module?
#include <WiFiEsp.h> // Esp8266 WiFi kütüphane
#include <Servo.h> // Servo kütüphane
#include <SoftwareSerial.h> // Seri haberleşme kütüphane
#ifndef HAVE_HWesp
#include "SoftwareSerial.h"
SoftwareSerial esp(2, 3); // Esp seri port Rx Tx
#endif
SoftwareSerial e32(10, 11); // LoRa seri port Rx Tx
char ssid[] = "*******"; // WiFi Ağ adı
char pass[] = "******"; // WiFi Ağ şifresi
int status = WL_IDLE_STATUS;
#define M0 6 // LoRa M0 pin
#define M1 7 // LoRa M1 pin
#define Istasyon1_Read_Rl A1 // Read röle 1
#define Istasyon2_Read_Rl A2 // Read röle 2
#define Istasyon3_Read_Rl A3 // Read röle 3
#define Ist1_Kapi_Servo 5 // Ist1 kapi servo pin
#define Ist2_Kapi_Servo 8 // Ist2 kapi servo pin
#define Ist3_Kapi_Servo 9 // Ist3 kapi servo pin
#define servo_ac 90 // Servo 90 dereceye ayarla
#define servo_kapa 0 // Servo 0 dereceye ayarla
#define servo_bklm_zamani_ac 255000 // Servo açık bekleme süresi
#define servo_bklm_zamani_kpt 15000 // Servo kapalı beklme süresi
#define servo_ac_ledi 12 // Servo açıksa yeşil led yakmak
#define servo_kpt_ledi 13 // Servo kapalıysa kırmızı led yakmak
#define buflen [6]
uint8_t Komut_Var = 0;
uint8_t Serial_Sira = 0;
uint8_t Lora_Cmd_Buf[10];
uint16_t Lora_Giden_Sayac = 0;
int Switch_On = 0;
int Servo1_Ac = 0;
int Servo2_Ac = 0;
int Servo3_Ac = 0;
int Servo1_Ac_bir = 0;
int Servo2_Ac_bir = 0;
int Servo3_Ac_bir = 0;
int servo1_adim = 0;
int servo2_adim = 0;
int servo3_adim = 0;
unsigned long servo1_bekleme_onceki = 0;
unsigned long servo1_bekleme = 0;
unsigned long servo2_bekleme_onceki = 0;
unsigned long servo2_bekleme = 0;
unsigned long servo3_bekleme_onceki = 0;
unsigned long servo3_bekleme = 0;
unsigned int Test_Sayac = 0;
unsigned int Test_Sayac_Zaman_L = 0;
unsigned int Test_Sayac_Zaman_H = 0;
Servo Servo1; // Ist1 servo
Servo Servo2; // Ist2 servo
Servo Servo3; // Ist3 servo
void setup() {
Serial.begin(115200); // PC seri port başlatma
delay(2000);
Serial.println("PC Serial hazır.");
esp.begin(9600); // Esp8266 seri port başlatma
delay(2000);
Serial.println("Esp Serial hazır.");
e32.begin(9600); // LoRa seri port başlatma
delay(2000);
Serial.println("Lora Serial hazır.");
Servo1.attach(Ist1_Kapi_Servo); // Servo1 pin atama
Servo2.attach(Ist2_Kapi_Servo); // Servo2 pin atama
Servo3.attach(Ist3_Kapi_Servo); // Servo3 pin atama
delay(2000); // 2s sistem beklemesi
// WiFi Bağlantı...
WiFi.init(&esp);
// ESP kontrol
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("ESP-01 mevcut değil.");
while (true)
;
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
}
Serial.println("Ağa bağlanıldı.");
Servo1.write(servo_ac);
Servo2.write(servo_ac);
Servo3.write(servo_ac);
delay(500);
Servo1.write(servo_kapa);
Servo2.write(servo_kapa);
Servo3.write(servo_kapa);
pinMode(Ist1_Kapi_Servo, OUTPUT);
pinMode(Ist2_Kapi_Servo, OUTPUT);
pinMode(Ist3_Kapi_Servo, OUTPUT);
Serial.println("System init...");
delay(250);
pinMode(servo_ac_ledi, OUTPUT);
pinMode(servo_kpt_ledi, OUTPUT);
pinMode(M0, OUTPUT);
pinMode(M1, OUTPUT);
delay(250);
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, LOW);
digitalWrite(Ist1_Kapi_Servo, LOW);
digitalWrite(Ist2_Kapi_Servo, LOW);
digitalWrite(Ist3_Kapi_Servo, LOW);
digitalWrite(M0, LOW);
digitalWrite(M1, LOW);
delay(250);
pinMode(Istasyon1_Read_Rl, INPUT_PULLUP);
pinMode(Istasyon2_Read_Rl, INPUT_PULLUP);
pinMode(Istasyon3_Read_Rl, INPUT_PULLUP);
Serial.println("Istasyon Hazır");
} // void(setup) satır sonu
// Rutin tanımları
void printWifiData() {
// WiFi IP adresi
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// MAC adresi
byte mac[6];
WiFi.macAddress(mac);
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void Test_Surekli_Gonder(void) { // LoRa data gönderme test rutini
Test_Sayac_Zaman_L++;
if (Test_Sayac_Zaman_L >= 100) {
Test_Sayac_Zaman_L = 0;
Test_Sayac_Zaman_H++;
if (Test_Sayac_Zaman_H >= 100) {
Test_Sayac_Zaman_H = 0;
Lora_Cmd_Buf[0] = 0x00;
Lora_Cmd_Buf[1] = 0x02;
Lora_Cmd_Buf[2] = 0x14;
Lora_Cmd_Buf[3] = 'T';
Lora_Cmd_Buf[4] = 'E';
Lora_Cmd_Buf[5] = 'S';
Lora_Cmd_Buf[6] = 'T';
Test_Sayac++;
Lora_Cmd_Buf[8] = Test_Sayac >> 8;
Lora_Cmd_Buf[9] = Test_Sayac & 0xFF;
e32.write(Lora_Cmd_Buf, sizeof(Lora_Cmd_Buf));
Serial.println((char *)Lora_Cmd_Buf);
Serial.println(sizeof(Lora_Cmd_Buf));
Serial.println("Seri Data Gonderildi ");
}
}
}
void Serial_Data_Gonder(void) // Seri data okuma rutini
{
byte cmd1 = 0XC1;
Lora_Cmd_Buf[0] = 0x00;
Lora_Cmd_Buf[1] = 0x02;
Lora_Cmd_Buf[2] = 0x14;
Lora_Cmd_Buf[3] = 'A';
Lora_Cmd_Buf[4] = 'B';
Lora_Cmd_Buf[5] = 'C';
Lora_Cmd_Buf[6] = 'D';
Lora_Cmd_Buf[7] = 'E';
Lora_Cmd_Buf[8] = 'F';
Lora_Cmd_Buf[9] = 'G';
Lora_Giden_Sayac++;
Lora_Cmd_Buf[8] = Lora_Giden_Sayac >> 8;
Lora_Cmd_Buf[9] = Lora_Giden_Sayac & 0xFF;
e32.write(Lora_Cmd_Buf, sizeof(Lora_Cmd_Buf));
Serial.println((char *)Lora_Cmd_Buf);
Serial.println(sizeof(Lora_Cmd_Buf));
Serial.println("Seri Data Gönderildi.");
if ((e32.available() > 0)) {
Serial.print("-");
cmd1 = e32.read();
Serial_Sira++;
if (Serial_Sira >= 7) {
Serial_Sira = 0;
Komut_Var = 1;
}
}
}
// Komut kontrol rutini
void Komut_Kontrol(void) {
int val1 = 0;
int val2 = 0;
int val3 = 0;
val1 = digitalRead(Istasyon1_Read_Rl);
//if ((val1 == 0) && (Switch_On == 0))
if ((val1 == 0) && (Switch_On == 0)) {
Lora_Cmd_Buf[3] = 'I';
Lora_Cmd_Buf[4] = 'S';
Lora_Cmd_Buf[5] = 'T';
Lora_Cmd_Buf[6] = '1';
Komut_Var = 1;
Switch_On = 1;
Servo1_Ac = 1;
servo1_adim = 0;
Servo1_Ac_bir = 0;
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, LOW);
}
// 2. istasyon read relay oku
val2 = digitalRead(Istasyon2_Read_Rl);
if ((val2 == 0) && (Switch_On == 0)) {
Lora_Cmd_Buf[3] = 'I';
Lora_Cmd_Buf[4] = 'S';
Lora_Cmd_Buf[5] = 'T';
Lora_Cmd_Buf[6] = '2';
Komut_Var = 1;
Switch_On = 1;
Servo2_Ac = 1;
servo2_adim = 0;
Servo2_Ac_bir = 0;
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, LOW);
}
// 3. istasyon read relay oku
val3 = digitalRead(Istasyon3_Read_Rl);
if ((val3 == 0) && (Switch_On == 0)) {
Lora_Cmd_Buf[3] = 'I';
Lora_Cmd_Buf[4] = 'S';
Lora_Cmd_Buf[5] = 'T';
Lora_Cmd_Buf[6] = '3';
Komut_Var = 1;
Switch_On = 1;
Servo3_Ac = 1;
servo3_adim = 0;
Servo3_Ac_bir = 0;
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, LOW);
}
if ((val1 == 1) && (val2 == 1) && (val3 == 1)) {
Switch_On = 0;
}
}
// Servo motor kontrol rutini
void Servo_Kapi_Kontrol(void) {
if (Servo1_Ac == 1) {
if (servo1_adim == 0) {
if (Servo1_Ac_bir == 0) {
Servo1.write(90);
digitalWrite(servo_ac_ledi, HIGH);
digitalWrite(servo_kpt_ledi, LOW);
Serial.println("--------------------------");
Serial.println("Servo1 Açıldı.");
Servo1_Ac_bir = 1;
}
servo1_bekleme++; // = millis();
if (servo1_bekleme >= servo_bklm_zamani_ac) {
servo1_bekleme = 0;
servo1_adim = 1;
Servo1_Ac_bir = 0;
Serial.println("Servo1 açma süre doldu.");
}
}
if (servo1_adim == 1) {
if (Servo1_Ac_bir == 0) {
Servo1.write(0);
Servo1_Ac_bir = 1;
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, HIGH);
Serial.println("Servo1 Kapatıldı.");
}
servo1_bekleme++;
if (servo1_bekleme >= servo_bklm_zamani_kpt) {
Serial.println("Servo1 kapama süre doldu.");
servo1_bekleme = 0;
servo1_adim = 0;
Servo1_Ac = 0;
}
}
} // servo1 ac sonu
if (Servo2_Ac == 1) {
if (servo2_adim == 0) {
if (Servo2_Ac_bir == 0) {
Servo2.write(90);
digitalWrite(servo_ac_ledi, HIGH);
digitalWrite(servo_kpt_ledi, LOW);
Serial.println("--------------------------");
Serial.println("Servo2 Açıldı.");
Servo2_Ac_bir = 1;
}
servo2_bekleme++;
if (servo2_bekleme >= servo_bklm_zamani_ac) {
servo2_bekleme = 0;
servo2_adim = 1;
Servo2_Ac_bir = 0;
Serial.println("Servo2 açma süre doldu.");
}
}
if (servo2_adim == 1) {
if (Servo2_Ac_bir == 0) {
Servo2.write(0);
Servo2_Ac_bir = 1;
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, HIGH);
Serial.println("Servo2 Kapatıldı");
}
servo2_bekleme++;
if (servo2_bekleme >= servo_bklm_zamani_kpt) {
Serial.println("Servo2 kapama süre doldu.");
servo2_bekleme = 0;
servo2_adim = 0;
Servo2_Ac = 0;
}
}
} // servo2 ac sonu
if (Servo3_Ac == 1) {
if (servo3_adim == 0) {
if (Servo3_Ac_bir == 0) {
Servo3.write(90);
digitalWrite(servo_ac_ledi, HIGH);
digitalWrite(servo_kpt_ledi, LOW);
Serial.println("--------------------------");
Serial.println("Servo3 Açıldı.");
Servo3_Ac_bir = 1;
}
servo3_bekleme++;
if (servo3_bekleme >= servo_bklm_zamani_ac) {
servo3_bekleme = 0;
servo3_adim = 1;
Servo3_Ac_bir = 0;
Serial.println("Servo3 açma süre doldu");
}
}
if (servo3_adim == 1) {
if (Servo3_Ac_bir == 0) {
Servo3.write(0);
Servo3_Ac_bir = 1;
digitalWrite(servo_ac_ledi, LOW);
digitalWrite(servo_kpt_ledi, HIGH);
Serial.println("Servo3 Kapatıldı");
}
servo3_bekleme++;
if (servo3_bekleme >= servo_bklm_zamani_kpt) {
Serial.println("Servo3 kapama süre doldu.");
servo3_bekleme = 0;
servo3_adim = 0;
Servo3_Ac = 0;
}
}
} // servo3 ac sonu
} // Servo motor kontrol rutini sonu
void loop() {
Test_Surekli_Gonder();
if (Komut_Var == 1) {
Serial_Data_Gonder();
Komut_Var = 0;
}
Komut_Kontrol();
Servo_Kapi_Kontrol();
}
Where's my mistake here? @b707
Nano iot 33 has hardware serial ports you could use to communicate with a lora module which uses serial communications
Using two SoftSerial:
as stated in post 8 the Nano 33 IOT RX0 and TX1 pins are a second serial port available as Serial1. port which can be connected to an external Lora device
as a test I used Microchip RN2483 which uses serial 57600baud to communicate with a host microcontroller
this was connected to the hardware serial port of a MKRFOX which uses the same SAMD21 processor as the Nano 33 IOT
the following program was run on the MKRFOX to communicate with the RN2483 lora device
// Arduino MKRFOX hardware serial1 port Serial1 on Tx pin 14 Rx pin 13
// on the MKRFOX Serial is used for USB communications and Serial1 is a hardware serial port on Tx pin 14 Rx pin 13
// NOTE: MKRFOX uses 3.3V logic
// - if commected to UNO 5V logic use a voltage divider 2.2K to ground 1K to UNO Tx
// MKRFOX pin 14 is TX
// MKRFOX pin 13 is Rx
// for loopback test connect pin 13 to pin 14
void setup() {
Serial.begin(115200); // initialise serial monitor port
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial1.begin(57600); // initialise Serial1
Serial.println();
Serial.write("Arduino MKRFOX Serial1 test - for loopback test connect pin 13 to pin 14\n");
}
void loop() {
if (Serial1.available()) // read from Serial1 output to Serial
Serial.write(Serial1.read());
if (Serial.available()) { // read from Serial outut to Serial1
int inByte = Serial.read();
Serial.write(inByte); // local echo if required
Serial1.write(inByte);
}
}
commands to the RN2483 could be typed into the MKRFOX serial monitor and responses from the remote RN2483 Lora device displayed, e.g. << added notes showing transmit and receive
Arduino MKRFOX Serial1 test - for loopback test connect pin 13 to pin 14
sys reset
RN2483 0.9.5 Mar 24 2015 14:15:33
radio set wdt 600000
ok
radio tx 12345678 << transmit to remote RN2483
ok
mac pause
4294967245
radio rx 0
ok
radio_rx 9876543210 << receive from remote RN2483
commands could be typed into the terminal connected to the remote RN2483 Lora device and responses displayed << added notes showing receive and transmit
RN2483 1.0.4 Oct 12 2017 14:59:25
radio set wdt 600000
ok
mac pause
4294967245
radio rx 0
ok
radio_rx 12345678 << receive for MKRFOX RN2483
mac pause
4294967245
radio tx 9876543210 << transmit to MKRFOX RN2483
ok
radio_tx_ok
Edit: you should therefore be able to connect the LoRa E32433T20D to the Nano 33 IOT Serial1 port similar to the above
Edit: an alternative would be to use a Lora device such as a Ra-02 which uses a SPI interface which is supported by the Nano 33 IOT
as stated in post 10 you should be able to connect the LoRa E32433T20D to the Nano 33 IOT Serial1 port and use SoftwareSerial for the ESP-01 - or vice versa
an alternative would be to use Serial1 port for the ESP-01 and a Lora device such as a RA-02 which uses SPI to connect with the Nano 33 IOT
the following uses an MKRFOX (same SAMD21 processor as the Nano 33 IOT) connected to a Lora/GPS HAT which has a RFM95W (with SX1276/SX1278 transceiver) which communicates with the host microcontrooller using SPI
tested with Examples>MCCI_LoRaWAN_LMIC_library>ttn-otaa-feather-us915 modified to use the MKRFOX pins (see code) and 868MHz frequency
// Examples>MCCI_LoRaWAN_LMIC_library>ttn-otaa-feather-us915
// Lora/GPS HAT connected to MKRFOX
// Lora hat 3.3v to MKRFOX VCC 3.3V
// Lora hat GND to MKRFOX GND
// Lora hat MOSI to MKRFOX MOSI pin 8
// Lora hat MISO to MKRFOX MISO pin 10
// Lora hat SCK to MKRFOX SCK pin 9
// Lora hat NSS to MKRFOX pin 6
// Lora hat DIO0 to MKRFOX pin 7
// Lora hat DIO1 to MKRFOX pin 11 (if version < 1.3 not connected)
// for 868MHz edit lmic_project_config.h to define
// #define CFG_eu868 1
// and add after LMIC_reset();
// LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
/*******************************************************************************
* Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
* Copyright (c) 2018 Terry Moore, MCCI
*
* Permission is hereby granted, free of charge, to anyone
* obtaining a copy of this document and accompanying files,
* to do whatever they want with them without any restriction,
* including, but not limited to, copying, modification and redistribution.
* NO WARRANTY OF ANY KIND IS PROVIDED.
*
* This example sends a valid LoRaWAN packet with payload "Hello,
* world!", using frequency and encryption settings matching those of
* the The Things Network. It's pre-configured for the Adafruit
* Feather M0 LoRa.
*
* This uses OTAA (Over-the-air activation), where where a DevEUI and
* application key is configured, which are used in an over-the-air
* activation procedure where a DevAddr and session keys are
* assigned/generated for use with all further communication.
*
* Note: LoRaWAN per sub-band duty-cycle limitation is enforced (1% in
* g1, 0.1% in g2), but not the TTN fair usage policy (which is probably
* violated by this sketch when left running for longer)!
* To use this sketch, first register your application and device with
* the things network, to set or generate an AppEUI, DevEUI and AppKey.
* Multiple devices can use the same AppEUI, but each device has its own
* DevEUI and AppKey.
*
* Do not forget to define the radio type correctly in
* arduino-lmic/project_config/lmic_project_config.h or from your BOARDS.txt.
*
*******************************************************************************/
#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
#define FILLMEIN 0
#else
#warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
#define FILLMEIN (#dont edit this, edit the lines that use FILLMEIN)
#endif
// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8] = { XXXXXXXXX };
void os_getArtEui(u1_t* buf) {
memcpy_P(buf, APPEUI, 8);
}
// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8] = { XXXXXXXXXXXX };
void os_getDevEui(u1_t* buf) {
memcpy_P(buf, DEVEUI, 8);
}
// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from the TTN console can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = {XXXXXXXXXXXXXX };
void os_getDevKey(u1_t* buf) {
memcpy_P(buf, APPKEY, 16);
}
static uint8_t mydata[] = "1Hello, world!";
static osjob_t sendjob;
// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 60;
// Pin mapping
//
const lmic_pinmap lmic_pins = {
.nss = 6,
.rxtx = LMIC_UNUSED_PIN,
.rst = LMIC_UNUSED_PIN,
.dio = {7,11,LMIC_UNUSED_PIN}, //DIO0, DIO1 connected
};
void printHex2(unsigned v) {
v &= 0xff;
if (v < 16)
Serial.print('0');
Serial.print(v, HEX);
}
void onEvent(ev_t ev) {
Serial.print(os_getTime());
Serial.print(": ");
switch (ev) {
case EV_SCAN_TIMEOUT:
Serial.println(F("EV_SCAN_TIMEOUT"));
break;
case EV_BEACON_FOUND:
Serial.println(F("EV_BEACON_FOUND"));
break;
case EV_BEACON_MISSED:
Serial.println(F("EV_BEACON_MISSED"));
break;
case EV_BEACON_TRACKED:
Serial.println(F("EV_BEACON_TRACKED"));
break;
case EV_JOINING:
Serial.println(F("EV_JOINING"));
break;
case EV_JOINED:
Serial.println(F("EV_JOINED"));
{
u4_t netid = 0;
devaddr_t devaddr = 0;
u1_t nwkKey[16];
u1_t artKey[16];
LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
Serial.print("netid: ");
Serial.println(netid, DEC);
Serial.print("devaddr: ");
Serial.println(devaddr, HEX);
Serial.print("AppSKey: ");
for (size_t i = 0; i < sizeof(artKey); ++i) {
if (i != 0)
Serial.print("-");
printHex2(artKey[i]);
}
Serial.println("");
Serial.print("NwkSKey: ");
for (size_t i = 0; i < sizeof(nwkKey); ++i) {
if (i != 0)
Serial.print("-");
printHex2(nwkKey[i]);
}
Serial.println();
}
// Disable link check validation (automatically enabled
// during join, but because slow data rates change max TX
// size, we don't use it in this example.
LMIC_setLinkCheckMode(0);
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_RFU1:
|| Serial.println(F("EV_RFU1"));
|| break;
*/
case EV_JOIN_FAILED:
Serial.println(F("EV_JOIN_FAILED"));
break;
case EV_REJOIN_FAILED:
Serial.println(F("EV_REJOIN_FAILED"));
break;
break;
case EV_TXCOMPLETE:
Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
if (LMIC.txrxFlags & TXRX_ACK)
Serial.println(F("Received ack"));
if (LMIC.dataLen) {
Serial.print(F("Received "));
Serial.print(LMIC.dataLen);
Serial.println(F(" bytes of payload"));
char text[100] = { 0 };
Serial.print(F("Data Received: "));
for (int i = 0; i < LMIC.dataLen; i++) {
text[i] = (byte)(LMIC.frame + LMIC.dataBeg)[i];
Serial.print(" 0x");
Serial.print((byte)text[i], HEX);
}
Serial.print(" ");
Serial.print("in ASCII = ");
Serial.println(text);
}
// Schedule next transmission
os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);
break;
case EV_LOST_TSYNC:
Serial.println(F("EV_LOST_TSYNC"));
break;
case EV_RESET:
Serial.println(F("EV_RESET"));
break;
case EV_RXCOMPLETE:
// data received in ping slot
Serial.println(F("EV_RXCOMPLETE"));
break;
case EV_LINK_DEAD:
Serial.println(F("EV_LINK_DEAD"));
break;
case EV_LINK_ALIVE:
Serial.println(F("EV_LINK_ALIVE"));
break;
/*
|| This event is defined but not used in the code. No
|| point in wasting codespace on it.
||
|| case EV_SCAN_FOUND:
|| Serial.println(F("EV_SCAN_FOUND"));
|| break;
*/
case EV_TXSTART:
Serial.println(F("EV_TXSTART"));
break;
case EV_TXCANCELED:
Serial.println(F("EV_TXCANCELED"));
break;
case EV_RXSTART:
/* do not print anything -- it wrecks timing */
break;
case EV_JOIN_TXCOMPLETE:
Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
break;
default:
Serial.print(F("Unknown event: "));
Serial.println((unsigned)ev);
break;
}
}
void do_send(osjob_t* j) {
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Prepare upstream data transmission at the next possible time.
LMIC_setTxData2(1, mydata, sizeof(mydata) - 1, 0);
Serial.print(F("Packet queued "));
Serial.println(mydata[0], HEX);
if (mydata[0] == '9') mydata[0] = '0';
else mydata[0] += 1;
}
// Next TX is scheduled after TX_COMPLETE event.
}
void setup() {
delay(5000);
while (!Serial)
;
Serial.begin(115200);
Serial.println();
Serial.println(F("MCCI_LoRaWAN_LMIC_library test Starting"));
#ifdef VCC_ENABLE
// For Pinoccio Scout boards
pinMode(VCC_ENABLE, OUTPUT);
digitalWrite(VCC_ENABLE, HIGH);
delay(1000);
#endif
// LMIC init
os_init();
// Reset the MAC state. Session and pending data transfers will be discarded.
LMIC_reset();
LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
#if defined(CFG_eu868)
Serial.println("CFG_eu868");
#endif
LMIC_setLinkCheckMode(0);
LMIC_setDrTxpow(DR_SF7, 14);
//LMIC_selectSubBand(1);
// Start job (sending automatically starts OTAA too)
do_send(&sendjob);
}
void loop() {
os_runloop_once();
}
when run the above connects to the TTN V3 server to uplink and downlink data - serial monitor output
run of ttn-otaa-feather-us915_1.ino (note DIO1 NOT connected)
MCCI_LoRaWAN_LMIC_library test Starting
CFG_eu868
Packet queued 31
314472: EV_JOINING
797877: EV_TXSTART
1119195: EV_JOINED
netid: 19
devaddr: 260B7162
AppSKey: xxxxxxxxxxxxxxx
NwkSKey:xxxxxxxxxxxxxxxxxx
1119588: EV_TXSTART
1439864: EV_TXCOMPLETE (includes waiting for RX windows)
Received 3 bytes of payload
Data Received: 0x66 0x77 0x88 in ASCII = fw�
5190092: EV_TXSTART
Packet queued 32
5510381: EV_TXCOMPLETE (includes waiting for RX windows)
Received 4 bytes of payload
Data Received: 0x77 0x88 0x99 0x0 in ASCII = w��
9260615: EV_TXSTART
and the TTN server displays
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.