Alex
Created November 30, 2023 © GPL3+

Blues Wireless Notecard - GPS Home Setter

This project is designed to use a piezo buzzer to notify individuals if they leave a range around the 'home' they set.

Work in progress20 hours13
Blues Wireless Notecard - GPS Home Setter

Things used in this project

Hardware components

Blues Notecard (Cellular)
Blues Notecard (Cellular)
×1
Blues Swan
Blues Swan
×1
Buzzer, Piezo
Buzzer, Piezo
×1

Software apps and online services

Blues Notehub.io
Blues Notehub.io

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Schematics

Schematic Close-Up

Code

GPS Ping Code

Arduino
#include <Arduino.h>
#include <Notecard.h>
#define usbSerial Serial
#define productUID "yourproductUID"
#define OnBoardButton USER_BTN

Notecard notecard;
int BUZZER_PIN = 11;


volatile bool homeisset = false;
double homelat = 0;
double homelon = 0;
double lat =0;
double lon = 0;
double maxrange = 2/(10^10);

void setHome(){     // Uses the notecard to set a location as "Home". Beeps the buzzer when it is done.
  homeisset = true;
}


// the setup function runs once when you press reset or power the board
void setup()
{
  tone(BUZZER_PIN,15);
  delay(500);
  noTone(BUZZER_PIN);
delay(2500);
usbSerial.begin(115200);
notecard.begin();
notecard.setDebugOutputStream(usbSerial);


J *resetreq = notecard.newRequest("card.restore");
JAddBoolToObject(resetreq,"delete",true);
notecard.sendRequest(resetreq);


J *req1 = notecard.newRequest("hub.set");
JAddStringToObject(req1, "product", productUID);
JAddStringToObject(req1, "mode", "periodic");
JAddNumberToObject(req1, "outbound", 30);
notecard.sendRequest(req1);

J *req2 = notecard.newRequest("card.location.mode");
  JAddStringToObject(req2, "mode", "periodic");
  JAddNumberToObject(req2, "seconds", 180);
notecard.sendRequest(req2);

J *req3 = notecard.newRequest("card.location.track");
  JAddBoolToObject(req3, "start", true);
  JAddBoolToObject(req3, "heartbeat", true);
  JAddNumberToObject(req3, "hours", -4);
  notecard.sendRequest(req3);

pinMode(BUZZER_PIN,OUTPUT);
attachInterrupt(digitalPinToInterrupt(OnBoardButton), setHome, FALLING);

}



void loop()
{
    if (homeisset) {
      {
      // Set the location mode to "continuous" mode to force the
      // Notecard to take an immediate GPS/GNSS reading.
      J *req4 = notecard.newRequest("card.location.mode");
      JAddStringToObject(req4, "mode", "continuous");
      notecard.sendRequest(req4);
      }

    J *req5 = notecard.newRequest("card.location");
    J *rsp1 = notecard.requestAndResponse(req5);
    Serial.println("Location:");

    while (homelat == 0) {
      Serial.println("No location found yet...");
    J *req6 = notecard.newRequest("card.location");
    J *rsp2 = notecard.requestAndResponse(req6);
    Serial.println("Location:");
    homelat = JGetNumber(rsp2, "lat");
    homelon = JGetNumber(rsp2, "lon");
      delay (10000);
    }

    tone(BUZZER_PIN,15);
    delay(500);
    noTone(BUZZER_PIN);

    J *req7 = notecard.newRequest("card.location.mode");
    JAddStringToObject(req7, "mode", "periodic");
    JAddNumberToObject(req7, "seconds", 180);
    notecard.sendRequest(req7);

J *req8 = notecard.newRequest("card.location.track");
  JAddBoolToObject(req8, "start", true);
  JAddBoolToObject(req8, "heartbeat", true);
  // JAddStringToObject(req3, "file", "locations.db");
  JAddNumberToObject(req8, "hours", -4);
  notecard.sendRequest(req8);
      
    homeisset = false;
  }
  else {

  
  J *req9 = notecard.newRequest("card.location");
  J *rsp5 = notecard.requestAndResponse(req9);

  
  J *req10 = notecard.newRequest("card.location.mode");
  J *rsp6 = notecard.requestAndResponse(req10);
  lat = JGetNumber(rsp6, "lat");
  lon = JGetNumber(rsp6, "lon");

  delay(4000);


  if (((homelat - lat) > (maxrange)) || ((homelon - lon) > (maxrange))){
    tone(BUZZER_PIN,5);
    delay(500);
    noTone(BUZZER_PIN);
    delay(500);
    } 
  }
}

Credits

Alex

Alex

1 project • 0 followers

Comments