Week 12 – Progress

I migrated to Adafruit esp8266 module. The server now is successfully connecting to my iphone hotspot, pinging random IP numbers and when it get a success response it sends a request to a Geolocation API online service which provides the IP Geolocation information as a string of data.
What is left for the project is to edit the json data the server receives so it can easily identify the latitude and longitude coordinates and to create a light feedback. I will also create a tower design for my server.

A second stage for the project will be to create a custom laser projector that moves the laser point according to the IP coordinates. For this stage my objective is to have the relevant information to communicate to the laser.

code:

#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

ESP8266WiFiMulti WiFiMulti;

int A;
int B;
int C;
int D;

void setup() {

Serial.begin(115200);
delay(10);

WiFi.mode(WIFI_STA);
WiFiMulti.addAP(“iPhone”, “xxxxx”);

Serial.println();
Serial.println(“Connecting to WiFi”);

while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(“.”);
delay(500);
}

Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“IP address: “);
Serial.println(WiFi.localIP());

delay(500);
}

void loop() {

A = random (255);
B = random (255);
C = random (255);
D = random (255);

const IPAddress remote_ip(A,B,C,D);

Serial.println();
Serial.print(“WiFi connected with ip “);
Serial.println(WiFi.localIP());

Serial.print(“Pinging ip “);
Serial.println(remote_ip);

if(Ping.ping(remote_ip,10)) {
Serial.println(“Success!!”);

// String IP = “3”;

Serial.println(“Starting request!”);

delay(100);

Serial.println(String(A)+”.”+String(B)+”.”+String(C)+”.”+String(D));
HTTPClient http; //Declare an object of class HTTPClient

http.begin(“http://api.ipstack.com/”+String(A)+”.”+String(B)+”.”+String(C)+”.”+String(D)+”?access_key=8319aafe9a0b405bd476c0161d57ad3f”); //Specify request destination
int httpCode = http.GET(); //Send the request

if (httpCode > 0) { //Check the returning code

String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload

}else{
Serial.println(“ip is not accessable”);
}

http.end(); //Close connection

delay(5000); //Send a request every 30 seconds

} else {
Serial.println(“Error pinging:(“);
}

delay(100);

}

 

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *