Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean datos = false;
- #include <WiFi.h>
- #include <HTTPClient.h>
- const char* ssid = "ssid";
- const char* password = "pass";
- //removed the password and ssid for security, it was there before.
- void setup() {
- pinMode(2, OUTPUT);
- Serial.begin(115200);
- while (! Serial);
- Serial.println("===================================================");
- Serial.println("Welcome to the menu, choose what do you want to do:");
- Serial.println("1º Connect to the Wifi | W");
- Serial.println("2º Scan Wifi | S");
- Serial.println("3º Send data to Website | D");
- Serial.println("===================================================");
- Serial.println("Made by Francine and Javi.");
- Serial.println("===================================================");
- }
- void scanwifi() {
- int n = WiFi.scanNetworks();
- Serial.println("===================================================");
- Serial.println("Scan have been finished.");
- Serial.println("===================================================");
- if (n == 0) {
- Serial.println("===================================================");
- Serial.println("No networks have been found.");
- Serial.println("===================================================");
- }
- else
- {
- Serial.print(n);// imprimir en el puerto serial el # de redes encontradas
- Serial.println(" networks have been found.");
- for (int i = 0; i < n; ++i) {
- // SSID: Nombre de la red; RSSI: Potencia de la red en dBm
- Serial.print(i + 1);//iniciamos en la red # 1...
- Serial.print(": ");
- Serial.print(WiFi.SSID(i));//Imprime el nombre de la red
- Serial.print(" (");
- Serial.print(WiFi.RSSI(i));//Imprime la potencia de la señal en dBm
- Serial.print(")");
- byte encryption = WiFi.encryptionType(i);// en la variable encryption, guardamos el tipo de encriptación de la red
- Serial.print(" Encryption Type: ");
- Serial.println(encryption,HEX);// imprimimos el tipo de encriptación: 2: WPA, 5: WEP, etc.
- delay(10);
- }
- }
- }
- void conectarsealwifi() {
- Serial.begin(115200);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.println("Connecting to WiFi..");
- }
- Serial.println("Connected to the WiFi network");
- delay(1000);
- setup();
- }
- void loop() {
- if (Serial.available()){
- char ch = Serial.read();
- if (ch == 'w' || ch == 'W'){
- conectarsealwifi();
- }
- if (ch == 'S' || ch == 's'){
- scanwifi();
- }
- if (ch == 'd' || ch == 'D'){
- datos = true;
- Serial.println(datos);
- }
- if (datos==true){ // si esta habilitado el sending de datos haz
- //randomN = random(200);
- if(WiFi.status()== WL_CONNECTED){
- digitalWrite(2, HIGH);
- HTTPClient http;
- http.begin("removedtheurl"); //Specify the URL
- int httpCode = http.GET(); //Make the request
- if (httpCode > 0) { //Check for the returning code
- String payload = http.getString();
- Serial.println(httpCode);
- Serial.println(payload);
- Serial.println("===================================================");
- }
- else {
- Serial.println("Error on HTTP request, reminder maybe its cloudflare shit.");
- }
- http.end(); //Free the resources
- digitalWrite(2, LOW);
- }
- delay(2000);
- }
- else
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement