783 KljGianni DubocquetNicolas DAILLY
Created June 26, 2023

Project HuntSafe

HuntSafe have for main objective to improve the security of hunters and hikers during Hunting Session. It's use LoraWan Technology.

49
Project HuntSafe

Things used in this project

Hardware components

Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Fingerprint Sensor
DFRobot Fingerprint Sensor
×1
Resistor 330 ohm
Resistor 330 ohm
×3
Arduino Leonardo
Arduino Leonardo
×2
Laser Diode, VCSEL
Laser Diode, VCSEL
×1
LoRa Arduino Shield
Makestro LoRa Arduino Shield
It's not really this one but the Dragino one
×1
Development Kit Accessory, GPS Antenna
Development Kit Accessory, GPS Antenna
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×2

Software apps and online services

Node-RED
Node-RED
The Things Stack
The Things Industries The Things Stack
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Schema 1

This is the scheme of the first module.

Fritzing Schema 2

This is the scheme of the GPS/LoraWan module

Code

Code Part : Arduino GPS

Arduino
Code That configure the second Leonardo card with the GPS and LoraWan Antenna and Shield.
include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>
#include "TinyGPS++.h"
#include <SoftwareSerial.h>


// LoRaWAN NwkSKey, network session key
// This is the default Semtech key, which is used by the prototype TTN
// network initially.
//ttn
static const PROGMEM u1_t NWKSKEY[16] = { 0x48, 0xA1, 0x23, 0xA9, 0x42, 0x61, 0xD1, 0xF0, 0xEA, 0x47, 0xD0, 0x13, 0x4D, 0x77, 0x17, 0xA6 };
// LoRaWAN AppSKey, application session key
// This is the default Semtech key, which is used by the prototype TTN
// network initially.
//ttn
static const u1_t PROGMEM APPSKEY[16] = { 0xA4, 0x71, 0xC7, 0x62, 0x72, 0x24, 0x43, 0x2F, 0xB6, 0x4F, 0x79, 0x56, 0xAC, 0xEF, 0xD7, 0x5F };

// LoRaWAN end-device address (DevAddr)
// See http://thethingsnetwork.org/wiki/AddressSpace
// ttn
static const u4_t DEVADDR = 0x260B2483;

/*
   This sample sketch demonstrates the normal use of a TinyGPS++ (TinyGPSPlus) object.
   It requires the use of SoftwareSerial, and assumes that you have a
   4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx).
*/
static const int RXPin = 1, TXPin = 0;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
//SoftwareSerial ss(RXPin, TXPin);

// These callbacks are only used in over-the-air activation, so they are
// left empty here (we cannot leave them out completely unless
// DISABLE_JOIN is set in config.h, otherwise the linker will complain).
void os_getArtEui (u1_t buf) { }
void os_getDevEui (u1_t* buf) { }
void os_getDevKey (u1_t* buf) { }

static uint8_t mydata[] = {0,0,0,0,0,0};
static osjob_t initjob, sendjob, blinkjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 10;
// Pin mapping
const lmic_pinmap lmic_pins = {
  .nss = 10,
  .rxtx = LMIC_UNUSED_PIN,
  .rst = 9,
  .dio = {2, 6, 7},
};
void do_send(osjob_t* j) {

  // Check if there is not a current TX/RX job running
  if (LMIC.opmode & OP_TXRXPEND) {
    Serial.println("OP_TXRXPEND, not sending");
  } else {
//Remplir my data


    // Prepare upstream data transmission at the next possible time.
    LMIC_setTxData2(1, mydata, sizeof(mydata), 0);
//    Serial.println("Packet queued");
//    Serial.println(LMIC.freq);
  }
  // Next TX is scheduled after TX_COMPLETE event.
}

