Real Space Tracker

CODE
#include <ESP8266WiFi.h>
#include <LiquidCrystal.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
HTTPClient http;

const char* ssid = "Your name";
const char* password = "Your code";

const int rs = D5;
const int en = D3;
const int d4 = D2;
const int d5 = D1;
const int d6 = D0;
const int d7 = D4;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

bool isConnected = false;

float targetLat = Your cordinates;
float targetLon = Your cordinates;
float distanceThreshold = 10;

unsigned long lastDetectionTime = 0;
unsigned long notificationInterval = 30000;
unsigned long displayAstronautsTime = 7000;

float lat = 0.0;
float lon = 0.0;

bool isSwitchOn = false;
bool wasSwitchOn = false;
bool displayAstronauts = false;
unsigned long displayStartTime = 0;

void setup() {
  Serial.begin(115200);
  lcd.begin(16, 2);
  lcd.setCursor(2, 0);
  lcd.print("ISS  tracker");
  connectToWiFi();
  pinMode(D6, INPUT_PULLUP);
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    if (!isConnected) {
      lcd.clear();
      lcd.print("Connected!");
      isConnected = true;
    }
    getISSPosition();
    checkIfNearTarget();
    handleSwitch();
    handleDisplayAstronauts();
  } else {
    if (isConnected) {
      lcd.clear();
      lcd.print("Connection Lost");
      isConnected = false;
    }
  }
  delay(1000);
}

void connectToWiFi() {
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("Connected to WiFi");
}

void getISSPosition() {
  if (!isSwitchOn) { // Ενημερώνουμε τις συντεταγμένες μόνο όταν το switch είναι ανενεργό
    WiFiClient client;
    http.begin(client, "http://api.open-notify.org/iss-now.json");
    int httpCode = http.GET();
    if (httpCode == HTTP_CODE_OK) {
      String payload = http.getString();
      deserializeISSPayload(payload);
    } else {
      Serial.println("HTTP request error");
    }
    http.end();
  }
}

void deserializeISSPayload(String payload) {
  StaticJsonDocument<256> doc;
  DeserializationError error = deserializeJson(doc, payload);
  if (error) {
    Serial.println("JSON deserialization error");
    return;
  }
  lat = doc["iss_position"]["latitude"];
  lon = doc["iss_position"]["longitude"];
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Lat: " + String(lat, 6));
  lcd.setCursor(0, 1);
  lcd.print("Lon: " + String(lon, 6));
  lcd.setCursor(11, 1);
  lcd.print("        ");
  lcd.setCursor(11, 0);
  lcd.print("        ");
}

void checkIfNearTarget() {
  float latDiff = abs(targetLat - lat);
  float lonDiff = abs(targetLon - lon);

  if (latDiff <= distanceThreshold && lonDiff <= distanceThreshold) {
    if (millis() - lastDetectionTime > notificationInterval) {
      lcd.setCursor(0, 0);
      lcd.print("   ISS detect  ");
      lcd.setCursor(0, 1);
      lcd.print("                   ");
      lastDetectionTime = millis();
      delay(3000);
    }
  } else {
    lastDetectionTime = 0;
  }
}

void handleSwitch() {
  wasSwitchOn = isSwitchOn;
  isSwitchOn = digitalRead(D6) == LOW;

  if (isSwitchOn && !wasSwitchOn) {
    displayAstronauts = true;
    displayStartTime = millis();
  }
}

void handleDisplayAstronauts() {
  if (displayAstronauts && (millis() - displayStartTime <= displayAstronautsTime)) {
    displayAstronautCount();
  } else {
    displayAstronauts = false;
  }
}

void displayAstronautCount() {
  WiFiClient client;
  http.begin(client, "http://api.open-notify.org/astros.json");
  int httpCode = http.GET();
  if (httpCode == HTTP_CODE_OK) {
    String payload = http.getString();
    DynamicJsonDocument doc(1024);
    DeserializationError error = deserializeJson(doc, payload);
    if (!error) {
      int astronautCount = doc["number"];
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Astronauts: " + String(astronautCount));
      lcd.setCursor(0, 1);
      lcd.print("Speed: 7.706m/s");
    }
  }
  http.end();
}

Hey, thats is a easy project to make. Is a tracking device for the International Space Station at thiw device you can see at real time their cordinates and if you press the button you gonna see how many astronauts is at thiw time in the space and the speed of iss. Here is the part i like the most whn the iss pass above your location you gonna have a notification on the divice. 

 

 

Real Space Tracker | Arduino Project Hub

License
All Rights
Reserved
licensBg
0