I want to fix the frequency

I’m using RAK2245 and Feather M0 with LoRa. How can I set a fixed frequency in the following code? I’ve tried using the disableChannel() method, and I’ve also tried using LMIC.freq = 922100000 .

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#define CHANNEL  1
static const u1_t PROGMEM APPEUI[8] = { 0x10, 0x97, 0x7E, 0xCE, 0x0E, 0x7B, 0x7E, 0xFE };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8); }
// This should also be in little endian format
static const u1_t PROGMEM DEVEUI[8] = { 0x53, 0x00, 0x06, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8); }
// This key should be in big endian format
static const u1_t PROGMEM APPKEY[16] = { 0x46, 0x8A, 0x33, 0xAF, 0xD2, 0x3A, 0xAF, 0x71, 0xEF, 0xA1, 0x4A, 0x4B, 0x89, 0xDC, 0x65, 0xC8 };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16); }
static uint8_t mydata[] = "Hello, 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 = 8,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = LMIC_UNUSED_PIN,
    .dio = {3, 9, LMIC_UNUSED_PIN},
};
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"));
            // Disable link check validation (automatically enabled
            // during join, but not supported by TTN at this time).
            LMIC_setLinkCheckMode(0);
            break;
        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.println(F("Received "));
              Serial.println(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
            }
            // 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;
         default:
            Serial.println(F("Unknown event"));
            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.println(F("Packet queued"));
        Serial.println(LMIC.freq);
    }
    // Next TX is scheduled after TX_COMPLETE event.
    os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
}
void setup() {
    Serial.begin(9600);
    Serial.println(F("Starting"));
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();
    LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100);
//    LMIC.freq = 922100000;
//    for (uint8_t i = 0; i < 9; i++) {
//  if (i != CHANNEL) {
//    LMIC_disableChannel(i);
//  }
//}
    do_send(&sendjob);
}
void loop() {
    os_runloop_once();
}

Please edit your post so that code is formatted with the </> tool - click the Pencil tool to edit.

And perhaps explain why you want to side step the LoRaWAN spec?

And which bit of the code is relevant so the volunteers answering can narrow down on the relevant bit.

I want to transmit data from four M0 devices simultaneously, but there are cases where data is lost due to frequency collisions. Therefore, I want to fix the frequency for each M0 device to prevent this issue.

This is not how LoRaWAN was designed. Collisions can occur at any time and are a fundamental part of the architecture or LoRaWAN. They cannot be prevented from happening. Also, LoRaWAN is using ISM bands and because of sharing frequencies with other (non-LoRaWAN) users collisions can happen always.

Your approach to “fix it in the code” is not the way to go because the code will automatically choose a different frequency for every transmission.

You may have to reconsider your choice for this technology if you feel that the issues you see are not addressed to your needs.

Be aware that a TX interval of 60 seconds will significantly breach the TTN fair use policy.

Why?

You can take the readings at the same time and then queue a send - with a bit of random delay and 8 channels you should see the same packet loss as most other applications which is typically <5%.

Please confirm that you are adhering to the Fair Use Policy.