Basic CubeCell Lora examples

Hello,

With the cubecell, most of the examples are for LoraWAN and the only example of actual Lora is the pingpong example which isn’t commented in the actual body, does any one have an example of just a basic transmit and receive like the wireless sticks had for the cubecell? So far I have be able to get add-ons working with cubecell (switches, lcd, ic2 items etc) but the setup of Lora has been a challenge, it could just be I don’t program in C and I’m missing something obvious but if anyone has basic send hello world and recieve hello world I would document and submit it the git repo for others.

Eh I got it working by just cutting up the pingpong example below is sender example still haven’t figured out how to make a receiver only program out of the ping pong example.

#include “LoRaWan_APP.h”
#include “Arduino.h”

#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif

#define RF_FREQUENCY 915000000 // Hz

#define TX_OUTPUT_POWER 14 // dBm

#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false

#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 30 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

int16_t txnumber;

int16_t RSSI,rxSize;

void setup() {
BoardInitMcu( );
Serial.begin(115200);

txnumber=0;
RSSI=0;





Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                               LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                               LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                               true, 0, 0, LORA_IQ_INVERSION_ON, 3000 ); 

}

void loop()
{

  	delay(1000);
  	txnumber++;
      sprintf(txpacket,"%s","how long can hello tx be");
     
      RGB_ON(COLOR_SEND,0);

      Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));

      Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );

}

Here is the same transmit code with the BME280 sensor. It works OK, but I cannot implement so far the VEXT and the LowPower_Handler() functions. It seems that the I2C connection of my BME280 sensor gets lost.

With this code the CellCube board and the sensor consume 12 mAh, what is a bit too much for the battery set-up. The VCC of the BME280 sensor is connected to the VEXT pin on the side of the board.

#include “LoRaWan_APP.h”
#include “Arduino.h”
#include “Wire.h”
#include “BME280.h”

BME280 bme280;

#ifndef LoraWan_RGB
#define LoraWan_RGB 0
#endif

#define RF_FREQUENCY 868000000 // Hz

#define TX_OUTPUT_POWER 14 // dBm

#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false

#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 30 // Define the payload size here

char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];

unsigned long time_now = 0;
unsigned long next_millis = 0;

static RadioEvents_t RadioEvents;

int16_t txnumber;

int16_t RSSI, rxSize;

void setup() {

BoardInitMcu( );
Serial.begin(115200);

pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);

txnumber = 0;
RSSI = 0;

Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );

if (!bme280.init()) {
Serial.println(“Device error!”);
}

time_now = millis();
while (millis() < time_now + 500) { // equivalent of delay(…);
}

}

void loop()
{

float temp = 0;
float humd = 0;
float prss = 0;
float altd = 0;
temp = bme280.getTemperature();
humd = bme280.getHumidity();
prss = bme280.getPressure();
altd = bme280.calcAltitude(prss);

//get and print temperatures
Serial.print("Temp: ");
Serial.print(temp);
Serial.println(“C”);//The unit for Celsius because original arduino don’t support speical symbols

//get and print humidity data
Serial.print(“Humidity: “);
Serial.print(humd);
Serial.println(”%”);

//get and print atmospheric pressure data
Serial.print("Pressure: ");
Serial.print(prss);
Serial.println(“Pa”);

//get and print altitude data
Serial.print("Altitude: ");
Serial.print(altd);
Serial.println(“m”);

uint16_t voltage = 0;

voltage = analogRead(ADC); //return the voltage in mV, max value can be read is 3300mV
Serial.println(voltage);

time_now = millis();
while (millis() < time_now + 500) { // equivalent of delay(…);
}

char *str_temp;

String msgT = “”;

msgT = String(temp, 1) + “#” + String(humd, 1) + “#” + String((prss / 100), 1) + “#” + String(altd, 1) + “#” + String(voltage);

memset(txpacket, 0, BUFFER_SIZE);

// converting strig to a char?
str_temp = (char*)(msgT).c_str();

sprintf(txpacket, “%s”, str_temp);

RGB_ON(COLOR_SEND, 0);

Serial.printf("\r\nsending packet “%s” , length %d\r\n", txpacket, strlen(txpacket));

Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );

RGB_ON(0, 0);

time_now = millis();
while (millis() < time_now + 10000) {
}

}

Thanks for the sending example, what does the receiver code look like on the other side is it also a cubecell or a different board?

Just an Idea: do you reinit your sensor after sleep?