maybe the key point is how to create user1 and user2 binary. others are just review SDK sample.
maybe the key point is how to create user1 and user2 binary. others are just review SDK sample.
Explore... Chat... Share...
Moderator: igrr
#!/usr/bin/python
# -*- coding: cp1252 -*-
#
# this script will push an OTA update to the ESP
#
# use it like: python ota_server.py <ESP_IP_address> <sketch.bin>
#
# NECESARIO PYTHON 2.7
from __future__ import print_function
import socket
import sys
import os
def serve(remoteAddr, filename):
# Parámetros que se pueden cambiar
serverIP = '192.168.1.36'
serverPort = 48266
clientPort = 8266
print('Esperando para la conexion...', file=sys.stderr)
while True:
socket.setdefaulttimeout(1)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = (serverIP, serverPort)
sock.bind(server_address)
sock.listen(1)
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
remote_address = (remoteAddr, clientPort)
content_size = os.path.getsize(filename)
message = ' %d %d\n' % ( serverPort, content_size)
sent = sock2.sendto(message, remote_address)
try:
connection, client_address = sock.accept()
print('Conexion establecida', file=sys.stderr)
try:
f = open(filename, "rb")
while True:
chunk = f.read(1460)
if not chunk:
break
sys.stderr.write('.')
sys.stderr.flush()
connection.settimeout(10)
try:
connection.sendall(chunk)
res = connection.recv(4)
except:
print('\nError subiendo firmware', file=sys.stderr)
connection.close()
f.close()
sock.close()
return 1
print('\nEsperando el resultado...\n', file=sys.stderr)
try:
connection.settimeout(60)
data = connection.recv(32)
print('Resultado: %s' % data, file=sys.stderr)
connection.close()
f.close()
sock.close()
return 0
except:
print('Resultado: sin respuesta!', file=sys.stderr)
connection.close()
f.close()
sock.close()
return 1
finally:
connection.close()
f.close()
return 0
except socket.timeout:
sys.stderr.write('.')
sock.close()
sock2.close()
finally:
pass
def main(args):
try:
return serve(args[1], args[2]) #Introduzca como argumentos la IP del Cliente y la direccion del fichero
except:
print('Introduzca como argumentos la IP del Cliente y la direccion del fichero', file=sys.stderr)
print('Ejemplo: python ota_server.py 192.168.1.35 c:\sketch.bin', file=sys.stderr)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
const char* ssid = "YourSSID";
const char* password = "YourPass";
const char* host = "192.168.1.35"; //IP del servidor OTA
const uint16_t OTAport = 8266;
//Datos de configuración del módulo IP
IPAddress ip(192,168,1,36);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(192,168,1,1);
WiFiUDP OTA;
int i = 0; // Contador usado en varios sitios
void setup() {
Serial.begin(115200);
WiFi.config(ip, gateway, subnet, dns);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
Serial.println();
OTA.begin(OTAport);
delay(100);
Serial.print("Buscando actualizaciones.");
unsigned long millisNo = millis();
while (millis()-millisNo < 10000){
OTAfirmware();
delay(100); // Este delay es necesario para el OTA, sino no funciona
if (i == 5 ){
Serial.print("."); // Contador y escribo un punto 1 de cada 5 veces
i=0;
}
else {
i++;
}
}
Serial.println();
}
void loop() {
//Your loop
}
void OTAfirmware() {
if (OTA.parsePacket()) {
IPAddress remote = OTA.remoteIP();
int port = OTA.parseInt();
int size = OTA.parseInt();
Serial.printf("\nActualizando desde la IP: ");
Serial.print(remote);
Serial.printf(", puerto:%d, tamano del fichero:%d\n", port, size);
uint32_t startTime = millis();
WiFiUDP::stopAll();
if(!Update.begin(size)){
Serial.println("Error actualizando");
return;
}
WiFiClient client;
if (client.connect(remote, port)) {
uint32_t written;
while(!Update.isFinished()){
written = Update.write(client);
if(written > 0) client.print(written, DEC);
}
Serial.setDebugOutput(false);
if(Update.end()){
client.println("OK");
Serial.printf("Actualizacion completada: %lu\nReiniciando...\n", millis() - startTime);
ESP.restart();
} else {
Update.printError(client);
Update.printError(Serial);
}
} else {
Serial.printf("Fallo de conexion: %lu\n", millis() - startTime);
}
}
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]