[SOLVED]CubeCell – Dev-Board Simple Receive Example

Im searching 2 example sketches. One sketch for sending sensor data over lora and then a receiver sketch to receive the sensor data over lora. The sensor is the bme280. I found a sketch for sending, but not for receiving. Thank You in Advance

Can you post your code for a look?

I got no code because i dont know how to use this library to write a receive script. The sender script is in the examples of the board.

If you need to use the standard loraWAN protocol, you need to purchase a gateway.

This example include receiver example: https://github.com/HelTecAutomation/ASR650x-Arduino/blob/master/libraries/LoRa/examples/LoRaBasic/pingpong/pingpong.ino

Anyway, we will update another independent receiving example later.

I just want to send data from a module to a other because there is no gateway near by.

When will you upload a independent receiving example? Thanks and have a nice day

Sorry I didn’t understand you correctly at the beginning.

/* Heltec Automation Ping Pong communication test example
*

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

/*

  • set LoraWan_RGB to 1,the RGB active in loraWan
  • RGB red means sending;
  • RGB green means received done;
    */
    #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;

  RadioEvents.RxDone = OnRxDone;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );

Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,
                               LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,
                               LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,
                               0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

turnOnRGB(COLOR_SEND,0); //change rgb color
Serial.println(“into RX mode”);
}

void loop()
{
Radio.Rx( 0 );
delay(500);
Radio.IrqProcess( );
}

void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr )
{
rssi=rssi;
rxSize=size;
memcpy(rxpacket, payload, size );
rxpacket[size]=’\0’;
turnOnRGB(COLOR_RECEIVED,0);
Radio.Sleep( );
Serial.printf("\r\nreceived packet “%s” with rssi %d , length %d\r\n",rxpacket,rssi,rxSize);

}

Thx a lot. Do you also got a send script with the bme 280 sensor ? Tried today to add it so the packet and send it but it was not working


I’m so sorry.I don’t have BMP280 , but you can reference this code.

And add the read data to the position in the picture, pay attention to the data type.

Do you know the datatype for example for float tried it but there was no success

/* Heltec Automation Ping Pong communication test example
*

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

/*

  • set LoraWan_RGB to 1,the RGB active in loraWan
  • RGB red means sending;
  • RGB green means received done;
    */
    #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;

double txNumber;

int16_t rssi,rxSize;
void DoubleToString( char *str, double double_num,unsigned int len);

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 += 0.01;
sprintf(txpacket,"%s",“Hello world number”); //start a package
// sprintf(txpacket+strlen(txpacket),"%d",txNumber); //add to the end of package

DoubleToString(txpacket,txNumber,3);	   //add to the end of package

turnOnRGB(COLOR_SEND,0); //change rgb color

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

Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out	

}

/**

  • @brief Double To String
  • @param str: Array or pointer for storing strings
  • @param double_num: Number to be converted
  • @param len: Fractional length to keep
  • @retval None
    */
    void DoubleToString( char *str, double double_num,unsigned int len) {
    double fractpart, intpart;
    fractpart = modf(double_num, &intpart);
    fractpart = fractpart * (pow(10,len));
    sprintf(str + strlen(str),"%d", (int)(intpart)); //Integer part
    sprintf(str + strlen(str), “.%d”, (int)(fractpart)); //Decimal part
    }

You can try this code.

Thanks a lot for the help :+1:

i got a problem, it sends two times the right data and then stops and does nothing. It does that when i try to send sensor data, with the 0.01 it works

    /* Heltec Automation Ping Pong communication test example
*

Function:
Send data from a CubeCell device over hardware
this project also realess in GitHub:
https://github.com/HelTecAutomation/ASR650x-Arduino
*/
#include <LoRaWan_APP.h>
#include <Arduino.h>
#include "Seeed_BME280.h"
#include <Wire.h>

BME280 bme280;



/*

set LoraWan_RGB to 1,the RGB active in loraWan
RGB red means sending;
RGB green means received done;
*/
#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 9 // [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;

double txNumber;

int16_t rssi,rxSize;
void DoubleToString( char *str, double double_num,unsigned int len);

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 ); 
 pinMode(Vext, OUTPUT);
  digitalWrite(Vext, LOW);
  delay(500);
  if(!bme280.init()){
    Serial.println("Device error!");
  }

                               
}

void loop()
{
  //float temp = bme280.getTemperature();
delay(1000);

txNumber = 0.01;
sprintf(txpacket,"%s","Hello world number"); //start a package
// sprintf(txpacket+strlen(txpacket),"%d",txNumber); //add to the end of package

DoubleToString(txpacket,txNumber,2);     //add to the end of package

turnOnRGB(COLOR_SEND,0); //change rgb color

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

Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out 
turnOffRGB();
}

/**

@brief Double To String
@param str: Array or pointer for storing strings
@param double_num: Number to be converted
@param len: Fractional length to keep
@retval None
*/
void DoubleToString( char *str, double double_num,unsigned int len) {
double fractpart, intpart;
fractpart = modf(double_num, &intpart);
fractpart = fractpart * (pow(10,len));
sprintf(str + strlen(str),"%d", (int)(intpart)); //Integer part
sprintf(str + strlen(str), ".%d", (int)(fractpart)); //Decimal part
}

Recommend do basic node-to-node communication test first. that will help you verify if there have any hardware problem.

Then add your function step by step.