Beep Autonomous Embedded System Via LoRawan Communication Monitoring Beehives

by Titi_bu in Circuits > Arduino

345 Views, 2 Favorites, 0 Comments

Beep Autonomous Embedded System Via LoRawan Communication Monitoring Beehives

Capture d’écran 2022-11-29 160202.png
P1040710.JPG
HoneyChan H (84.1 × 59.4 cm) (1)-1.png

This instructable explains how to build and monitor an autonomous embedded system in order to receive data from beehives (temperature, humidity, weight, luminosity, battery voltage, frequencies) and being able to watch these values remotly.


You can watch a presentation here https://youtu.be/CLdYry7MDEE



Supplies

battery.png
dht22.png
maxim.png
micro.png
solar.png

Here is an exhaustive list of all the necessary hardware needed:

-Solar pannel : https://www.gotronic.fr/art-cellule-solaire-sol2w-18995.htm

-Lipo-Rider shield : https://www.gotronic.fr/art-carte-lipo-rider-pro-106990008-19050.htm

-Arduino Nano 33 BLE : https://docs.arduino.cc/hardware/nano-33-ble-sense

-Lora Module : https://www.gotronic.fr/art-module-lora-e5-grove-113020091-33673.htm

-3.7V Battery : https://www.gotronic.fr/art-accu-li-ion-3-7-v-1050-mah-5811.htm

-USB converter : https://www.gotronic.fr/art-convertisseur-usb-serie-dfr0164-19336.htm

-Temperature sensor : https://www.gotronic.fr/art-capteur-de-temperature-grove-101990019-23842.htm

-Weight sensor : https://www.gotronic.fr/art-amplificateur-hx711-grove-101020712-31346.htm

-Humidity sensor : https://www.gotronic.fr/art-module-capteur-t-et-humidite-sen-dht22-31502.htm

-Jack female : https://www.gotronic.fr/art-fiche-femelle-pf203p-4807.htm#complte_desc

-Microphone

-Weight sensor:

-Audio amplificator : https://www.gotronic.fr/art-lm386n-10319.htm

-Labdec : https://www.gotronic.fr/art-plaque-de-montage-rapide-22812.htm

-Switch : https://www.gotronic.fr/art-inter-unipolaire-c170h-4424.htm

-Resistors

-Converter 3.3V

-Capacitors

-Wires

Electrical Schematic

unnamed.png

Here is the explicit electrical schematic. Note that you are note obliged to wire every sensor for the system to work.

Send Data Via Lora to TheThingsNetwork

Capture d’écran 2023-01-03 142050.png
unknown.png

I The Things Network


  1. Create an account on the things Network :Overview - Console - The Things Network
  2. Go to "Applications"/"+ create application" and name it as you would like. We called ours "zebee".
  3. Go to "End Device"/"+ add end device" and select "seedTechnology" under "brand", "Seed Studio lorawan Dev kit" under model, "EU_863_870" for the profile if you are in europe.
  4. Frequency plan: Europe 863-870 MHz (SF9 for RX2 – recommended)AppEUI : Fill it with zeros for now, DevEUI: Generate, AppKey: Generate, EndDeviceId: zebee.


II Communication using USB/Série DFR0164


Connect the Lora module to the usb converter

LoRa E5 | DFR0164

Tx | TXD

Rx | RXD

Launch Putty and establish a connection with 9600 bauds and write the following commands:

AT send "OK" 
AT+ID Send module IDs (DevAddr, AppEUI, DevEUI)
AT+DR=EU868 # set the zone, can be U915...
+DR: EU868

To change module IDS :
AT+ID=DevEUI,0B68BADE43C2FADE # set the DevEUI
AT+ID=AppEUI,81263C32387B3144 # set the AppEUI
AT+KEY=APPKEY,216BBEF3ADBBE2DXXXXXXXXXXXXXXXX