void onEvent (ev_t ev) {
  Serial.print(os_getTime());
  Serial.print(": ");
  Serial.println(ev);
  switch (ev) {
    case EV_SCAN_TIMEOUT:
      Serial.println("EV_SCAN_TIMEOUT");
      break;
    case EV_BEACON_FOUND:
      Serial.println("EV_BEACON_FOUND");
      break;
    case EV_BEACON_MISSED:
      Serial.println("EV_BEACON_MISSED");
      break;
    case EV_BEACON_TRACKED:
      Serial.println("EV_BEACON_TRACKED");
      break;
    case EV_JOINING:
      Serial.println("EV_JOINING");
      break;
    case EV_JOINED:
      Serial.println("EV_JOINED");
      break;
    case EV_RFU1:
      Serial.println("EV_RFU1");
      break;
    case EV_JOIN_FAILED:
      Serial.println("EV_JOIN_FAILED");
      break;
    case EV_REJOIN_FAILED:
      Serial.println("EV_REJOIN_FAILED");
      break;
    case EV_TXCOMPLETE:
      Serial.println("EV_TXCOMPLETE (includes waiting for RX windows)");
      if (LMIC.dataLen) {
        // data received in rx slot after tx
        Serial.print("Data Received: ");
        Serial.write(LMIC.frame + LMIC.dataBeg, LMIC.dataLen);
        Serial.println();
      }
      // Schedule next transmission
      os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(TX_INTERVAL), do_send);
      break;
    case EV_LOST_TSYNC:
Serial.println("EV_LOST_TSYNC");
      break;
    case EV_RESET:
      Serial.println("EV_RESET");
      break;
    case EV_RXCOMPLETE:
      // data received in ping slot
      Serial.println("EV_RXCOMPLETE");
      break;
    case EV_LINK_DEAD:
      Serial.println("EV_LINK_DEAD");
      break;
    case EV_LINK_ALIVE:
      Serial.println("EV_LINK_ALIVE");
      break;
    default:
      Serial.println("Unknown event");
      break;
  }
}

void GPS () {
  // This sketch displays information every time a new sentence is correctly encoded.
  while (Serial1.available() > 0)
    if (gps.encode(Serial1.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
    while (true);
  }
}

void displayInfo()
{
  Serial1.begin(GPSBaud);
  Serial.print(F("Location: "));
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }
Serial.println();

  mydata[0]=(int)floor(gps.location.lat());
  mydata[1]=(int)floor((gps.location.lat()-mydata[0])60);
  mydata[2]=(int)floor((gps.location.lat()-mydata[0]-mydata[1]/60.)3600);
  mydata[3]=(int)floor(gps.location.lng());
  mydata[4]=(int)floor((gps.location.lng()-mydata[3])60);
  mydata[5]=(int)floor((gps.location.lng()-mydata[3]-mydata[4]/60.)3600);

  Serial.print("Coordonnées : ");
  Serial.print(gps.location.lat());
  Serial.print(" # ");
  Serial.print(mydata[0]);
  Serial.print("° ");
  Serial.print(mydata[1]);
  Serial.print("' ");
  Serial.print(mydata[2]);
  Serial.println("'' ");
  Serial.print(gps.location.lng());
  Serial.print(" # ");
  Serial.print(mydata[3]);
  Serial.print("° ");
  Serial.print(mydata[4]);
  Serial.print("' ");
  Serial.print(mydata[5]);
  Serial.println("'' ");

}

void setup() {
  Serial.begin(115200);
  //while (!Serial);
//  Serial.println("Starting");
#ifdef VCC_ENABLE
  // For Pinoccio Scout boards
  pinMode(VCC_ENABLE, OUTPUT);
  digitalWrite(VCC_ENABLE, HIGH);
  delay(1000);
#endif

  // LMIC init
  os_init();
  // Reset the MAC state. Session and pending data transfers will be discarded.
  LMIC_reset();
  //LMIC_setClockError(MAX_CLOCK_ERROR * 1/100);
  // Set static session parameters. Instead of dynamically establishing a session
  // by joining the network, precomputed session parameters are be provided.
#ifdef PROGMEM
  // On AVR, these values are stored in flash and only copied to RAM
  // once. Copy them to a temporary buffer here, LMIC_setSession will
  // copy them into a buffer of its own again.
  uint8_t appskey[sizeof(APPSKEY)];
  uint8_t nwkskey[sizeof(NWKSKEY)];
  memcpy_P(appskey, APPSKEY, sizeof(APPSKEY));
  memcpy_P(nwkskey, NWKSKEY, sizeof(NWKSKEY));
  LMIC_setSession (0x1, DEVADDR, nwkskey, appskey);
#else
  // If not running an AVR with PROGMEM, just use the arrays directly
  LMIC_setSession (0x1, DEVADDR, NWKSKEY, APPSKEY);
#endif

  // Disable link check validation
  LMIC_setLinkCheckMode(0);

  // TTN uses SF9 for its RX2 window.
  LMIC.dn2Dr = DR_SF9;

  // Set data rate and transmit power (note: txpow seems to be ignored by the library)
  LMIC_setDrTxpow(DR_SF7, 14);

  // Start job
  do_send(&sendjob);

//  Serial.println(TinyGPSPlus::libraryVersion());
//  Serial.println();
}


