mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
Merge remote-tracking branch 'remotes/esp8266/esp8266' into esp8266
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiUDP.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <ESP8266SSDP.h>
|
||||
|
||||
@ -12,11 +11,11 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println("Starting WiFi...");
|
||||
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
||||
|
||||
|
||||
Serial.printf("Starting HTTP...\n");
|
||||
HTTP.on("/index.html", HTTP_GET, [](){
|
||||
HTTP.send(200, "text/plain", "Hello World!");
|
||||
@ -25,7 +24,7 @@ void setup() {
|
||||
SSDP.schema(HTTP.client());
|
||||
});
|
||||
HTTP.begin();
|
||||
|
||||
|
||||
Serial.printf("Starting SSDP...\n");
|
||||
SSDP.setSchemaURL("description.xml");
|
||||
SSDP.setHTTPPort(80);
|
||||
@ -38,7 +37,7 @@ void setup() {
|
||||
SSDP.setManufacturer("Royal Philips Electronics");
|
||||
SSDP.setManufacturerURL("http://www.philips.com");
|
||||
SSDP.begin();
|
||||
|
||||
|
||||
Serial.printf("Ready!\n");
|
||||
} else {
|
||||
Serial.printf("WiFi Failed\n");
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
/*
|
||||
SDWebServer - Example WebServer with SD Card backend for esp8266
|
||||
|
||||
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
|
||||
This file is part of the ESP8266WebServer library for Arduino environment.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
@ -23,7 +23,7 @@
|
||||
File extensions with more than 3 charecters are not supported by the SD Library
|
||||
File Names longer than 8 charecters will be truncated by the SD library, so keep filenames shorter
|
||||
index.htm is the default index (works on subfolders as well)
|
||||
|
||||
|
||||
upload the contents of SdRoot to the root of the SDcard and access the editor by going to http://esp8266sd.local/edit
|
||||
|
||||
*/
|
||||
@ -38,9 +38,8 @@
|
||||
|
||||
const char* ssid = "**********";
|
||||
const char* password = "**********";
|
||||
const char* hostname = "esp8266sd";
|
||||
const char* host = "esp8266sd";
|
||||
|
||||
MDNSResponder mdns;
|
||||
ESP8266WebServer server(80);
|
||||
|
||||
static bool hasSD = false;
|
||||
@ -62,7 +61,7 @@ void returnFail(String msg) {
|
||||
bool loadFromSdCard(String path){
|
||||
String dataType = "text/plain";
|
||||
if(path.endsWith("/")) path += "index.htm";
|
||||
|
||||
|
||||
if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
|
||||
else if(path.endsWith(".htm")) dataType = "text/html";
|
||||
else if(path.endsWith(".css")) dataType = "text/css";
|
||||
@ -74,7 +73,7 @@ bool loadFromSdCard(String path){
|
||||
else if(path.endsWith(".xml")) dataType = "text/xml";
|
||||
else if(path.endsWith(".pdf")) dataType = "application/pdf";
|
||||
else if(path.endsWith(".zip")) dataType = "application/zip";
|
||||
|
||||
|
||||
File dataFile = SD.open(path.c_str());
|
||||
if(dataFile.isDirectory()){
|
||||
path += "/index.htm";
|
||||
@ -84,9 +83,9 @@ bool loadFromSdCard(String path){
|
||||
|
||||
if (!dataFile)
|
||||
return false;
|
||||
|
||||
|
||||
if (server.hasArg("download")) dataType = "application/octet-stream";
|
||||
|
||||
|
||||
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
|
||||
DBG_OUTPUT_PORT.println("Sent less data than expected!");
|
||||
}
|
||||
@ -152,7 +151,7 @@ void handleDelete(){
|
||||
void handleCreate(){
|
||||
if(server.args() == 0) return returnFail("BAD ARGS");
|
||||
String path = server.arg(0);
|
||||
if(path == "/" || SD.exists((char *)path.c_str())) {
|
||||
if(path == "/" || SD.exists((char *)path.c_str())) {
|
||||
returnFail("BAD PATH");
|
||||
return;
|
||||
}
|
||||
@ -183,7 +182,7 @@ void printDirectory() {
|
||||
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
|
||||
server.send(200, "text/json", "");
|
||||
WiFiClient client = server.client();
|
||||
|
||||
|
||||
server.sendContent("[");
|
||||
for (int cnt = 0; true; ++cnt) {
|
||||
File entry = dir.openNextFile();
|
||||
@ -244,25 +243,26 @@ void setup(void){
|
||||
}
|
||||
DBG_OUTPUT_PORT.print("Connected! IP address: ");
|
||||
DBG_OUTPUT_PORT.println(WiFi.localIP());
|
||||
|
||||
if (mdns.begin(hostname, WiFi.localIP())) {
|
||||
|
||||
if (MDNS.begin(host)) {
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
DBG_OUTPUT_PORT.println("MDNS responder started");
|
||||
DBG_OUTPUT_PORT.print("You can now connect to http://");
|
||||
DBG_OUTPUT_PORT.print(hostname);
|
||||
DBG_OUTPUT_PORT.print(host);
|
||||
DBG_OUTPUT_PORT.println(".local");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
server.on("/list", HTTP_GET, printDirectory);
|
||||
server.on("/edit", HTTP_DELETE, handleDelete);
|
||||
server.on("/edit", HTTP_PUT, handleCreate);
|
||||
server.on("/edit", HTTP_POST, [](){ returnOK(); });
|
||||
server.onNotFound(handleNotFound);
|
||||
server.onFileUpload(handleFileUpload);
|
||||
|
||||
|
||||
server.begin();
|
||||
DBG_OUTPUT_PORT.println("HTTP server started");
|
||||
|
||||
|
||||
if (SD.begin(SS)){
|
||||
DBG_OUTPUT_PORT.println("SD Card initialized.");
|
||||
hasSD = true;
|
||||
|
@ -108,20 +108,26 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
|
||||
|
||||
if (!isForm){
|
||||
if (searchStr != "") searchStr += '&';
|
||||
String bodyLine = client.readStringUntil('\r');
|
||||
//some clients send headers first and data after (like we do)
|
||||
//give them a chance
|
||||
int tries = 100;//100ms max wait
|
||||
while(!client.available() && tries--)delay(1);
|
||||
size_t plainLen = client.available();
|
||||
char *plainBuf = (char*)malloc(plainLen+1);
|
||||
client.readBytes(plainBuf, plainLen);
|
||||
plainBuf[plainLen] = '\0';
|
||||
#ifdef DEBUG
|
||||
DEBUG_OUTPUT.print("Plain: ");
|
||||
DEBUG_OUTPUT.println(bodyLine);
|
||||
DEBUG_OUTPUT.println(plainBuf);
|
||||
#endif
|
||||
if(bodyLine.startsWith("{") || bodyLine.startsWith("[") || bodyLine.indexOf('=') == -1){
|
||||
if(plainBuf[0] == '{' || plainBuf[0] == '[' || strstr(plainBuf, "=") == NULL){
|
||||
//plain post json or other data
|
||||
searchStr += "plain=";
|
||||
searchStr += bodyLine;
|
||||
searchStr += client.readString();
|
||||
searchStr += plainBuf;
|
||||
} else {
|
||||
searchStr += bodyLine;
|
||||
client.readStringUntil('\n');
|
||||
searchStr += plainBuf;
|
||||
}
|
||||
free(plainBuf);
|
||||
}
|
||||
_parseArguments(searchStr);
|
||||
if (isForm){
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
/*
|
||||
ESP8266WiFi.cpp - WiFi library for esp8266
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
@ -158,7 +158,7 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
|
||||
|
||||
wifi_station_dhcpc_stop();
|
||||
wifi_set_ip_info(STATION_IF, &info);
|
||||
|
||||
|
||||
_useStaticIp = true;
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ void ESP8266WiFiClass::config(IPAddress local_ip, IPAddress gateway, IPAddress s
|
||||
ip_addr_t d;
|
||||
d.addr = static_cast<uint32_t>(dns);
|
||||
dns_setserver(0,&d);
|
||||
|
||||
|
||||
_useStaticIp = true;
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ void ESP8266WiFiClass::softAP(const char* ssid)
|
||||
{
|
||||
softAP(ssid, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden)
|
||||
{
|
||||
@ -314,7 +314,7 @@ uint8_t* ESP8266WiFiClass::softAPmacAddress(uint8_t* mac)
|
||||
wifi_get_macaddr(SOFTAP_IF, mac);
|
||||
return mac;
|
||||
}
|
||||
|
||||
|
||||
String ESP8266WiFiClass::softAPmacAddress(void)
|
||||
{
|
||||
uint8_t mac[6];
|
||||
@ -336,7 +336,7 @@ IPAddress ESP8266WiFiClass::softAPIP()
|
||||
{
|
||||
struct ip_info ip;
|
||||
wifi_get_ip_info(SOFTAP_IF, &ip);
|
||||
return IPAddress(ip.ip.addr);
|
||||
return IPAddress(ip.ip.addr);
|
||||
}
|
||||
|
||||
IPAddress ESP8266WiFiClass::subnetMask()
|
||||
@ -400,7 +400,7 @@ void ESP8266WiFiClass::_scanDone(void* result, int status)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
int i = 0;
|
||||
bss_info_head_t* head = reinterpret_cast<bss_info_head_t*>(result);
|
||||
|
||||
@ -477,7 +477,7 @@ int8_t ESP8266WiFiClass::scanNetworks(bool async)
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
|
||||
scanDelete();
|
||||
|
||||
struct scan_config config;
|
||||
@ -641,7 +641,7 @@ int ESP8266WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
|
||||
esp_yield();
|
||||
// will return here when dns_found_callback fires
|
||||
}
|
||||
|
||||
|
||||
return (aResult != 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
@ -702,7 +702,7 @@ bool ESP8266WiFiClass::beginWPSConfig(void) {
|
||||
|
||||
disconnect();
|
||||
|
||||
DEBUGV("wps begin: %d\n", wps_type);
|
||||
DEBUGV("wps begin\n");
|
||||
|
||||
if(!wifi_wps_disable()) {
|
||||
DEBUGV("wps disable faild\n");
|
||||
@ -751,7 +751,7 @@ void ESP8266WiFiClass::beginSmartConfig()
|
||||
_smartConfigStarted = true;
|
||||
_smartConfigDone = false;
|
||||
|
||||
//SC_TYPE_ESPTOUCH use ESPTOUCH for smartconfig, or use SC_TYPE_AIRKISS for AIRKISS
|
||||
//SC_TYPE_ESPTOUCH use ESPTOUCH for smartconfig, or use SC_TYPE_AIRKISS for AIRKISS
|
||||
smartconfig_start(reinterpret_cast<sc_callback_t>(&ESP8266WiFiClass::_smartConfigCallback), 1);
|
||||
}
|
||||
|
||||
@ -777,7 +777,7 @@ void ESP8266WiFiClass::_smartConfigCallback(uint32_t st, void* result)
|
||||
sc_status status = (sc_status) st;
|
||||
if (status == SC_STATUS_LINK) {
|
||||
station_config* sta_conf = reinterpret_cast<station_config*>(result);
|
||||
|
||||
|
||||
wifi_station_set_config(sta_conf);
|
||||
wifi_station_disconnect();
|
||||
wifi_station_connect();
|
||||
@ -826,7 +826,7 @@ void ESP8266WiFiClass::printDiag(Print& p)
|
||||
|
||||
static struct station_config conf;
|
||||
wifi_station_get_config(&conf);
|
||||
|
||||
|
||||
const char* ssid = reinterpret_cast<const char*>(conf.ssid);
|
||||
p.print("SSID (");
|
||||
p.print(strlen(ssid));
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
/*
|
||||
WiFiClient.cpp - TCP/IP client for esp8266, mostly compatible
|
||||
with Arduino WiFi shield library
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
#define LWIP_INTERNAL
|
||||
|
||||
extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#include "include/wl_definitions.h"
|
||||
#include "osapi.h"
|
||||
@ -48,7 +48,7 @@ template<>
|
||||
WiFiClient* SList<WiFiClient>::_s_first = 0;
|
||||
|
||||
|
||||
WiFiClient::WiFiClient()
|
||||
WiFiClient::WiFiClient()
|
||||
: _client(0)
|
||||
{
|
||||
WiFiClient::_add(this);
|
||||
@ -78,7 +78,7 @@ WiFiClient::WiFiClient(const WiFiClient& other)
|
||||
WiFiClient& WiFiClient::operator=(const WiFiClient& other)
|
||||
{
|
||||
if (_client)
|
||||
_client->unref();
|
||||
_client->unref();
|
||||
_client = other._client;
|
||||
if (_client)
|
||||
_client->ref();
|
||||
@ -86,7 +86,7 @@ WiFiClient& WiFiClient::operator=(const WiFiClient& other)
|
||||
}
|
||||
|
||||
|
||||
int WiFiClient::connect(const char* host, uint16_t port)
|
||||
int WiFiClient::connect(const char* host, uint16_t port)
|
||||
{
|
||||
IPAddress remote_addr;
|
||||
if (WiFi.hostByName(host, remote_addr))
|
||||
@ -96,7 +96,7 @@ int WiFiClient::connect(const char* host, uint16_t port)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WiFiClient::connect(IPAddress ip, uint16_t port)
|
||||
int WiFiClient::connect(IPAddress ip, uint16_t port)
|
||||
{
|
||||
ip_addr_t addr;
|
||||
addr.addr = ip;
|
||||
@ -162,12 +162,12 @@ bool WiFiClient::getNoDelay() {
|
||||
return _client->getNoDelay();
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(uint8_t b)
|
||||
size_t WiFiClient::write(uint8_t b)
|
||||
{
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(const uint8_t *buf, size_t size)
|
||||
size_t WiFiClient::write(const uint8_t *buf, size_t size)
|
||||
{
|
||||
if (!_client || !size)
|
||||
{
|
||||
@ -179,19 +179,18 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
|
||||
|
||||
int WiFiClient::available()
|
||||
{
|
||||
int result = 0;
|
||||
if (!_client)
|
||||
return false;
|
||||
|
||||
if (_client) {
|
||||
result = _client->getSize();
|
||||
}
|
||||
int result = _client->getSize();
|
||||
|
||||
if (!result) {
|
||||
optimistic_yield();
|
||||
optimistic_yield(100);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int WiFiClient::read()
|
||||
int WiFiClient::read()
|
||||
{
|
||||
if (!available())
|
||||
return -1;
|
||||
@ -200,12 +199,12 @@ int WiFiClient::read()
|
||||
}
|
||||
|
||||
|
||||
int WiFiClient::read(uint8_t* buf, size_t size)
|
||||
int WiFiClient::read(uint8_t* buf, size_t size)
|
||||
{
|
||||
return (int) _client->read(reinterpret_cast<char*>(buf), size);
|
||||
}
|
||||
|
||||
int WiFiClient::peek()
|
||||
int WiFiClient::peek()
|
||||
{
|
||||
if (!available())
|
||||
return -1;
|
||||
@ -213,13 +212,13 @@ int WiFiClient::peek()
|
||||
return _client->peek();
|
||||
}
|
||||
|
||||
void WiFiClient::flush()
|
||||
void WiFiClient::flush()
|
||||
{
|
||||
if (_client)
|
||||
_client->flush();
|
||||
}
|
||||
|
||||
void WiFiClient::stop()
|
||||
void WiFiClient::stop()
|
||||
{
|
||||
if (!_client)
|
||||
return;
|
||||
@ -228,7 +227,7 @@ void WiFiClient::stop()
|
||||
_client = 0;
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::connected()
|
||||
uint8_t WiFiClient::connected()
|
||||
{
|
||||
if (!_client)
|
||||
return 0;
|
||||
@ -236,14 +235,14 @@ uint8_t WiFiClient::connected()
|
||||
return _client->state() == ESTABLISHED || available();
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::status()
|
||||
uint8_t WiFiClient::status()
|
||||
{
|
||||
if (!_client)
|
||||
return CLOSED;
|
||||
return _client->state();
|
||||
}
|
||||
|
||||
WiFiClient::operator bool()
|
||||
WiFiClient::operator bool()
|
||||
{
|
||||
return _client != 0;
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
/*
|
||||
WiFiServer.cpp - TCP/IP server for esp8266, mostly compatible
|
||||
with Arduino WiFi shield library
|
||||
|
||||
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
@ -99,7 +99,7 @@ WiFiClient WiFiServer::available(byte* status)
|
||||
return result;
|
||||
}
|
||||
|
||||
optimistic_yield();
|
||||
optimistic_yield(1000);
|
||||
|
||||
return WiFiClient();
|
||||
}
|
||||
@ -161,4 +161,3 @@ void WiFiServer::_s_discard(void* server, ClientContext* ctx)
|
||||
{
|
||||
reinterpret_cast<WiFiServer*>(server)->_discard(ctx);
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
|
||||
#define LWIP_INTERNAL
|
||||
#include <functional>
|
||||
|
||||
extern "C"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "include/wl_definitions.h"
|
||||
#include "osapi.h"
|
||||
@ -45,7 +45,7 @@ template<>
|
||||
WiFiUDP* SList<WiFiUDP>::_s_first = 0;
|
||||
|
||||
/* Constructor */
|
||||
WiFiUDP::WiFiUDP() : _ctx(0)
|
||||
WiFiUDP::WiFiUDP() : _ctx(0)
|
||||
{
|
||||
WiFiUDP::_add(this);
|
||||
}
|
||||
@ -74,7 +74,7 @@ WiFiUDP::~WiFiUDP()
|
||||
}
|
||||
|
||||
/* Start WiFiUDP socket, listening at local port */
|
||||
uint8_t WiFiUDP::begin(uint16_t port)
|
||||
uint8_t WiFiUDP::begin(uint16_t port)
|
||||
{
|
||||
if (_ctx) {
|
||||
_ctx->unref();
|
||||
@ -94,7 +94,7 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
|
||||
_ctx->unref();
|
||||
_ctx = 0;
|
||||
}
|
||||
|
||||
|
||||
ip_addr_t ifaddr;
|
||||
ifaddr.addr = (uint32_t) interfaceAddr;
|
||||
ip_addr_t multicast_addr;
|
||||
@ -123,7 +123,9 @@ int WiFiUDP::available() {
|
||||
}
|
||||
|
||||
if (!result) {
|
||||
optimistic_yield();
|
||||
// yielding here will not make more data "available",
|
||||
// but it will prevent the system from going into WDT reset
|
||||
optimistic_yield(1000);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -161,7 +163,7 @@ int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
return (_ctx->connect(addr, port)) ? 1 : 0;
|
||||
}
|
||||
|
||||
int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
|
||||
int WiFiUDP::beginPacketMulticast(IPAddress multicastAddress, uint16_t port,
|
||||
IPAddress interfaceAddress, int ttl)
|
||||
{
|
||||
ip_addr_t mcastAddr;
|
||||
@ -207,8 +209,12 @@ int WiFiUDP::parsePacket()
|
||||
{
|
||||
if (!_ctx)
|
||||
return 0;
|
||||
if (!_ctx->next())
|
||||
|
||||
if (!_ctx->next()) {
|
||||
optimistic_yield(100);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _ctx->getSize();
|
||||
}
|
||||
|
||||
@ -216,8 +222,8 @@ int WiFiUDP::read()
|
||||
{
|
||||
if (!_ctx)
|
||||
return -1;
|
||||
|
||||
return _ctx->read();
|
||||
|
||||
return _ctx->read();
|
||||
}
|
||||
|
||||
int WiFiUDP::read(unsigned char* buffer, size_t len)
|
||||
@ -284,4 +290,3 @@ void WiFiUDP::stopAll()
|
||||
it->stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,12 @@ Usage
|
||||
-----
|
||||
1. Download this repository as a zip (button on the right) and follow [these instructions to install into Arduino](http://arduino.cc/en/Guide/Libraries).
|
||||
2. Include the ESP8266mDNS library in the sketch.
|
||||
3. Create an instance of the MDNSResponder class.
|
||||
4. Call the begin method in the sketch's setup and provide a domain name (without
|
||||
the '.local' suffix, i.e. just provide 'foo' to resolve 'foo.local'), and the
|
||||
IP address to advertise. Optionally provide a time to live (in seconds)
|
||||
for the DNS record--the default is 1 hour.
|
||||
5. Call the update method in each iteration of the sketch's loop function.
|
||||
3. Call MDNS.begin method in the sketch's setup and provide a domain name (without
|
||||
the '.local' suffix, i.e. just provide 'foo' to resolve 'foo.local'). Optionally provide
|
||||
the IP address to advertise and time to live (in seconds) for the DNS record -- the default is 1 hour.
|
||||
4. To advertise DNS-SD services, call MDNS.addService(service, proto, port), where service and proto
|
||||
are strings with service and protocol name (e.g. "http", "tcp"), and port is an integer port number
|
||||
for this service (e.g. 80).
|
||||
|
||||
See the included MDNS + HTTP server sketch for a full example.
|
||||
|
||||
@ -49,4 +49,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
THE SOFTWARE.
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <WiFiUDP.h>
|
||||
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
const char* host = "esp8266-ota";
|
||||
const char* ssid = "**********";
|
||||
const char* pass = "**********";
|
||||
const uint16_t aport = 8266;
|
||||
|
||||
|
||||
WiFiServer TelnetServer(aport);
|
||||
WiFiClient Telnet;
|
||||
WiFiUDP OTA;
|
||||
@ -15,10 +15,10 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("");
|
||||
Serial.println("Arduino OTA Test");
|
||||
|
||||
|
||||
Serial.printf("Sketch size: %u\n", ESP.getSketchSize());
|
||||
Serial.printf("Free size: %u\n", ESP.getFreeSketchSpace());
|
||||
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
if(WiFi.waitForConnectResult() == WL_CONNECTED){
|
||||
MDNS.begin(host);
|
||||
@ -43,24 +43,24 @@ void loop() {
|
||||
Serial.print(remote);
|
||||
Serial.printf(", port:%d, size:%d\n", port, size);
|
||||
uint32_t startTime = millis();
|
||||
|
||||
|
||||
WiFiUDP::stopAll();
|
||||
|
||||
|
||||
if(!Update.begin(size)){
|
||||
Serial.println("Update Begin Error");
|
||||
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("Update Success: %u\nRebooting...\n", millis() - startTime);
|
||||
|
@ -1,32 +1,32 @@
|
||||
/**
|
||||
* simple demo to show sha1 calculation
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <Hash.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(921600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// usage as String
|
||||
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
|
||||
Serial.print("SHA1:");
|
||||
Serial.println(sha1("abc"));
|
||||
|
||||
// usage as ptr
|
||||
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
uint8_t hash[20];
|
||||
sha1("abc", &hash[0]);
|
||||
|
||||
Serial.print("SHA1:");
|
||||
for(uint16_t i = 0; i < 20; i++) {
|
||||
Serial.printf("%02x", hash[i]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* simple demo to show sha1 calculation
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <Hash.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(921600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// usage as String
|
||||
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
|
||||
Serial.print("SHA1:");
|
||||
Serial.println(sha1("abc"));
|
||||
|
||||
// usage as ptr
|
||||
// SHA1:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
uint8_t hash[20];
|
||||
sha1("abc", &hash[0]);
|
||||
|
||||
Serial.print("SHA1:");
|
||||
for(uint16_t i = 0; i < 20; i++) {
|
||||
Serial.printf("%02x", hash[i]);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
@ -165,9 +165,6 @@ uint8_t Servo::attach(int pin, int minUs, int maxUs)
|
||||
{
|
||||
ServoTimerSequence timerId;
|
||||
|
||||
Serial.print("_servoIndex ");
|
||||
Serial.println(_servoIndex);
|
||||
|
||||
if (_servoIndex < MAX_SERVOS) {
|
||||
pinMode(pin, OUTPUT); // set servo pin to output
|
||||
digitalWrite(pin, LOW);
|
||||
|
@ -161,13 +161,15 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){
|
||||
}
|
||||
|
||||
int TwoWire::available(void){
|
||||
int result = rxBufferLength - rxBufferIndex;
|
||||
int result = rxBufferLength - rxBufferIndex;
|
||||
|
||||
if (!result) {
|
||||
optimistic_yield();
|
||||
}
|
||||
if (!result) {
|
||||
// yielding here will not make more data "available",
|
||||
// but it will prevent the system from going into WDT reset
|
||||
optimistic_yield(1000);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
int TwoWire::read(void){
|
||||
@ -209,7 +211,7 @@ void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
|
||||
// // copy twi rx buffer into local read buffer
|
||||
// // this enables new reads to happen in parallel
|
||||
// for(uint8_t i = 0; i < numBytes; ++i){
|
||||
// rxBuffer[i] = inBytes[i];
|
||||
// rxBuffer[i] = inBytes[i];
|
||||
// }
|
||||
// // set rx iterator vars
|
||||
// rxBufferIndex = 0;
|
||||
@ -242,4 +244,3 @@ void TwoWire::onRequest( void (*function)(void) ){
|
||||
// Preinstantiate Objects //////////////////////////////////////////////////////
|
||||
|
||||
TwoWire Wire = TwoWire();
|
||||
|
||||
|
@ -0,0 +1,33 @@
|
||||
|
||||
/*
|
||||
* NativeSdk by Simon Peter
|
||||
* Access functionality from the Espressif ESP8266 SDK
|
||||
* This example code is in the public domain
|
||||
*
|
||||
* This is for advanced users.
|
||||
* Note that this makes your code dependent on the ESP8266, which is generally
|
||||
* a bad idea. So you should try to use esp8266/Arduino functionality
|
||||
* where possible instead, in order to abstract away the hardware dependency.
|
||||
*/
|
||||
|
||||
// Expose Espressif SDK functionality - wrapped in ifdef so that it still
|
||||
// compiles on other platforms
|
||||
#ifdef ESP8266
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Call Espressif SDK functionality - wrapped in ifdef so that it still
|
||||
// compiles on other platforms
|
||||
#ifdef ESP8266
|
||||
Serial.print("wifi_station_get_hostname: ");
|
||||
Serial.println(wifi_station_get_hostname());
|
||||
#endif
|
||||
delay(1000);
|
||||
}
|
Reference in New Issue
Block a user