Skip to content

Commit

Permalink
Add chipID to generate DEV_EUI.
Browse files Browse the repository at this point in the history
Add chipID to generate DEV_EUI.
  • Loading branch information
Quency-D committed Jun 19, 2021
1 parent 2b11cac commit 7104eaa
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/OTAA/OTAA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/OTAA_Battery_power/OTAA_Battery_power.ino
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/OTAA_LED/OTAA_LED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/OTAA_OLED/OTAA_OLED.ino
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/Sensor/LoRaWAN_HDC1080/LoRaWAN_HDC1080.ino
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ void loop()
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
3 changes: 3 additions & 0 deletions examples/WiFi_LoRaWAN/WiFi_LoRaWAN.ino
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ void loop(void) {
{
case DEVICE_STATE_INIT:
{
#if(LORAWAN_DEVEUI_AUTO)
LoRaWAN.generateDeveuiByChipID();
#endif
LoRaWAN.init(loraWanClass,loraWanRegion);
break;
}
Expand Down
25 changes: 24 additions & 1 deletion src/ESP32_LoRaWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,25 @@ static void lwan_dev_params_update( void )
LoRaMacPrimitives_t LoRaMacPrimitive;
LoRaMacCallback_t LoRaMacCallback;

void LoRaWanClass::generateDeveuiByChipID()
{
int i;
uint64_t chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).

//Serial.printf("\nDevEui=");
for( i=0;i<6;i++)
{
DevEui[i] = chipid&0XFF;// (uniqueId[1]>>(8*(3-i)))&0xFF;
chipid = chipid >>8;
//Serial.printf("%02X",DevEui[i]);
}
DevEui[6] = DevEui[1] &DevEui[2];
//Serial.printf("%02X",DevEui[6]);
DevEui[7] = DevEui[3] &DevEui[4];
//Serial.printf("%02X",DevEui[7]);

}

void LoRaWanClass::init(DeviceClass_t classMode,LoRaMacRegion_t region)
{
if(classMode == CLASS_B)
Expand Down Expand Up @@ -394,7 +413,11 @@ void LoRaWanClass::init(DeviceClass_t classMode,LoRaMacRegion_t region)
mibReq.Param.Class = classMode;
LoRaMacMibSetRequestConfirm( &mibReq );


Serial.printf("\nDevEui=");
for(int i = 0;i<8;i++)
{
Serial.printf("%02X",DevEui[i]);
}
Serial.print("\r\nLoRaWAN ");
switch(region)
{
Expand Down
1 change: 1 addition & 0 deletions src/ESP32_LoRaWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class LoRaWanClass{
void displaySending();
void displayAck();
void displayMcuInit();
void generateDeveuiByChipID();
};

extern enum eDeviceState deviceState;
Expand Down
2 changes: 1 addition & 1 deletion src/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
#ifndef __GPIO_H__
#define __GPIO_H__

#include <stdint.h>
#include "pinName-board.h"
#include "pinName-ioe.h"
Expand Down

0 comments on commit 7104eaa

Please sign in to comment.