void loop() {
  os_runloop_once();
  GPS();
  displayInfo(); 
}

Code Part : LaserBeam , LCD and Fingerprint

Arduino
This code set up the fingerprint module to control the identity of the owner.
The LCD screen tell us if the laser beam can be activate or not.
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Fingerprint.h>

SoftwareSerial mySerial(10, 11);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

#define LED_RED 7
#define LED_GREEN 6
#define PUSH_BUTTON 8

void setup()
{
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_RED, OUTPUT);
  pinMode(PUSH_BUTTON, OUTPUT);
  //Serial.begin(9600);
  lcd.init();                      // initialize the lcd 

  //while (!Serial);  For Yun/Leo/Micro/Zero/...
  delay(100);
  lcd.print("Lancement !");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    //Serial.println("Found fingerprint sensor!");
  } else {
   // Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  finger.getTemplateCount();

  if (finger.templateCount == 0) {
    lcd.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
  }
  else {
    lcd.print("Waiting for valid finger...");
    lcd.print("Sensor contains "); lcd.print(finger.templateCount); lcd.print(" templates");
  }
}
void loop()
{

  getFingerprintID();
  delay(50); 
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      /lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Image taken");/
      break;
    case FINGERPRINT_NOFINGER:
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Veuillez poser");
      lcd.setCursor(0,1);
      lcd.print("votre doigt !");
      digitalWrite(LED_RED,HIGH);
      analogWrite(LED_GREEN, LOW);
      analogWrite(PUSH_BUTTON, LOW);
      return p;
      lcd.print("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      lcd.print("Imaging error");
      return p;
    default:
      lcd.clear();
      lcd.print("OK");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
     /* lcd.setCursor(0,1);
      lcd.print("Comparaison");*/
      break;
    case FINGERPRINT_IMAGEMESS:
      //Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      //Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      //Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      //Serial.println("Could not find fingerprint features");
      return p;
    default:
     lcd.clear();
     digitalWrite(LED_GREEN, HIGH);
     digitalWrite(LED_RED, LOW);
     lcd.setCursor(0,0);
     lcd.print("OK");
     lcd.setCursor(0,1);
     lcd.print("Deverouillage !");
      return p;
  }
// OK converted!
  p = finger.fingerSearch();
  if (p == FINGERPRINT_OK) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Aucun match !");
    return p;
  } else {
    //ICI
    lcd.clear();
    digitalWrite(LED_GREEN, HIGH);
    digitalWrite(LED_RED, LOW);
    digitalWrite(PUSH_BUTTON,HIGH);
    lcd.setCursor(0,0);
    lcd.print("OK");
    lcd.setCursor(0,1);
    lcd.print("Deverouillage !");
    return p;
  }

  // found a match!
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Found ID #"); lcd.print(finger.fingerID);

  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;

  // found a match!
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Found ID #"); lcd.print(finger.fingerID);

  return finger.fingerID;
}

Credits

783 Klj
1 project • 1 follower
Contact
Gianni Dubocquet
0 projects • 1 follower
Contact
Nicolas DAILLY
33 projects • 21 followers
Associated Professor at UniLaSalle - Amiens / Head of the Computer Network Department / Teach Computer and Telecommunication Networks
Contact

Comments

Please log in or sign up to comment.