Select OTAA mode to join the network
AT+MODE=LWOTAA # set OTAA join mode
AT+DR=DR0 # change speed for SF7 BW125
AT+DR=DR1 # change speed for SF8 BW125
AT+DR=DR2 # change speed for SF9 BW125
AT+DR=DR3 # change speed for SF10 BW125
AT+DR=DR4 # change speed for SF11 BW125
AT+DR=DR5 # change speed for SF12 BW125

Join the network
AT+JOIN
+JOIN: Start
+JOIN: NORMAL
+JOIN: Network joined
+JOIN: NetID 326548 DevAddr 48:00:00:42
+JOIN: Done

# in case of problem during join you get
+JOIN: Start
+JOIN: NORMAL
+JOIN: Join failed
+JOIN: Done

Send a message :
AT+MSGHEX=01020304 # send payload 0x01,0x02,0x03,0x04 / 4B
+MSGHEX: Start
+MSGHEX: Done

or to send plain text
AT+MSG=01020304 # send payload "01020304" / 8 chars
+MSG: Start
+MSG: Done

You can check full documentation here: LoRa-E5 AT Command Specification_V1.0 .pdf (seeedstudio.com)


III Arduino connection


On the arduino we can connect the Lora module :

LoRa E5 | Arduino

Tx | Rx

Rx | Tx

And write the following code:

static char recv_buf[512];
static bool is_exist = false;
static bool is_join = false;
static int led = 0;
unsigned int ret = 0;
unsigned char led_flag = 0;

// Fonction called in order to connect to the LoRaWan network
static int at_send_check_response(char *p_ack, int timeout_ms, char *p_cmd, ...)
{
    unsigned int ch;
    unsigned int num = 0;
    unsigned int index = 0;
    unsigned int startMillis = 0;


    memset(recv_buf, 0, sizeof(recv_buf));
    Serial1.write(p_cmd);
    delay(200);
    startMillis = millis();


    do
    {
        while (Serial1.available() > 0)
        {
            ch = Serial1.read();
            recv_buf[index++] = ch;
            delay(2);
        }


    } while (millis() - startMillis < timeout_ms);


    if (strstr(recv_buf, p_ack) != NULL)
    {
        return 1;
    }
    else
        return 0;
}

// Fonction called to Setup the LoRaWan
void Setup_LoRaWan()
{
  ret = at_send_check_response("+AT: OK", 100, "AT\r\n");
  while ( !ret ){
    ret = at_send_check_response("+AT: OK", 100, "AT\r\n");
  }


  is_exist = true;
  at_send_check_response("+ID: AppEui", 1000, "AT+ID\r\n");
  at_send_check_response("+MODE: LWOTAA", 1000, "AT+MODE=LWOTAA\r\n");
  at_send_check_response("+DR: EU868", 1000, "AT+DR=EU868\r\n");
  at_send_check_response("+CH: NUM", 1000, "AT+CH=NUM,0-2\r\n");
  at_send_check_response("+KEY: APPKEY", 1000,
                          "AT+KEY=APPKEY,\"437BBxxxxxxxxxxxxxxxxxxxx\"\r\n");
  at_send_check_response("+KEY: DEVEUI", 1000, "AT+ID=DEVEUI,\"2022202220222022\"\r\n");
  at_send_check_response("+KEY: APPEUI", 1000, "AT+ID=APPEUI,\"0000000000000000\"\r\n");
  at_send_check_response("+CLASS: C", 1000, "AT+CLASS=A\r\n");
  at_send_check_response("+PORT: 8", 1000, "AT+PORT=8\r\n");
  delay(200);
}

// Fonction called in order to connect to lorawan network
void Connect_LoRaWan()
{
  if (at_send_check_response("+JOIN: Network joined", 12000, "AT+JOIN\r\n"))
  {
    is_join = true;
  }
  else
  {
    at_send_check_response("+ID: AppEui", 1000, "AT+ID\r\n");
    delay(5000);
  }
}

