Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino 我的Lora adafruit羽毛m0元';无法发送加入请求_Arduino_Lorawan - Fatal编程技术网

Arduino 我的Lora adafruit羽毛m0元';无法发送加入请求

Arduino 我的Lora adafruit羽毛m0元';无法发送加入请求,arduino,lorawan,Arduino,Lorawan,所以,我从Adafruit得到了一个新的LoRa模块,名为Feather m0(900MHz)。我尝试运行修改后的示例代码,但无法向live server发送“加入请求”。我还没有像示例代码所建议的那样将Io1连接到引脚6,所以我想知道是否有人知道我的代码出了什么问题?或者如果我需要用不同的方式写?请注意,这些密钥不再有效,因此,它们是否显示并不重要。以下代码被修改为仅发送编码的数字“18” /***************************************************

所以,我从Adafruit得到了一个新的LoRa模块,名为Feather m0(900MHz)。我尝试运行修改后的示例代码,但无法向live server发送“加入请求”。我还没有像示例代码所建议的那样将Io1连接到引脚6,所以我想知道是否有人知道我的代码出了什么问题?或者如果我需要用不同的方式写?请注意,这些密钥不再有效,因此,它们是否显示并不重要。以下代码被修改为仅发送编码的数字“18”

/*******************************************************************************
*物联网-传感器数据示例
*
*发送具有DHT22温度和
*使用Feather M0 LoRa将湿度数据传输至物联网。
*
*学习指南:https://learn.adafruit.com/the-things-network-for-feather
*
*版权所有(c)2015 Thomas Telkamp和Matthijs Kooijman
*版权所有(c)2018年麦肯锡特里·摩尔
*版权所有(c)2018布伦特·鲁贝尔,Adafruit Industries
*
*特此免费向任何人授予许可
*获取本文件和随附文件的副本,
*他们想做什么就做什么,没有任何限制,
*包括但不限于复制、修改和重新分发。
*不提供任何形式的担保。
*******************************************************************************/
#包括
#包括
#包括
//
//对于正常使用,我们要求您编辑草图以替换FILLMEIN
//使用TTN控制台分配的值。然而,对于回归测试,
//我们希望能够编译这些脚本。回归测试定义了
//编译回归测试,在这种情况下,我们将FILLMEIN定义为非-
//有用但无害的价值。
//
//这个EUI必须是小尾端格式,所以是最低有效字节
//首先。从ttnctl输出复制EUI时,这意味着要反转
//字节数。对于发出的TTN EUIs,最后一个字节应为0xD5、0xB3,
//0x70。
静态常量u1_t PROGMEM APPEUI[8]={0x70、0xB3、0xD7、0x7E、0xD0、0x04、0x0C、0xA6};
void os_getArtEui(u1_t*buf){memcpy_P(buf,APPEUI,8);}
//这也应该是little-endian格式,见上文。
静态常量u1_t PROGMEM DEVEUI[8]={0x00、0x53、0x9C、0x7B、0x6C、0xA5、0x4C、0xED};
void os_getDevEui(u1_t*buf){memcpy_P(buf,DEVEUI,8);}
//这个键应该是big-endian格式(或者,因为它不是真正的
//数字,但一块内存,endianness并不真正适用)。在里面
//实际上,从TTN控制台获取的密钥可以按原样复制。
静态常量u1_t PROGMEM APPKEY[16]={0x8A、0x16、0xE7、0x7D、0x10、0x74、0x0D、0x47、0x19、0x3C、0xE5、0x3F、0x82、0xF2、0x65、0x10};
void os_getDevKey(u1_t*buf){memcpy_P(buf,APPKEY,16);}
//要发送到TTN网关的有效负载
静态uint8_t有效载荷[5];
静态osjob\u t sendjob;
//计划每这么多秒发送一次(由于工作原因可能会变长
//周期限制)。
常数无符号发送间隔=60;
//Adafruit羽毛M0 LoRa的Pin映射
常数lmic_引脚映射lmic_引脚={
.nss=8,
.rxtx=LMIC_未使用_引脚,
.rst=4,
.dio={3,6,LMIC\u未使用的\u PIN},
.rxtx_rx_active=0,
.rssi_cal=8,//LBT cal表示Adafruit羽毛M0 LoRa,单位为dB
.spi_freq=8000000,
};
//初始化。DHT
无效打印HEX2(无符号v){
v&=0xff;
if(v<16)
Serial.print('0');
串行打印(v,十六进制);
}
无效事件(ev_t ev){
Serial.print(os_getTime());
连续打印(“:”);
开关(ev){
案例EVU扫描超时:
Serial.println(F(“EV_扫描超时”);
打破
发现的案例:
序列号:println(F(“EV_BEACON_FOUND”);
打破
案例EV_灯塔_遗漏:
序列号。打印号(F(“EV_信标缺失”);
打破
追踪到的情况:
序列号println(F(“EV_信标跟踪”);
打破
案例EV_连接:
连续打印(F(“EV_加入”);
打破
加入的案例:
序列号:println(F(“EV_加入”);
{
u4_t netid=0;
devaddr_t devaddr=0;
u1_t nwkKey[16];
u1_t artKey[16];
LMIC_GetSessionKey(&netid,&devaddr,nwkKey,artKey);
连载打印(“netid:”);
序列号println(netid,DEC);
串行打印(“devaddr:”);
串行打印LN(devaddr,十六进制);
连续打印(“AppSKey:”);
对于(尺寸i=0;i
/*******************************************************************************
 * The Things Network - Sensor Data Example
 *
 * Example of sending a valid LoRaWAN packet with DHT22 temperature and
 * humidity data to The Things Networ using a Feather M0 LoRa.
 *
 * Learn Guide: https://learn.adafruit.com/the-things-network-for-feather
 *
 * Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
 * Copyright (c) 2018 Terry Moore, MCCI
 * Copyright (c) 2018 Brent Rubell, Adafruit Industries
 *
 * 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.
 *******************************************************************************/
#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.
//

// 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] = { 0x70, 0xB3, 0xD7, 0x7E, 0xD0, 0x04, 0x0C, 0xA6 } ;
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] = { 0x00, 0x53, 0x9C, 0x7B, 0x6C, 0xA5, 0x4C, 0xED } ;
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] = { 0x8A, 0x16, 0xE7, 0x7D, 0x10, 0x74, 0x0D, 0x47, 0x19, 0x3C, 0xE5, 0x3F, 0x82, 0xF2, 0x65, 0x10 };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

// payload to send to TTN gateway
static uint8_t payload[5];
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 for Adafruit Feather M0 LoRa
const lmic_pinmap lmic_pins = {
    .nss = 8,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 4,
    .dio = {3, 6, LMIC_UNUSED_PIN},
    .rxtx_rx_active = 0,
    .rssi_cal = 8,              // LBT cal for the Adafruit Feather M0 LoRa, in dB
    .spi_freq = 8000000,
};

// init. DHT

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.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;
        /*
        || 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 {
        // read the temperature from the DHT22
        float temperature = 18;
        Serial.print("Temperature: "); Serial.print(temperature);
        Serial.println(" *C");
        // adjust for the f2sflt16 range (-1 to 1)
        temperature = temperature / 100;

      

        // float -> int
        // note: this uses the sflt16 datum (https://github.com/mcci-catena/arduino-lmic#sflt16)
        uint16_t payloadTemp = LMIC_f2sflt16(temperature);
        // int -> bytes
        byte tempLow = lowByte(payloadTemp);
        byte tempHigh = highByte(payloadTemp);
        // place the bytes into the payload
        payload[0] = tempLow;
        payload[1] = tempHigh;


        // prepare upstream data transmission at the next possible time.
        // transmit on port 1 (the first parameter); you can use any value from 1 to 223 (others are reserved).
        // don't request an ack (the last parameter, if not zero, requests an ack from the network).
        // Remember, acks consume a lot of network resources; don't ask for an ack unless you really need it.
        LMIC_setTxData2(1, payload, sizeof(payload)-1, 0);
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    delay(5000);
    while (! Serial);
    Serial.begin(9600);
    Serial.println(F("Starting"));


    // LMIC init
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();
    // Disable link-check mode and ADR, because ADR tends to complicate testing.
    LMIC_setLinkCheckMode(0);
    // Set the data rate to Spreading Factor 7.  This is the fastest supported rate for 125 kHz channels, and it
    // minimizes air time and battery power. Set the transmission power to 14 dBi (25 mW).
    LMIC_setDrTxpow(DR_SF7,14);
    // in the US, with TTN, it saves join time if we start on subband 1 (channels 8-15). This will
    // get overridden after the join by parameters from the network. If working with other
    // networks or in other regions, this will need to be changed.
    //LMIC_selectSubBand(1);

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
  // we call the LMIC's runloop processor. This will cause things to happen based on events and time. One
  // of the things that will happen is callbacks for transmission complete or received messages. We also
  // use this loop to queue periodic data transmissions.  You can put other things here in the `loop()` routine,
  // but beware that LoRaWAN timing is pretty tight, so if you do more than a few milliseconds of work, you
  // will want to call `os_runloop_once()` every so often, to keep the radio running.
  os_runloop_once();
}