informatica:arduino:esp32
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
informatica:arduino:esp32 [2021/02/07 20:26] – jose | informatica:arduino:esp32 [2022/10/24 22:12] (current) – jose | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ESP32 | + | ====== Ejemplos: ====== |
+ | **Estación Metereológica: | ||
+ | https:// | ||
+ | ====== Bateria bien montada ====== | ||
+ | https:// | ||
+ | |||
+ | ====== ESP32 ====== | ||
{{: | {{: | ||
- | https:// | + | ====== ARDUINO IDE ====== |
+ | Nos descargamos la última versión de Arduino IDE, tiene que ser por encima de la 1.6 | ||
- | / | + | Descargamos un plugin para poder conectar con esp32: |
- | wget https:// | + | https:// |
- | Abrimos | + | https:// |
+ | |||
+ | Ponemos esta URL en file > preferences > Additional Boards Manager URLs: | ||
+ | https:// | ||
+ | |||
+ | Tarda un ratillo en descargárselas | ||
+ | |||
+ | Ahora vamos a tools > Board: “Arduino Uno” y seleccionamos Boards Manager. Buscamos esp32 y damos a install | ||
+ | |||
+ | En Tools > Board: “Arduino Uno” | ||
+ | |||
+ | Reiniciamos Arduino. Nos aseguramos que python apunte a python3 instalando python-is-python3 | ||
+ | sudo apt install python-is-python3 | ||
+ | |||
+ | Código de ejemplo. Conecta a wifi y nos da la ip. Una vez subido tenemos que reiniciar esp32 (desconectando usb) | ||
< | < | ||
- | # | + | |
- | + | # | |
- | const char* ssid = "yourNetworkName"; | + | |
- | const char* password = "yourNetworkPass"; | + | const char* ssid |
- | + | const char* password = "********"; | |
void setup() { | void setup() { | ||
- | + | Serial.begin(115200); | |
- | Serial.begin(115200); | + | delay(10); |
- | + | Serial.println(' | |
+ | |||
+ | WiFi.begin(ssid, | ||
+ | Serial.print(" | ||
+ | Serial.print(ssid); | ||
+ | |||
+ | while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect | ||
+ | delay(500); | ||
+ | Serial.print(' | ||
+ | } | ||
+ | |||
+ | Serial.println(' | ||
+ | Serial.println(" | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | La salida que nos da es esta: | ||
+ | < | ||
+ | . | ||
+ | |||
+ | Connection established! | ||
+ | IP address: | ||
+ | |||
+ | </ | ||
+ | |||
+ | HAcer petición GET y POST | ||
+ | < | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | const char* ssid = " | ||
+ | const char* password = " | ||
+ | |||
+ | //Your Domain name with URL path or IP address with path | ||
+ | String serverName = " | ||
+ | |||
+ | // the following variables are unsigned longs because the time, measured in | ||
+ | // milliseconds, | ||
+ | unsigned long lastTime = 0; | ||
+ | // Timer set to 10 minutes (600000) | ||
+ | //unsigned long timerDelay = 600000; | ||
+ | // Set timer to 5 seconds (5000) | ||
+ | unsigned long timerDelay = 5000; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(115200); | ||
WiFi.begin(ssid, | WiFi.begin(ssid, | ||
- | + | Serial.println(" | |
- | while (WiFi.status() != WL_CONNECTED) { | + | while(WiFi.status() != WL_CONNECTED) { |
delay(500); | delay(500); | ||
- | Serial.println("Connecting to WiFi.."); | + | Serial.print(" |
} | } | ||
+ | Serial.println("" | ||
+ | Serial.print(" | ||
+ | Serial.println(WiFi.localIP()); | ||
- | Serial.println(" | + | Serial.println(" |
- | + | } | |
+ | |||
+ | void loop() { | ||
+ | //Send an HTTP POST request every 10 minutes | ||
+ | if ((millis() - lastTime) > timerDelay) { | ||
+ | // | ||
+ | if(WiFi.status()== WL_CONNECTED){ | ||
+ | HTTPClient http; | ||
+ | |||
+ | String serverPath = serverName + "? | ||
+ | |||
+ | // Your Domain name with URL path or IP address with path | ||
+ | http.begin(serverPath.c_str()); | ||
+ | |||
+ | // Send HTTP GET request | ||
+ | int httpResponseCode = http.GET(); | ||
+ | |||
+ | if (httpResponseCode> | ||
+ | Serial.print(" | ||
+ | Serial.println(httpResponseCode); | ||
+ | String payload = http.getString(); | ||
+ | Serial.println(payload); | ||
+ | } | ||
+ | else { | ||
+ | Serial.print(" | ||
+ | Serial.println(httpResponseCode); | ||
+ | } | ||
+ | // Free resources | ||
+ | http.end(); | ||
+ | } | ||
+ | else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | lastTime = millis(); | ||
+ | } | ||
} | } | ||
- | |||
- | void loop() {} | ||
</ | </ | ||
Line 91: | Line 201: | ||
Hard resetting via RTS pin... | Hard resetting via RTS pin... | ||
</ | </ | ||
+ | |||
+ | ====== Arduino IDE ====== | ||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | Ponemos esta URL en file > preferences > Additional Boards Manager URLs: | ||
+ | https:// | ||
+ | |||
+ | Ahora vamos a tools > Board: " | ||
+ | |||
+ | En Tools > Board: " | ||
+ | |||
+ | |||
+ | ====== Energia y consumo ====== | ||
+ | https:// | ||
+ | |||
+ | ====== Pantalla e-paper ====== | ||
+ | https:// |
informatica/arduino/esp32.1612729581.txt.gz · Last modified: 2021/02/07 20:26 by jose