// Fonction called in order to send data though the LoRaWan network
void Communication_LoRaWan()
{
  char cmd[512];
  sprintf(cmd, "AT+MSGHEX=%04X%08X%08X%08X%04X%08X%04X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\r\n",u_battery, Tab_Maxim_temp[0], Tab_Maxim_temp[1], dht22_1_temp, dht22_1_hum, dht22_2_temp, dht22_2_hum, sunlight, weight, out[0], out[1], out[2], out[3], out[4], out[5],out[6],out[7],out[8],out[9]);

  Serial.println(cmd);
  Serial.println(dht22_1_temp, HEX);


  ret = at_send_check_response("Done", 5000, cmd);
  if (ret)
  {
    delay(5000);
    Downlink_treatment(recv_buf);
  }
  else
  {
      Serial.print("Send failed!\r\n\r\n");
  }


}

/* --- Arduino default fonctions --- */
void setup()
{
  delay(2000);
  Serial.begin(9600);
  Serial1.begin(9600);
  Setup_LoRaWan();
  delay(2000);
  while ( is_join == false )
  {
    Connect_LoRaWan();
  }
}

void loop()
{
  Communication_LoRaWan();
  delay(20000);
}


Finally, you should see in live-data some data sent.

You can decode this data using payload-formatter by writing in the uplink session this custom javascript formatter:

function decodeUplink(input) {
  var data = {};
  data.bv = (input.bytes[0] << 8 | (input.bytes[1]))/10;
  data.t_0 = ((input.bytes[2] << 24) | (input.bytes[3] << 16) | (input.bytes[4] << 8) | input.bytes[5])/10;
  data.t_1 = ((input.bytes[6] << 24) | (input.bytes[7] << 16) | (input.bytes[8] << 8) | input.bytes[9])/10;
  data.t_2 = ((input.bytes[10] << 24) | (input.bytes[11] << 16) | (input.bytes[12] << 8) | input.bytes[13])/10;
  data.h = ((input.bytes[14] << 8 | (input.bytes[15])))/10;
  data.t_3 = ((input.bytes[16] << 24) | (input.bytes[17] << 16) | (input.bytes[18] << 8) | input.bytes[19])/10;
  data.humidity = ((input.bytes[20] << 8 | (input.bytes[21])))/10;
  data.l = ((input.bytes[22] << 8 | (input.bytes[23])));
  data.weight_kg = ((input.bytes[24] << 8 | (input.bytes[25])))/10;
  data.s_bin098_146Hz = (input.bytes[26]);
  data.s_bin146_195Hz = (input.bytes[27]);
  data.s_bin195_244Hz = (input.bytes[28]);
  data.s_bin244_293Hz = (input.bytes[29]);
  data.s_bin293_342Hz = (input.bytes[30]);
  data.s_bin342_391Hz = (input.bytes[31]);
  data.s_bin391_439Hz = (input.bytes[32]);
  data.s_bin439_488Hz = (input.bytes[33]);
  data.s_bin488_537Hz = (input.bytes[34]);
  data.s_bin537_586Hz = (input.bytes[35]);
 return {
 data: data,
 warnings: [],
 errors: []
 };
}


Step 3: Decode Data on Ubidots

ubidots.png

On an additionnal step, you can send your data to ubidots followig this tutorial

Plugins: Connect The Things Stack to Ubidots | Ubidots Help Center

Board and Audio PCB

CleanShot_2023-01-07_at_17.41.422x.png
image.png

Code for All the Sensors

weightsensor.png
audio.png
dht22.png
maxim.png
solar.png

Because of the limitation of instructable, the entire code is linked here so that you can dive into it to connect all the required sensors


The fft decoder has been written by QFFT : (105) QuickFFT: High Speed FFT for Arduino - YouTube

Downloads

Install the System

P1040757.JPG

Once everything is working well, you can finally install it on the beehive