mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-13 13:01:55 +03:00
mDNS, platform and espota.py changes for IDE Upload
mDNS responds with more TXT properties platform change to support OTA functions espota.py added authentication parameter IDE branch: https://github.com/me-no-dev/Arduino-1/tree/esp8266-ota
This commit is contained in:
@ -85,7 +85,7 @@ static const IPAddress MDNS_MULTICAST_ADDR(224, 0, 0, 251);
|
|||||||
static const int MDNS_MULTICAST_TTL = 1;
|
static const int MDNS_MULTICAST_TTL = 1;
|
||||||
static const int MDNS_PORT = 5353;
|
static const int MDNS_PORT = 5353;
|
||||||
|
|
||||||
MDNSResponder::MDNSResponder() : _conn(0) { _services = 0; }
|
MDNSResponder::MDNSResponder() : _conn(0) { _services = 0; _arduinoAuth = false; }
|
||||||
MDNSResponder::~MDNSResponder() {}
|
MDNSResponder::~MDNSResponder() {}
|
||||||
|
|
||||||
bool MDNSResponder::begin(const char* domain){
|
bool MDNSResponder::begin(const char* domain){
|
||||||
@ -101,8 +101,6 @@ bool MDNSResponder::begin(const char* domain){
|
|||||||
_hostName[i] = tolower(domain[i]);
|
_hostName[i] = tolower(domain[i]);
|
||||||
_hostName[n] = '\0';
|
_hostName[n] = '\0';
|
||||||
|
|
||||||
os_strcpy(_boardName, ARDUINO_BOARD);
|
|
||||||
|
|
||||||
// Open the MDNS socket if it isn't already open.
|
// Open the MDNS socket if it isn't already open.
|
||||||
if (!_conn) {
|
if (!_conn) {
|
||||||
uint32_t ourIp = _getOurIp();
|
uint32_t ourIp = _getOurIp();
|
||||||
@ -372,7 +370,10 @@ void MDNSResponder::_parsePacket(){
|
|||||||
return _reply(responseMask, (serviceName), (protoName), servicePort);
|
return _reply(responseMask, (serviceName), (protoName), servicePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MDNSResponder::enableArduino(uint16_t port, bool auth){
|
||||||
|
_arduinoAuth = auth;
|
||||||
|
addService("arduino", "tcp", port);
|
||||||
|
}
|
||||||
|
|
||||||
void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint16_t port){
|
void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint16_t port){
|
||||||
int i;
|
int i;
|
||||||
@ -439,24 +440,53 @@ void MDNSResponder::_reply(uint8_t replyMask, char * service, char *proto, uint1
|
|||||||
|
|
||||||
// TXT Response
|
// TXT Response
|
||||||
if(replyMask & 0x4){
|
if(replyMask & 0x4){
|
||||||
if(replyMask & 0x8){//send the name
|
if(replyMask & 0x8){
|
||||||
uint8_t txtHead[2] = {0xC0, (uint8_t)(36 + serviceLen)};
|
uint8_t txtHead[10] = {
|
||||||
_conn->append(reinterpret_cast<const char*>(txtHead), 2);
|
0xC0, (uint8_t)(36 + serviceLen),//send the name
|
||||||
|
0x00, 0x10, //Type TXT
|
||||||
|
0x80, 0x01, //Class IN, with cache flush
|
||||||
|
0x00, 0x00, 0x11, 0x94, //TTL 4500
|
||||||
|
};
|
||||||
|
_conn->append(reinterpret_cast<const char*>(txtHead), 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t boardNameLen = os_strlen(_boardName);
|
if(strcmp(reinterpret_cast<const char*>("arduino"), service) == 0){
|
||||||
|
//arduino
|
||||||
uint8_t txt[24] = {
|
//arduino service dependance should be removed and properties abstracted
|
||||||
0x00, 0x10, //Type TXT
|
const char *tcpCheckExtra = "tcp_check=no";
|
||||||
0x80, 0x01, //Class IN, with cache flush
|
uint8_t tcpCheckExtraLen = os_strlen(tcpCheckExtra);
|
||||||
0x00, 0x00, 0x11, 0x94, //TTL 4500
|
|
||||||
0x00, 0x0e, //DATA LEN
|
const char *sshUploadExtra = "ssh_upload=no";
|
||||||
(uint8_t)(6 + boardNameLen), //strlen(board=) + strlen(boardName)
|
uint8_t sshUploadExtraLen = os_strlen(sshUploadExtra);
|
||||||
0x62, 0x6f, 0x61, 0x72, 0x64, 0x3d //board=
|
|
||||||
};
|
char boardName[64];
|
||||||
_conn->append(reinterpret_cast<const char*>(txt), 17);
|
const char *boardExtra = "board=";
|
||||||
_conn->append(reinterpret_cast<const char*>(_boardName), boardNameLen);
|
os_sprintf(boardName, "%s%s\0", boardExtra, ARDUINO_BOARD);
|
||||||
|
uint8_t boardNameLen = os_strlen(boardName);
|
||||||
|
|
||||||
|
char authUpload[16];
|
||||||
|
const char *authUploadExtra = "auth_upload=";
|
||||||
|
os_sprintf(authUpload, "%s%s\0", authUploadExtra, reinterpret_cast<const char*>((_arduinoAuth)?"yes":"no"));
|
||||||
|
uint8_t authUploadLen = os_strlen(authUpload);
|
||||||
|
|
||||||
|
uint16_t textDataLen = (1 + boardNameLen) + (1 + tcpCheckExtraLen) + (1 + sshUploadExtraLen) + (1 + authUploadLen);
|
||||||
|
uint8_t txt[2] = {(uint8_t)(textDataLen >> 8), (uint8_t)(textDataLen)}; //DATA LEN
|
||||||
|
_conn->append(reinterpret_cast<const char*>(txt), 2);
|
||||||
|
|
||||||
|
_conn->append(reinterpret_cast<const char*>(&boardNameLen), 1);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(boardName), boardNameLen);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(&authUploadLen), 1);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(authUpload), authUploadLen);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(&tcpCheckExtraLen), 1);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(tcpCheckExtra), tcpCheckExtraLen);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(&sshUploadExtraLen), 1);
|
||||||
|
_conn->append(reinterpret_cast<const char*>(sshUploadExtra), sshUploadExtraLen);
|
||||||
|
} else {
|
||||||
|
//not arduino
|
||||||
|
//we should figure out an API so TXT properties can be added for services
|
||||||
|
uint8_t txt[2] = {0,0};
|
||||||
|
_conn->append(reinterpret_cast<const char*>(txt), 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SRV Response
|
// SRV Response
|
||||||
|
@ -77,12 +77,14 @@ public:
|
|||||||
void addService(String service, String proto, uint16_t port){
|
void addService(String service, String proto, uint16_t port){
|
||||||
addService(service.c_str(), proto.c_str(), port);
|
addService(service.c_str(), proto.c_str(), port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void enableArduino(uint16_t port, bool auth=false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct MDNSService * _services;
|
struct MDNSService * _services;
|
||||||
UdpContext* _conn;
|
UdpContext* _conn;
|
||||||
char _hostName[128];
|
char _hostName[128];
|
||||||
char _boardName[64];
|
bool _arduinoAuth;
|
||||||
|
|
||||||
uint32_t _getOurIp();
|
uint32_t _getOurIp();
|
||||||
uint16_t _getServicePort(char *service, char *proto);
|
uint16_t _getServicePort(char *service, char *proto);
|
||||||
|
@ -17,6 +17,7 @@ MDNS KEYWORD1
|
|||||||
begin KEYWORD2
|
begin KEYWORD2
|
||||||
update KEYWORD2
|
update KEYWORD2
|
||||||
addService KEYWORD2
|
addService KEYWORD2
|
||||||
|
enableArduino KEYWORD2
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
|
14
platform.txt
14
platform.txt
@ -92,18 +92,18 @@ recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).*
|
|||||||
tools.esptool.cmd=esptool
|
tools.esptool.cmd=esptool
|
||||||
tools.esptool.cmd.windows=esptool.exe
|
tools.esptool.cmd.windows=esptool.exe
|
||||||
tools.esptool.path={runtime.platform.path}/tools/esptool
|
tools.esptool.path={runtime.platform.path}/tools/esptool
|
||||||
#runtime.tools.esptool.path
|
tools.esptool.network_cmd=python
|
||||||
|
tools.esptool.network_cmd.windows=python.exe
|
||||||
tools.mkspiffs.cmd=mkspiffs
|
|
||||||
tools.mkspiffs.cmd.windows=mkspiffs.exe
|
|
||||||
tools.mkspiffs.path={runtime.platform.path}/tools/mkspiffs
|
|
||||||
#runtime.tools.mkspiffs.path
|
|
||||||
|
|
||||||
tools.esptool.upload.protocol=esp
|
tools.esptool.upload.protocol=esp
|
||||||
tools.esptool.upload.params.verbose=-vv
|
tools.esptool.upload.params.verbose=-vv
|
||||||
tools.esptool.upload.params.quiet=
|
tools.esptool.upload.params.quiet=
|
||||||
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"
|
tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}.bin"
|
||||||
tools.esptool.network.pattern=python "{path}/espota.py" -i "{serial.port}" -p "{network.port}" -f "{build.path}/{build.project_name}.bin"
|
tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin"
|
||||||
|
|
||||||
|
tools.mkspiffs.cmd=mkspiffs
|
||||||
|
tools.mkspiffs.cmd.windows=mkspiffs.exe
|
||||||
|
tools.mkspiffs.path={runtime.platform.path}/tools/mkspiffs
|
||||||
|
|
||||||
tools.espota.cmd=python
|
tools.espota.cmd=python
|
||||||
tools.espota.cmd.windows=python.exe
|
tools.espota.cmd.windows=python.exe
|
||||||
|
@ -29,7 +29,7 @@ FLASH = 0
|
|||||||
SPIFFS = 100
|
SPIFFS = 100
|
||||||
|
|
||||||
|
|
||||||
def serve(remoteAddr, remotePort, filename, command = FLASH):
|
def serve(remoteAddr, remotePort, password, filename, command = FLASH):
|
||||||
# Create a TCP/IP socket
|
# Create a TCP/IP socket
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
serverPort = 48266
|
serverPort = 48266
|
||||||
@ -44,7 +44,7 @@ def serve(remoteAddr, remotePort, filename, command = FLASH):
|
|||||||
|
|
||||||
content_size = os.path.getsize(filename)
|
content_size = os.path.getsize(filename)
|
||||||
logging.info('Upload size: %d', content_size)
|
logging.info('Upload size: %d', content_size)
|
||||||
message = '%d %d %d\n' % (command, serverPort, content_size)
|
message = '%s %d %d %d\n' % (password, command, serverPort, content_size)
|
||||||
|
|
||||||
# Wait for a connection
|
# Wait for a connection
|
||||||
logging.info('Sending invitation to: %s', remoteAddr)
|
logging.info('Sending invitation to: %s', remoteAddr)
|
||||||
@ -131,6 +131,16 @@ def parser():
|
|||||||
)
|
)
|
||||||
parser.add_option_group(group)
|
parser.add_option_group(group)
|
||||||
|
|
||||||
|
# auth
|
||||||
|
group = optparse.OptionGroup(parser, "Authentication")
|
||||||
|
group.add_option("-a", "--auth",
|
||||||
|
dest = "auth",
|
||||||
|
help = "Set authentication password.",
|
||||||
|
action = "store",
|
||||||
|
default = ""
|
||||||
|
)
|
||||||
|
parser.add_option_group(group)
|
||||||
|
|
||||||
# image
|
# image
|
||||||
group = optparse.OptionGroup(parser, "Image")
|
group = optparse.OptionGroup(parser, "Image")
|
||||||
group.add_option("-f", "--file",
|
group.add_option("-f", "--file",
|
||||||
@ -190,7 +200,7 @@ def main(args):
|
|||||||
command = SPIFFS
|
command = SPIFFS
|
||||||
# end if
|
# end if
|
||||||
|
|
||||||
return serve(options.esp_ip, options.esp_port, options.image, command)
|
return serve(options.esp_ip, options.esp_port, options.auth, options.image, command)
|
||||||
# end main
|
# end main
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user