esp8266

tip v Sylvain platformio d1_mini / d1_mini_pro

Voor 3M spiffs in je config toevoegen build_flags = -Wl,-Teagle.flash.4m.ld upload_speed = 460800 of upload_speed = 921600 voor snellere uploads, bij mij lijkt 460800 sneller, denk dat de io wellicht blocked bij hogere snelheden

Async TCP Client

You do not have available(), instead you have onData callback to handle incoming data as it comes. Basically the whole thing is event based and you have callback for each different event. For example:

You start with connect(host, port, onConnectCallback) and attaching onError callback if connect fails. Once you have connected, you can attach the rest of the callbacks and start sending and receiving data. Once you get onDisconnect or you close the client, you will no longer get onData callbacks and you can not send data. That's about it.


```cpp
client = new AsyncClient();

if(!client)//could not allocate client
    return;

  client->onConnect([](void * arg, AsyncClient * client) {

///....

client->onData([](void *arg, AsyncClient *c, void *data, size_t len) {
        Serial.print("async_recv(): onData len = %d\n", len);

lib_deps ESPAsyncTCP in platformio.ini

[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino

lib_deps =
  https://github.com/me-no-dev/ESPAsyncTCP.git

OTA (over the air update)

platformio run -t upload --upload-port 192.168.1.73

mkspiffs error when running 'pio run -t buildfs'

pio run -t buildfs     # or uploadfs
[Tue Jan 30 21:33:25 2018] Processing d1_mini_pro (platform: espressif8266; board: d1_mini_pro; framework: arduino)
-----------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
Collected 26 compatible libraries
Scanning dependencies...
Library Dependency Graph ( http://bit.ly/configure-pio-ldf )
|-- <ArduinoOTA> v1.0
|   |-- <ESP8266WiFi> v1.0
|   |-- <ESP8266mDNS>
|   |   |-- <ESP8266WiFi> v1.0
|-- <Hash> v1.0
|-- <ESP8266WiFi> v1.0
|-- <ESP8266mDNS>
|   |-- <ESP8266WiFi> v1.0
Building SPIFFS image from 'data' directory to .pioenvs/d1_mini_pro/spiffs.bin
libc++abi.dylib: terminating with uncaught exception of type std::length_error: vector
*** [.pioenvs/d1_mini_pro/spiffs.bin] Error -6

There could be an error in ~/.platformio/platforms/espressif8266/builder/main.py. Somehow the size is negative (-s -1069056):

"mkspiffs" -c data -p 256 -b 8192 -s -1069056 .pioenvs/d1_mini_pro/spiffs.bin

Could line 212 in main.py be faulty? "-s", "${int(SPIFFS_END, 16) - int(SPIFFS_START, 16)}",

ESP D1 Mini Pro (wemos.cc)

ESP D1 mini

ESP D1 mini via PlatformIO

mkdir ESP2
cd ESP2
brew install platformio
pio boards esp8266
pio init -b d1_mini
ls
subl .
pio run
pio run -t upload
mkdir data
cd data
echo hallo > index.htm
cd ..
pio run -t uploadfs
ping esptje.local

Smart Config

>> AT

<< OK
>> AT+GMR

<< 00150900

Set Wifi mode to both Access Point and STAtion: AT+CWMODE=3 List Access Points: AT+CWLAP get the connection status AT+CIPSTATUS restart the module AT+RST check SSID of connected network AT+CWJAP? get IP address AT+CIFSR

send something to a UDP server running on your computer

  • on your computer run a UDP server: nc -lu 10.0.0.161 9999
  • then connect to the UDP server and send 5 bytes: AT+CIPSTART=4,"UDP","10.0.0.161",9999 AT+CIPSEND=4,5

    12345 SEND OK

setup a tcp server

AT+CIPMUX=1 AT+CIPSERVER=1,9999 AT+CIFSR

NodeMCU firmware

Flashing

NodeMCU API documentation

NodeMCU Lua ESP8266 ESP-12E WiFi Development Board

dir

function dir() l = file.list(); for k,v in pairs(l) do print("name:"..k..", size:"..v) end end

dir()


# connect to your wifi network

wifi.setmode(wifi.STATION) wifi.sta.config("SSID","password") print(wifi.sta.getip()) --192.168.18.110


# create a http get function

function dns(domain,cb) sk=net.createConnection(net.TCP, 0) sk:dns(domain,function(conn,ip) cb(ip) end) end

function httpget(domain,file) dns(domain, function(ip) sk=net.createConnection(net.TCP, 0) sk:on("receive", function(sck, c) print(c) end ) sk:connect(80,ip) sk:send("GET " .. file .. " HTTP/1.1 Host: " .. domain .. " Connection: keep-alive Accept: /

") end) end



# Compile NodeMCU firmware yourself to disable certain modules=
* http://www.allaboutcircuits.com/projects/guts-of-the-iot-part-1-building-nodemcu-from-source-for-the-esp8266/