Need coding service

I have the HTCC-AB01 connected to an ultrasonic sensor HC-SR04 with pin GIO1 and GIO2. I can’t get the code to send over Lora to Heltec WiFi Kit 32 OLED. Would like the AB01 to transmit distance to the ESP32 then deep sleep for 10 minuets. It will be on running it on battery and solar panel. I would also like it to transmit battery voltage.

I think I am more stuck on the TX part. I have the sensor working but can’t send the value.

case TX:
{
sprintf(txPacket,"%s",“ADC_battery: “);
sprintf(txPacket+strlen(txPacket),”%d”,voltage);
turnOnRGB(COLOR_SEND,0);
Serial.printf("\r\nsending packet “%s” , length %d\r\n",txPacket, strlen(txPacket));
Radio.Send( (uint8_t *)txPacket, strlen(txPacket) );
state=LOWPOWER;
break;
}

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

#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 8 // [SF7…SF12]
#define LORA_CODINGRATE 4 // [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

#define trigPin GPIO1
#define echoPin GPIO2

float duration;
float distance;

char txPacket[BUFFER_SIZE];
double txNumber;
static RadioEvents_t RadioEvents;
void OnTxDone( void );
void OnTxTimeout( void );

typedef enum
{
LOWPOWER,
ReadVoltage,
TX
} States_t;

States_t state;
bool sleepMode = false;
int16_t rssi, rxSize;
uint16_t voltage;

void setup() {
boardInitMcu( );
Serial.begin(115200);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
voltage = 0;
rssi = 0;

RadioEvents.TxDone = OnTxDone;
RadioEvents.TxTimeout = OnTxTimeout;

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 );

state = ReadVoltage;
}

void loop()
{
switch (state)
{
case TX:
{
sprintf(txPacket,"%s",“ADC_battery: “);
sprintf(txPacket+strlen(txPacket),”%d”,voltage);
turnOnRGB(COLOR_SEND,0);
Serial.printf("\r\nsending packet “%s” , length %d\r\n",txPacket, strlen(txPacket));
Radio.Send( (uint8_t *)txPacket, strlen(txPacket) );
state=LOWPOWER;
break;
}
case LOWPOWER:
{
lowPowerHandler();
delay(100);
turnOffRGB();
delay(2000); //LowPower time
state = ReadVoltage;
break;
}
case ReadVoltage:
{

    //Voltage
    pinMode(VBAT_ADC_CTL, OUTPUT);
    digitalWrite(VBAT_ADC_CTL, LOW);
    voltage = analogRead(ADC) * 2;
    pinMode(VBAT_ADC_CTL, INPUT);

    //Ultrasonic
    // Clears the trigPin
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin,
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    float distance = duration * 0.034 / 2;
    Serial.println(distance);

    state = TX;
    break;
  }
default:
  break;

}
Radio.IrqProcess();
}

void OnTxDone( void )
{
Serial.println(“TX done!”);
turnOnRGB(0, 0);
}

void OnTxTimeout( void )
{
Radio.Sleep( );
Serial.print(“TX Timeout…”);
state = ReadVoltage;
}

sorry, Heltec WiFi Kit 32 OLED have not LoRa hardware.

WiFi LoRa 32 have LoRa hardware. https://heltec.org/project/wifi-lora-32/

Sorry I ment to the WiFi LoRa 32. I just need help with the TX part.

look at the lorawan example to sent some bytes:

static void prepareTxFrame( uint8_t port )
{
/*appData size is LORAWAN_APP_DATA_MAX_SIZE which is defined in “commissioning.h”.
*appDataSize max value is LORAWAN_APP_DATA_MAX_SIZE.
*if enabled AT, don’t modify LORAWAN_APP_DATA_MAX_SIZE, it may cause system hanging or failure.
*if disabled AT, LORAWAN_APP_DATA_MAX_SIZE can be modified, the max value is reference to lorawan region and SF.
*for example, if use REGION_CN470,
*the max value for different DR can be found in MaxPayloadOfDatarateCN470 refer to DataratesCN470 and BandwidthsCN470 in “RegionCN470.h”.
*/
appDataSize = 4;
appData[0] = 0x00;
appData[1] = 0x01;
appData[2] = 0x02;
appData[3] = 0x03;
}

I posted almost the same question, if you search for coding service.
I’m not using the battery monitor. Yhis code is working sending distance reading from cubecell to Heltec ESP32 OLED V2
Here is the code

/* Heltec Automation send communication test example
*

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

int duration;

float dist = 0;

#define trigPin GPIO3
#define echoPin GPIO5

#define timetillsleep 5000
#define timetillwakeup 7200000

//#define timetosleep 1000
//#define timetowake 7200000 2 HRS 20000 24 sec

static TimerEvent_t sleep;
static TimerEvent_t wakeUp;
uint8_t lowpower=1;

/*

  • 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 22 // dBm

#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 8 // [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 10 // 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 getDistance() {

pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
delay(1000);
Wire.begin();
digitalWrite(Vext, LOW);
delay(100);
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

dist = ((duration/2) / 29.1 * 0.39370);
Serial.print("Distance: ");
Serial.println(dist);

delay (1000);

Wire.end();
digitalWrite(Vext, HIGH);
}

void onSleep()
{
Serial.printf(“Going into lowpower mode, %d ms later wake up.\r\n”,timetillwakeup);
lowpower=1;
//timetillwakeup ms later wake up;
TimerSetValue( &wakeUp, timetillwakeup );
TimerStart( &wakeUp );

}
void onWakeUp()
{
Serial.printf(“Woke up, %d ms later into lowpower mode.\r\n”,timetillsleep);
lowpower=0;
//timetillsleep ms later into lowpower mode;
TimerSetValue( &sleep, timetillsleep );
TimerStart( &sleep );

}

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

rssi=0;

Radio.Sleep( );
TimerInit( &sleep, onSleep );
TimerInit( &wakeUp, onWakeUp );
onSleep();

// time_now = millis();
// while (millis() < time_now + 500) {
//}

onWakeUp();

Radio.SetSyncWord(0x12); // 0x12 (private) or 0x34 (LoRaWan)
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()
{

if(lowpower){
//note that lowPowerHandler() runs six times before the mcu goes into lowpower mode;

digitalWrite(Vext, LOW);

}
// put your main code here, to run repeatedly:

else {

digitalWrite(Vext, HIGH);

delay(1000);

getDistance();

delay(1000);

char *str_temp;

String msgT = “”;

msgT = String(dist, 1);

memset(txpacket, 0, BUFFER_SIZE);

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

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

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

Serial.printf("\r\nsending packet “%s” , length %d\r\n", txpacket, strlen(txpacket));
Radio.Send( (uint8_t *)txpacket, strlen(txpacket) ); //send the package out

}
}