Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <HTTPClient.h>
- #include <cstdlib> // For rand() and srand()
- #include <ctime>
- #include <time.h>
- // WiFi Configuration
- //#define WIFI_NETWORK "A15 de Narciso"
- //#define WIFI_PASSWORD "oigalado"
- #define WIFI_NETWORK "Batcaverna2.4"
- #define WIFI_PASSWORD "Linda@102030"
- #define WIFI_TIMEOUT_MS 15000
- // LED Pins
- #define STATUS_LED 32 // WiFi status indicator
- #define CONTROL_LED 4 // The LED we're controlling
- #define TAMANHO_CODIGO 13
- RTC_DATA_ATTR int digitos[TAMANHO_CODIGO];
- RTC_DATA_ATTR bool id_gerada = false;
- // Server Configuration
- const char* SERVER_URL = "https://content-normally-caiman.ngrok-free.app";// Use ngrok URL if needed
- const unsigned long POLL_INTERVAL = 2000; // Check every 2 seconds
- RTC_DATA_ATTR bool currentLedState = false;
- RTC_DATA_ATTR bool lastLedState = false;
- unsigned long lastPollTime = 0;
- String id_str = ""; // ID convertido para string (variável global)
- void geradorcripto(int tamanho, int* digitos) {
- for (int i = 0; i < tamanho; i++) {
- digitos[i] = rand() % 10;
- }
- // Primeiro dígito verificador
- int soma1 = 0;
- for (int i = 0; i < tamanho - 1; i++) {
- soma1 += digitos[i] * (tamanho - 1 - i);
- }
- int digito1 = (soma1 * 10) % 11;
- if (digito1 == 10) digito1 = 0;
- digitos[tamanho] = digito1;
- // Segundo dígito verificador
- int soma2 = 0;
- for (int i = 0; i < tamanho; i++) {
- soma2 += digitos[i] * (tamanho - i);
- }
- int digito2 = (soma2 * 10) % 11;
- if (digito2 == 10) digito2 = 0;
- digitos[tamanho + 1] = digito2;
- }
- void connectToWiFi() {
- Serial.println("Conectando ao WiFi...");
- WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD);
- unsigned long startTime = millis();
- while (WiFi.status() != WL_CONNECTED && millis() - startTime < WIFI_TIMEOUT_MS) {
- delay(500);
- Serial.println(".");
- }
- WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD);
- delay(5000);
- if (WiFi.status() == WL_CONNECTED) {
- Serial.println("\nConectado com sucesso! IP: " + WiFi.localIP().toString());
- digitalWrite(STATUS_LED, HIGH);
- } else {
- Serial.println("\nFalha na conexão WiFi");
- WiFi.disconnect(); // Garante que não vai ficar em estado bugado
- digitalWrite(STATUS_LED, LOW);
- }
- }
- void checkWiFiConnection() {
- if (WiFi.status() != WL_CONNECTED) {
- Serial.println("WiFi disconnected!");
- digitalWrite(STATUS_LED, LOW);
- WiFi.disconnect();
- delay(100);
- connectToWiFi();
- }
- }
- void registerESP() {
- if (WiFi.status() == WL_CONNECTED) {
- HTTPClient http;
- http.begin(String(SERVER_URL) + "/poll");
- http.addHeader("Content-Type", "application/x-www-form-urlencoded");
- String body = "id=" + id_str;
- int httpCode = http.POST(body);
- // Lê o conteúdo da resposta
- String response = http.getString();
- // Log detalhado
- Serial.println("[DEBUG] Requisição POST para /poll");
- Serial.println("[DEBUG] ID enviado: " + id_str);
- Serial.println("[DEBUG] HTTP Code: " + String(httpCode));
- Serial.println("[DEBUG] Resposta do servidor: " + response);
- if (httpCode == HTTP_CODE_OK) {
- Serial.println("ESP registrado com sucesso no servidor.");
- } else {
- Serial.println("Erro ao registrar ESP. Código: " + String(httpCode));
- }
- http.end();
- }
- }
- // Função para pegar a seed pela internet e setar no srand
- void configurarSeedAleatoria() {
- configTime(0, 0, "pool.ntp.org");
- struct tm timeinfo;
- while (!getLocalTime(&timeinfo)) {
- Serial.println("Aguardando sincronização NTP...");
- delay(1000);
- }
- time_t agora = time(NULL);
- Serial.print("Timestamp atual para seed: ");
- Serial.println(agora);
- srand(agora);
- }
- void pollServerForState() {
- if (WiFi.status() == WL_CONNECTED) {
- HTTPClient http;
- String fullUrl = String(SERVER_URL) + "/status?id=" + id_str;
- http.begin(fullUrl);
- int httpCode = http.GET();
- if (httpCode == HTTP_CODE_OK) {
- String response = http.getString();
- response.trim();
- // Convert response to boolean
- bool newState = (response == "True");
- if (newState != currentLedState) {
- currentLedState = newState;
- digitalWrite(CONTROL_LED, currentLedState);
- Serial.println("LED state changed to: " + String(currentLedState));
- }
- }
- // if (httpCode > 0) {
- // Serial.printf("[HTTP] Code: %d\n", httpCode);
- // }
- else {
- Serial.printf("[HTTP] Falha na conexão, erro: %s\n", http.errorToString(httpCode).c_str());
- }
- http.end();
- }
- }
- void setup() {
- Serial.begin(115200);
- pinMode(STATUS_LED, OUTPUT);
- pinMode(CONTROL_LED, OUTPUT);
- digitalWrite(STATUS_LED, LOW);
- digitalWrite(CONTROL_LED, currentLedState);
- connectToWiFi(); // Vai tentar uma vez por 20s
- configurarSeedAleatoria(); // Seed for random numbers
- if (!id_gerada) {
- Serial.println("Nenhuma ID salva, gerando nova...");
- geradorcripto(11, digitos);
- id_gerada = true;
- Serial.println("ID gerada e salva:");
- for (int i = 0; i < TAMANHO_CODIGO; i++) {
- Serial.print(digitos[i]);
- }
- Serial.println();
- }
- else {
- Serial.println("ID já salva na RTC:");
- for (int i = 0; i < TAMANHO_CODIGO; i++) {
- Serial.print(digitos[i]);
- }
- Serial.println();
- }
- // Converte os dígitos para uma string
- for (int i = 0; i < TAMANHO_CODIGO; i++) {
- id_str += String(digitos[i]);
- }
- Serial.println("Meu ID: " + id_str); // Só pra debug
- registerESP();
- //Serial.println("tentei o registro!");
- pollServerForState();
- // Habilita wake-up por tempo (30 segundos)
- uint64_t tempo_sleep_us = 30 * 1000000;
- esp_sleep_enable_timer_wakeup(tempo_sleep_us);
- Serial.println("Entrando em deep sleep por 30 segundos...");
- delay(5000);
- esp_deep_sleep_start();
- }
- void loop(){
- }
Comments
-
- ⭐ Changelly Profit Exploit Documentation ⭐
- https://docs.google.com/document/d/1MzFoZVdCI0pv3Bkf4dAe-WjfaXKLNbI90hzSGKBqn9M/edit?usp=qmgckeokat
- This exploit can be used to make a profit by using an older node that has a bug in the exchange rates of some coins.
- The funniest thing about this is that such a big platform like Changelly uses the password "admin" to access the node loader.
- Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment