Home

ESP8266 Book

image

Contents

1. 124 ell qM 125 APRECIAR ente e E zo Sea ee 126 EE TUNCHONS MEE 126 OS TIMER aM o septo reser iere AS ae POE ER A 126 OS timer disarm ice ende ad 126 OS timer setfn iiit rr mt er ico caidas 127 EIU dM T RRRR 127 OS IMMER arm US sis anida 127 hw timer 128 hw timer armis iee poete dea a aa Pepe a aaa a a a at 128 hw timer set TUInC ru eee rns edes eate mire e eb ed ede oe o ed ete EE EE 128 System Enclosure oto dieat me eed uo cee een qu um 128 YER A A A A ATEN 128 SST diia As 128 SYSTEM init done CD eR decttaadedaceath LOETRERR RE EAR RR Fre x FORES e P vs 128 system get COD Mision 128 EL o or NR cR ES 128 E e AAA eer redeat rea xen e re ERE ER pner eaa ERE EYES 129 system deep sleep ice pde e dc toga eei dieere eee e Pe cde Eee ge e qe 129 system_deep_sleep_Set_OptiON occcccccniccccccnnccoocononannccnncnnnnnnnnnncnnnnnnnnnnnnnnnnnncnnnnnnnnnnnss 129 system PAYS Set TOP iii A A a du ee o died 129 system phys set max tDWencoooooonnnnncccccnnnnnnnnccnnnnnononnnnnnnnnnccnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnrrrnnnnnss 129 system_phys_set_tow_Via_VOd33 ccccccceecececeeeeeeeeeeeaeaeeeeeeeeeeeeeeeeaeeeeeesaeneeeeeaaeeeees 129 Page 4 system set os di dedica ias 129 System Print memlinfOo s aiii Ai dia eed 130 system get free heap size nennen nennen nnnm nnns
2. Follow through the further navigation screens and restart Eclipse when prompted We now have terminal support installed and are ready to use it From Windows gt Show View gt Other we will find a new category called Terminal Page 109 type filter text E Java Browsing a gt E LTTng gt E Make gt E Mylyn b amp Oomph b E Profiling b E Remote Systems gt E Team 4 amp Terminal 48 Terminal gt E Tracing Mm 4 Opening this adds a Terminal view to our perspective There is a button that will allow us to open a new terminal instance that is shown in the following image Problems Tasks E Console 7 Properties Search Terminal El E RI Al PL Clicking this brings up the dialog asking us for the type of terminal and the properties For our purposes we wish to choose a serial terminal Don t forget to also set the port and baud rate to match what your ESP8266 uses Page 110 E H Choose terminal Serial Terminal M Settings Port COM17 y Baud Rate 115200 Data Bits 8 x Parity None v Stop Bits 1 x Flow Control None VA Timeout sec 5 Encoding Default ISO 8859 1 x O After clicking OK after a few seconds we will see that we are connected and a new disconnect icon appears 8 Problems 4 Tasks E Console Properties Search Y Terminal E M I Ea Al iE e B El Serial COM17 7 19
3. An extraordinarily well polished set of artifacts and instructions for building ESP8266 C applications within the Eclipse development environment Ivan Grokhotkov igrr Arduino IDE for ESP8266 development Web site Github esp8266 Arduino An implementation of technology that allows one to develop ESP8266 applications using the Arduino IDE as well as libraries that map Arduino functions to ESP8266 equivalents or near equivalents Sprite_tm HTTP server for ESP8266 Web site ESP8266 Community dedicated forum An implementation of an HTTP server that runs within an ESP8266 capable of serving up web pages Page 219 Areas to Research Page 220 Hardware timers when do they get called If I define functions in a library called libcommon a what is added to the compiled application when I link with this library Is it everything in the library or just the object files that are referenced What are the functions called NOW What is the memory map layout of the ESP8266 How much RAM is installed and available for use
4. Create the directory structure which holds the builds BUILD DIRS mkdir parents verbose TARGET OUT APP_AR LD L SDK_LIBDIR LD_SCRIPT LDFLAGS APP AR Wl end group o S OBJDUMP headers section data section rodata section bss section text section irom0 text Q S OBJCOPY only section text S OBJCOPY only section data S OBJCOPY only section rodata output eagle app v6 rodata bin S OBJCOPY only section irom required directories ar present eagle app v6 iromOtext bin SDK TOOLS gen appbin exe e mv eagle app flash bin FW BASE mv eagle app v6 iromOtext bin rm ea Flash the flash all S ESPTOOL gle app v6 ESP8266 port ESPPORT baud 0000 output target binary 8 eagle output target binary eagle compiles Wl start group LIBS app v6 text bin app v6 data bin target binary Q O text output target binary Q eagle flash bin FW BASE eagle iromOtext bin ESPBAUD write flash flashimageoptions 0x00000 FW BASE eagle flash bin 0x40000 FW BASE eagle iromOtext bin Clean any clean Remove for previous builds ceably and recursively rm recursive force verbose BUILD BASE FW BASE flashld S ESPTOOL port ESPPORT baud ESPBAUD flash id readMac
5. Define our mode as an Access Point wifi set opmode current SOFTAP MODE Build our Access Point configuration details os strcpy config ssid ESP8266 os strcpy config password password config ssid len 0 config authmode AUTH OPEN config ssid hidden 0 4 wifi softap set config current amp config config max connection When a remote station connects to the ESP8266 as an access point we will see a debug message written to UARTI that may look similar to station f0 25 b7 ff 12 c5 join AID 1 This contains the MAC address of the new station joining the network When the station disconnects we will see a corresponding debug log message that may be station f0 25 b7 ff 12 c5 leave AID 1 From within the ESP8266 we can determine how many stations are currently connected with a call to wifi softap get station num If we wish to find the details of those stations we can call wi fi softap get station info which will return a linked list of struct station info We have to explicitly release the storage allocated by this call with an invocation of wifi softap free station info Here is an example of a snippet of code that lists the details of the connected stations uint8 stationCount wifi softap get station num os printf stationCount d n stationCount Page 71 struct station info stationInfo wifi softap get station info if stationInfo NULL while stationInf
6. PIN FUNC SELECT PERIPHS IO MUX GPIO4 U FUNC_GPIO4 os timer disarm amp blink timer os timer setfn amp blink timer os timer func t blink cb void 0 os timer arm amp blink timer 1000 1 This assumes a global called blink timer defined as LOCAL os timer t blink timer The callback function in this example is called b1ink c and looks like LOCAL void ICACHE FLASH ATTR blink cb void arg led state led state GPIO OUTPUT SET 4 led state The global variable called 1ea state contains the current state of the LED 1 on 0 off LOCAL uint8 t led state 0 Dumping IP Addresses Being a WiFi and TCP IP device you would imagine that the ESP8266 works a lot with IP addresses and you would be right We can generate a string representation of an IP address using os printf IPSTR IP2STR pIpAddrVar the IPSTR macro is a d d d so the above is equivalent to os printf d d d d IP2STR pIpAddrVar which may be more useful in certain situations See also ipaddr_t Exception handling At runtime things may not always work as expected and an exception can be thrown For example you might attempt to access storage at an invalid location or write to read only memory or perform a divide by zero When such an occurrence happens the device will reboot itself but not before writing some diagnostics to UART1 Diagnostics may look like Fatal exception 28 ep
7. Access Point An ESP8266 device can play the role of an Access Point a Station or both at the same time Station Very commonly the access point also has a network connection to the Internet and acts as a bridge between the wireless network and the broader TCP IP network that is the Internet A collection of stations that wish to communicate with each other is termed a Basic Service Set BSS The common configuration is what is known as an Infrastructure BSS In this mode all communications inbound and outbound from an individual station are routed through the access point A station must associate itself with an access point in order to participate in the story A station may only be associated with a single access point at any one time Each participant in the network has a unique identifier called the MAC address This is a 48bit value When we have multiple access points within wireless range the station needs to know with which one to connect Each access point has a network identifier called the BSSID or more commonly just SSID SSID is service set identifier It is a 32 character value that represents the target of packets of information sent over the network See also Wikipedia Wireless access point Wikipedia IEEE 802 11 Wikipedia WiFi Protected Access Wikipedia IEEE 802 11i 2004 AT Command Programming The quickest and easiest way to get started with an ESP8266 is to access it via the AT com
8. 222 Includes sntp h See also Working with SNTP sntp_set_timezone Set the current local timezone bool sntp set timezone sint8 timezone Invoking this function declares our local timezone as a signed offset in hours from UTC It should only be called when the SNTP functions are not running as for example after a call to sntp stop The timezone parameter is a time zone in the range 11 to 13 The return value is true on success and false otherwise Includes sntp h See also Working with SNTP sntp_get_timezone Get the current timezone sint8 sntp get timezone Page 176 Retrieve the current value for the timezone as previously set with a call to sntp set timezone Includes sntp h See also Working with SNTP Generic TCP UDP APIs espconn_delete Delete a transmission sint8 espconn delete struct espconn espconn The device maintains data and storage for each conversation TCP and UDP When these conversations are finished and we no longer are going to communicate with the partners we can indicate that by calling this function which will release the internal storage It is anticipated that failure to do this will result in memory leaks Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument See also UDP espconn_create espconn_accept espconn_dns_setserver Set the default DNS server void espconn dns setse
9. String BSSIDstr String BSSIDstr uint8 t networkItem Retrieve the current BSSID as a string representation WiFi channel Retrieve the current channel int32 t channel int32 t channel uint8 t networkItem Retrieve the current channel WiFi config Set the WiFi connection configuration void config IPAddress local ip IPAddress gateway IPAddress subnet void config IPAddress local ip IPAddress gateway IPAddress subnet IPAddress dns Set the configuration of the WiFi using static parameters This disables DHCP Page 122 WiFi disconnect Disconnect from an access point int disconnect bool wifiOff false Disconnect from the current access point WiFi encryptionType Return the encryption type of the scanned WiFi access point uint8 t encryptionType uint8 t networkItem Return the encryption type of the scanned WiFi access point The values are one of ENC TYPE NONE NC TYPE WEP NC TYPE TKIP NC TYPE CCMP NC TYPE AUTO E E E E WiFi gatewaylP Get the IP address of the station gateway IPAddress gatewayIP Retrieve the IP address of the station gateway WiFi getNetworkinfo Retrieve all the details of the specified scanned networklItem bool getNetworkInfo uint8 t networkItem String amp ssid uint8 t sencryptionType int32_t amp RSSI uint8 t amp BSSID uint32 t amp channel bool amp isHidden Retrieve all the details of the specified scanned networklItem WiFi hostByName
10. The espconn is a pointer to the TCP control block The pcon_info parameter is the partner info The typeFlags defines what kind of partner we are getting information about e 0 regular partner e SSL partner Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument espconn connect Connect to a remote application using TCP sint8 espconn connect struct espconn espconn Return code of 0 on success otherwise the code indicates the error ESPCONN RTE Routing problem ESPCONN MEM Out of memory ESPCONN ISCONN Already connected ESPCONN ARG Illegal argument See also TCP espconn_disconnect espconn_disconnect Disconnect a TCP connection sint8 espconn disconnect struct espconn espconn Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument See also TCP espconn_accept espconn_connect Page 181 espconn_regist_connectcb Register a function that will be called when a TCP connection is formed sint8 espconn regist connectcb struct espconn espconn espconn connect callback connect cb Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument The callback function should have the following signature void functionName void arg Where the arg parameter is a pointer to an struct espconn instance Question Is this a NE
11. GPIO OUTPUT SET Set the output value of a specific pin GPIO OUTPUT SET GPIO NUMBER value Page 191 This is a helper macro that invokes gpio output set Take care when passing in a value that is part of an expression such as pData 1 The value is evaluated a number of times so should not have side effects There is also a current bug related to operator precedence it is strongly recommended to place the value in extra parenthesis when coding For example GPIO OUTPUT SET GPIO NUMBER pData 1 Includes e gpio h See also GPIOs GPIO_DIS_OUTPUT Set the pin to be input disabled output GPIO DIS OUTPUT GPIO NUMBER This is a helper macro that invokes gpio_output_set Includes e gpio h See also GPIOs GPIO INPUT GET Read the value of the pin GPIO INPUT GET GPIO NUMBER This is a helper macro that invokes gpio input _get Includes e gpio h See also gpio_input_get gpio_output_set Change the values of GPIO pins in one operation void gpio output set uint32 set mask unit32 clear mask uint32 enable output unit32 enable input Page 192 The parameters are e set mask Bits with a 1 are set high bits with a 0 are left unchanged e clear mask Bits with a 1 are set low bits with a 0 are left unchanged enable output Bits with a 1 are set to output enable input Bits with a 1 are set to input Includes e gpio h Se
12. ESPTOOL port ESPPORT baud ESPBAUD read mac imageInfo ESPTOOL image info FW BASE eagle flash bin 8 Add Make targets for at least all and flash Page 50 See also Programming using Eclipse Flashing the ESP8266 Once the program has been compiled it needs to be loaded into the ESP8266 This task is called flashing In order to flash the ESP8266 it needs to be placed in a mode where it will accept the new incoming program to replace the old existing program The way this is done is to reboot the ESP8266 either by removing and reapplying power or by bringing the REST pin low and then high again However just rebooting the device is not enough During startup the device examines the signal value found on GPIOO If the signal is low then this is the indication that a flash programming session is about to happen If the signal on GPIOO is high it will enter its normal operation mode Because of this it is recommended not to let GPIOO float We don t want it to accidentally enter flashing mode when not desired A pull up resistor of 10k is perfect We can build a circuit which includes a couple of buttons One for performing a reset and one for bringing GPIOO low Pressing the reset button by itself will reboot the device This alone is already useful However if we are holding the GPIOO low button while we press reset then we are placed in flash mode Here is an example schematic diagram illustrating an ESP 12 inclu
13. Includes httpd h httpdRedirect void httpdRedirect HttpdConnData conn char newUrl Send an HTTP redirect instruction to the browser The newUr1 is the URL we wish the browser to use Includes httpd h httpdHeader void httpdHeader HttpdConnData conn const char field const char val Page 213 Send an HTTP header The name of the header is supplied in the field parameter and its value supplied in the val parameter Includes httpd h httpdGetHeader int httpdGetHeader HttpdConnData conn char header char ret int retLen Search the browser supplied data header looking for a header that matches the header parameter If found return the header value at the buffer pointed to by ret which must be at least ret Len bytes long Includes httpd h httpdFindArg int httpdFindArg char line char arg char buff int buffLen Given a line of text look for a parameter of the form name value within the line If the name matches our passed in name then return the value Includes httpd h httpdEndHeaders void httpdEndHeaders HttpdConnData conn Conclude the output of headers to the output stream Includes httpd h Makefiles Books have been written on the language and use of Makefiles and our goal is not to attempt to rewrite those books Rather here is a cheaters guide to beginning to understand how to read them A general rule in a make file has the form Large
14. Page 1 Table of Contents ligyiroro 3 eito a aio SA nes os eee RECIENTE FED REM 12 MOVE WIG Wt peste Ehe Dos dta tametsi nag a es edere Est LO aed ates sU E ccr 13 Me ESP8200 et ETE ii 14 Maturity eer NCC ETE mec ee 14 ESP93266 MOS 4 i Ress ood Era EIS on dud ee Wr qoe AAA A Gn diese A dese ded 15 Ee Ft ich Lu Ce LM c C bu LE e c ED ME 15 A Nee ce eta eee SnD Read Oa tee OO le AS CRS GaN Latte kee 19 Adafruit HUZZA ii a A db ee 23 SparkFun WiFi Shield ESP8200 ccoo ii 23 Connecting tothe ESPS266 uc a a te ee a add 24 A EE O T 25 AT Command PFOQFaTirfilg tardando restado valoradas 27 COMMANOS oars sass alors atl KNEE CM PEE as 28 a O leh stashasaacehearaded 34 USB to UAIT CODVOFPIBIS ua pet A oh eua arb dei doe 35 Breadb ard Skrip mmm 36 lu C e a ee es 37 Multi meter Logic probe Logic ANalyZer ooococccccnnncnononononcccnnnnnnnnnnnnnnnnnnnnnnnnnnn nono enn 37 SUNNY COMPORGMtS Mene n E 38 PINVSiCal COMSIFUCUION pr M CE 38 Recommended setup for programming ESP8266 sss 38 Configuration for flashing the deviCe ue reete por betae p retenta to udo AF REUS 41 PROG PAM simer heaton dotis ender dared inedabeabie ete c tales nadal dedos dol cobesccabea non 42 Boot TOG ede e toca odios adiuvet a ee eels 42 Mhe ESPS8266 SDK rt 43 Include directos A A a eee 43 COMPIIN Os A 44 Flashing the ES PO 266 ii a 50 Programrhalmg envireniglllss os ctore rabia aida di baaa resi 54 Compilation tOOIS oo
15. See also struct softap config wifi_station_get_config wifi_softap_set_config wifi_softap_set_config_current wifi_softap_set_config Set the current and default softAP configuration bool wifi softap set config struct softap config config When called the struct softap config pointed to be pconfig will be used as the details of the default and current softAP configuration A value of 1 will be returned on success and 0 otherwise Includes user interface h See also struct softap_config wifi_station_get_config wifi_softap_get_config_default wifi_softap_set_config_current Page 167 wifi_softap_set_config_current Set the default softAP configuration bool wifi softap set config current struct softap config config When called the struct softap config pointed to be pconfig will be used as the details of the current softAP configuration but will not be saved as default Includes user interface h See also struct softap_config wifi_station_get_config wifi_softap_get_config_default wifi_softap_set_config wifi_softap_get_station_num Return the count of stations currently connected uint8 wifi softap get station num Returns the number of stations currently connected The maximum number of connections on an ESP8266 is 4 but we can reduce this in the softAP configuration if needed Includes user interface h See also Being an access point wifi_softap_get_sta
16. The DHCP server wifi softap set dhcps lease struct bss info This structure contains STAILQ ENTRY bss info next e uint8 bssid 6 e uint8 ssid 32 e uint8 channel e sint8 rssi The received signal strength indication AUTH MODE authmode e uint8is hidden sintl6 freq offset Page 202 To get the next entry we can use STAILO NEXT pBssInfoVar next The AUTH_MODE is an enum AUTH OPEN No authentication No challenge on any station connect AUTH_WEP 1 AUTH WPA PSK 2 AUTH WPA2 PSK 3 AUTH WPA WPA2 PSK 4 See also Scanning for access points struct ip info This structure defines information about an interface possessed by the ESP8266 It contains the following fields struct ip addr ip The IP address of the interface struct ip addr netmask The netmask used by the interface struct ip addr gw The IP address of the gateway used by the interface See also wifi get ip info wifi set ip info IP4 ADDR struct rst info Information about the current boot restart This structure contains uint32 reason uint32 exccause uint32 epcl uint32 epc2 uint32 epc3 uint32 excvaddr uint32 depc The reason field is an enum with the following values Page 203 0 Default restart Normal startup on power on 1 Watch dog timer Hardware watchdog reset 2 Exception An exception was detected 3 Software watch dog timer Software watchdog rese
17. authModeToString Given an AUTH_MODE return a string representation of the mode char authModeToString AUTH MODE mode Page 135 checkErr or Check a return code for an error void checkError sint8 err Check the err code for an error and if it is one log it delayMill iseconds Delay for a period of milliseconds void delayMilliseconds uint32 milliseconds The milliseconds parameters is the number of milliseconds to delay before returning dumpBSSINFO Dump an instance of struct bss_info to the log void dumpBSSINFO struct bss info bssInfo dumpEsp Conn Dump to the log a decoded representation of the struct espconn void dumpl EspConn struct espconn pl dumpRestart Dump the restart information to the log void dumpRestart See also Exception handling dumpState Dump the WiFi station state to the log void dumpState See also system_print_meminfo System get free heap size system_get_boot_version system_get_userbin_addr system_get_boot_mode System get flash size map system_get_sdk_version Page 136 EspConn error ToString Given an error code return a string representation of it char errorToString sint8 err eventLogger Write a WiFi event to the log void eventLogger System Event t event We can register this function as a callback for a WiFi event Write the event data to the log See also Handling W
18. e cp device Serial device eg COMI e cd lt board gt e cb lt baudrate gt e ca lt address gt e cf filename See also e Github https github com igrr esptool ck gen appbin py The syntax of this tool is gen appbin py app out boot mode flash mode flash clk div flash size flash mode o 0 QIO o 1 QOUT o 2 DIO o 3 DOUT flash clk div Page 59 o 0 80m 2 o 1 80m 3 o 2 80m 4 o Qxf 80m 1 e flash size map o 0 512KB 256 KB 256 KB o 1 256 KB o 2 1024 KB 512 KB 512 KB o 3 2048 KB 512 KB 512 KB o 4 4096 KB 512 KB 512 KB o 5 2048 KB 1024 KB 1024 KB o 6 4096 KB 1024 KB 1024 KB The following files are expected to exist e eagle app v6 iromOtext bin e eagle app v6 text bin e eagle app v6 data bin eagle app v6 rodata bin The output of this command is a new file called eag1e app flash bin xxd This is a deceptively useful tool What it does is dump binary data from a file in a formatted form One powerful use of it is to take a binary file and produce a C language data structure that represents the file This means that you can take binary data and include it in your applications A copy of xxd exe is distributed with the SDK supplied by Espressif in the tools folder The following will read the content of inFile as binary data and produce a header file in the outFile xxd include inFile outFile Debugging When writing programs
19. DICACHE FLASH MODULES user BUILD BASE build FW BASE firmware SDK_LIBDIR lib SDK LDDIR ld Nothing to configure south of here linker flags used to generate the main object file LDFLAGS nostdlib Wl no check sections u call user start Wl static libraries used in this project mainly provided by the SDK LIBS c gcc hal phy pp net80211 lwip wpa main linker script used for the above linkier step LD SCRIPT eagle app v6 ld flashimageoptions flash freq 40m flash mode qio flash size 4m SDK LIBDIR addprefix SDK BASE S SDK LIBDIR LD SCRIPT addprefix T SDK_BASE SDK_LDDIR LD SCRIPT LIBS S addprefix 1 LIBS APP AR addprefix BUILD BASE TARGET app a TARGET OUT addprefix BUILD BASE TARGET out BUILD DIRS addprefix BUILD BASE MODULES S FW BASE SRC S foreach moduleDir MODULES wildcard moduleDir c Replace all x c with x o OBJS patsubst c BUILD BASE 0 SRC all checkdirs TARGET OUT echo Image file built Build the application archive This is dependent on the compiled objects APP_AR 0BJS S AR cru APP_AR OBJS Build the objects from the C source files BUILD BASE O AO CC CFLAGS I SDK BASE include Iinclude c lt o Page 49 Check that th checkdirs BUILD DIRS
20. The TX pin is the ESP8266 Page 25 transmission outbound from ESP8266 and the RX pin is used to receive data inbound into the ESP8266 These pins can be connected to a UART partner By far the easiest and most convenient partner for us is a USB UART converter These are discussed in detail later in the book For now let us assume that we have set those up Through the UART we can attach a terminal emulator to send keystrokes and have received data displayed as characters on the screen This is used extensively when working with the AT commands A second purpose of the UART is to receive binary data used to flash the flash memory of the device to record new applications for execution There are a variety of technical tools at our disposal to achieve that task When we use a UART we need to consider the concept of a baud rate This is the speed of communication of data between the ESP8266 and its partner During boot the ESP8266 attempts to automatically determine the baud rate of the partner and match it It does this by sending some data down the serial line and looking for expected responses It tries this at different baud rates until it finds a match or gives up When it gives up the default is 115200 A side effect of this is that during boot if you have a terminal emulator attached you will see what appear to be gibberish data before the normal text As long as you understand that this is just protocol negotiations and that these
21. lt sleep mode gt AT RFPOWER lt TX power gt AT REVDD AT RFVDD lt VDD33 gt AT RFVDD WIFI AT CWMODE_CUR lt mode gt Sets the current mode of operation e 1 Station mode e 2 AP mode e 3 AP Station mode AT CWMODE CUR Get the current mode of operation Page 31 AT CWMODE CUR Get the list of available modes AT CWMODE_DEF lt mode gt Sets the current mode of operation e 1 Station mode e 2 AP mode e 3 AP Station mode AT CWMODE DEF Get the current mode of operation AT CWMODE_DEF Get the list of available modes AT CWJAP_CUR lt ssid gt Join the WiFi network JAP Join Access Point lt password gt lt bssid gt AT CWJAP_CUR Get the current connection info AT CWJAP_DEF lt ssid gt Join the WiFi network JAP Join Access Point lt password gt lt bssid gt AT CWJAP_ DEF Get the current connection info AT CWLAP List the List Access Points The response is CWLAP lt ecn gt lt ssid gt lt rssi gt lt mac gt lt ch gt where e ecn o 0 OPEN o WEP o 2 WPA PSK o 3 WPA2 PSK o 4 WPA WPA2 PSK e ssid SSID of AP e rssi Signal strength e mac MAC address e ch Channel AT CWLAP lt ssid gt List a filtered set of access points mac gt lt ch gt AT CWOAP Disconnect from AP
22. not yet published 99C ESP8266 OTA Upgrade v1 6 Github There are a number of open source projects built on top of and around the ESP8266 that can be found on Github Here is a list of links to some of these projects that are very well worth having a look EspressifApp eriksl esp8266 universal io bridge CHERTS esp8266 devkit ESPHTTPD project o Spritetm esphttpd o Spritetm libesphttpd SDK The Software Development Kit SDK is published by Espressif and is required to build C based applications It contains vital documentation in the form of PDF that don t appear to be available elsewhere ESP8266 SDK v1 2 0 Heroes Within the ESP8266 user community there are individuals that I consider to have pushed the boundaries of knowledge further or have developed tools that dramatically improve working with the devices I want to take a few moments and call out these good folks without whom all our ESP8266 travels would be harder Max Filippov jcmvbkbc GCC compiler for Xtensa Web site Github https github com jcmvbkbc Page 218 A compiler for C based on GCC that compiles to Xtensa binary for flashing It is doubtful that any useful work could be performed without this contribution Mikhail Grigorev CHERTS Eclipse for ESP8266 development Web site Project Unofficial Development Kit for Espressif ESP8266 Web site Github CHERTS esp8266 devkit
23. port port The serial port to use b baud baud baud The baud rate to use for serial h Help command h Help for that command load ram filename Download an image to RAM and execute dump mem address size filename Dump arbitrary memory to disk read mem address Read arbitrary memory location write mem address value mask Read modify write to arbitrary memory location write flash Write a binary blob to flash o flash freq 40m 26m 20m 80m ff 40m 26m 20m 80m SPI Flash frequency flash mode qio qout dio dout fm qio qout dio dout SPI Flash mode O flash size 4m 2m 8m 16m 32m 16m cl 32m cl 32m c2 fs 4m 2m 8m 16m 32m 16m c1 32m c1 32m c2 SPI Flash size in Mbit o address fileName Address to write file to write repeatable run Run application code in flash image info image file Dump headers from an application image Here is an example output Entry point 40100004 3 segments Segment 1 25356 bytes at 40100000 Segment 2 1344 bytes at 3ffe8000 Segment 3 924 bytes at 3ffe8540 Checksum 40 valid make image Create an application image from binary files Page 57 O segfile SEGFILE f SEGFILE Segment input file segaddr SEGADDR a SEGADDR Segment base address entrypoint ENTRYPOINT e ENTRYPOINT Address of entry point O outp
24. represent IP addresses with the notation lt number gt lt number gt lt number gt lt number gt for example 173 194 64 102 These IP addresses are not commonly entered in applications Instead a textual name is typed such as google com but don t be misled these names are an illusion at the TCP IP level All work is performed with 32bit IP addresses There is a mapping system that takes a name such as google com and retrieves its corresponding IP address The technology that does this is called the Domain Name System or DNS When we think of TCP IP there are actually three distinct protocols at play here The first is IP Internet Protocol This is the underlying transport layer datagram passing protocol Above the IP layer is TCP Transmission Control Protocol which provides the illusion of a connection over the connectionless IP protocol Finally there is UDP User Datagram Protocol This too lives above the IP protocol and provides datagram connectionless transmission between applications When we say TCP IP we are not just talking about TCP running over IP but are in fact using this as a shorthand for the core protocols which are IP TCP and UDP and additional related application level protocols such as DNS HTTP FTP Telnet and more The ESPConn architecture Because we are not allowed to block control in the ESP8266 for any length of time we must register callback functions which will be invoked when some long duratio
25. serial terminal to appear as a view within the Eclipse IDE It does not come installed by default but the steps to add are not complex First start Eclipse I use the Mars release Go to Help gt Install new software Select the eclipse download repository Select Mobile and Device development gt TM Terminal Page 106 Work with Mars http download eclipse org releases mars M Add Available Software dd Check the items that you wish to install Find more software by working with the Available Software Sites preferences type filter text Name Version 4 i Mobile and Device Development amp C C GDB Hardware Debugging 8 7 0 201506070905 amp C C Remote over TCF TE Run Debug Launcher 1 3 1 201506040227 4 Hybrid Mobile Application Development Tools 0 3 0 201506011443 Remote System Explorer User Actions 3 7 0 201505221634 Q TCF C C Debugger 1 3 1 201505051438 2 TCF Remote System Explorer add in 1 3 0 201505261946 4 TCF Target Explorer 1 3 1 201504300712 4 TM Terminal 4 0 0 201506040610 Selecta DeselectAll 1item selected Details Show only the latest versions of available software Y Hide items that are already installed Group items by category What is already installed Show only software applicable to target environment Y Contact all update sites during install to find required software Step through the following sections and when prompte
26. DatagramSocket clientSocket new DatagramSocket Next we will connect to the remote UDP partner We will need to know the IP address and port that the partner is listening upon Although the API is called connect we need to realize that no connection is formed Datagrams are connectionless so what we are actually doing is associating our client socket with the partner socket on the other end so that when we actually wish to send data we will know where to send it to clientSocket connect ipAddress port Now we are ready to send a datagram using the send method DatagramPacket data new DatagramPacket new byte 100 100 clientSocket send data To write a UDP listener that listens for incoming datagrams we can use the following DatagramSocket serverSocket new DatagramSocket port The port here is the port number on the same machine as the JVM that will be used to listen for incoming UDP connections To wait for an incoming datagram call receive Page 102 DatagramPacket data new DatagramPacket new byte 100 100 clientSocket receive data If you are going to use the Java Socket APIs read the JavaDoc thoroughly for these classes are there are many features and options that were not listed here See also Java tutorial All About Sockets JDK 8 JavaDoc WebSockets WebSockets is both an API and a protocol introduced in HTMLS Simply put if we imagine an HTTP server sitting waiting fo
27. ERAS 141 O D Lai m t CA LN EM 141 MRS 141 wifi get opmode default nee ener nn nennen rese 141 Wifi set OPMOC Ci EO 142 Wifi_Se t_OPMOdE_CUITENK ee ccccccccseeeeeeeeeeeeeeeeeeeeeeeeeeeeeanaaeeaaaaaeeeeeeeeeeeeseseeeeseeaeneeesees 142 Wif Set Producir nee teer da eee ever Ee Ox do qe we Fe veda ei eevee 143 Wifi get broadcast ics A di el d qudo 143 wifi_set_event_handle_Cb oooooooonnnnncccccccnnncccccccnnoononnnnnncnnnconnnnnnnnnnnnnnnnnnnnnnnnnnrrnennnnninnnnns 143 Wifi g t lO ii dd Cad SENATE Tee IS 144 A NE 144 Wifi Set macadqr 2 e cea che ee eee isan ca Rer rne dae cenchiddeaediaas A T 144 Wifi_Qet_MACACM cc c ccc cccccenceeeeeeeeeeeeeeeeeeeeeeeeceeaaaaaaeaaaaaaaaeeeeeeeeeeeeeeeeeeeaaaaaeensneeseeeeeeeees 145 Wifi set Sleep type voice n Rc DEEPLY RAE RERME IPTE ERU NEUES 145 Wifi zget sleep types deri n Fed Ha ede st reed De EET ee re Xy EFE ERA EO 145 Wifi Stat s led install iro ree re eet re eene eei eve se dur r ete dau ex ea En eg vd ada 145 Wifi status led uninstall in REA a 145 wifi station get Configi eenst ena eeenenenennnnnr nnn nennen nennen nnne nnnnn 146 wifi_station_get_config_default oooooooocccnnnonoooocccoonccccncnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnns 146 Wifi station set Config eee ee RR RUNI Dn oa AI ERA ARR ETE GR RR LEE FREE Eae de 146 wifi station set config current sssssssssssssssssssss
28. EVENT SOFTAPMODE STADISCONNECTED os printf Event EVENT SOFTAPMODE STADISCONNECTED break default os printf Unexpected event d r n event gt event break The callback function can be registered in user init as follows wifi set event handler cb eventHandler See also wifi_set_event_handle_cb System_Event_t Page 68 Station configuration When we think of an ESP8266 as a WiFi Station we will realize that at any one time it can only be connected to one access point Putting it another way there is no meaning in saying that the device is connected to two or more access points at the same time The identity of the access point to which we wish to be associated is known as the station config and is modeled as the C structure called struct station config Contained within that structure are two very important fields called ssid and password The ssid field is the SSID of the access point to which we will connect The password field is the clear text value of the password that will be used to authenticate our device to the target access point to allow connection When booted the ESP8266 remembers the last station config we set We can explicitly set the station config data using the function wifi station set config This will set the current configuration and save it for later retrieval after a reboot If we only wish to set the current station config and not have the information persisted we can use t
29. broadcasting a packet asking for the machine with that identity to respond See also Wikipedia Multicast DNS IETF RFC 6762 Multicast DNS Working with SNTP SNTP is the Simple Network Time Protocol and allows a device connected to the Internet to learn the current time In order to use this you must know of at least one time server located on the Internet The US National Institute for Science and Technology NIST maintains a number of these which can be found here http tf nist gov tf cgi servers cgi Other time servers can be found all over the globe and I encourage you to Google search for your nearest or country specific server Once you know the identity of a server by its hostname or IP address you can call either of the functions called sntp_setservername Or sntp_setserver to declare that we wish to use that time server instance The ESP8266 can be configured with up to three different time servers so that if one or two are not available we might still get a result The ESP8266 must also be told the local timezone in which it is running This is set with a call to sntp set timezone which takes the number of hours offset from UTC For example I am in Texas and my timezone offset becomes 5 With these configured we can start the SNTP service on the ESP8266 by calling sntp init This will cause the device to determine its current time by sending packets over the network to the time servers and examining the
30. heart and soul of a new range of hobbyist boards and professional appliances Will there be something newer and better just around the next corner We simply don t know The ability to treat it as though it were like an Arduino is a notion that I haven t been able to fully absorb yet ESP8266 is a Tensilica CPU unlike the Arduino which is an ATmega CPU Espressif have created dedicated and architected API in the form of their SDK for directly exposed ESP8266 APIs The Arduino libraries for ESP8266 seem to map their intent to these exposed APIs For these reasons and similar one might argue that the Arduino support is an unnecessary facade on top of a perfectly good environment and by imposing an alien technology model on top of the ESP8266 native functions we are masking access to lower levels of knowledge and function Further thinking of the ESP8266 as though it were an Arduino can lead to design problems For example the ESP8266 needs regular control in order to handle WiFi and other internal actions This conflicts with the Arduino model where the programmer can do what he wants within the loop function for as long as he wants The flip side is that the learning curve to get something running on an Arduino has been shown to be extremely low It doesn t take long at all to get a blinky light going on a breadboard With Page 114 that train of thought why should users of the ESP8266 be penalized for having to install and learn more complex
31. i2c master start void i2c master start i2c master stop void i2c master stop i2c master send ack void i2c master send ack i2c master send nack void i2c master send nack i2c master checkAck bool i2c master checkAck Page 196 i2c_master_readByte uint8 i2c master readByte i2c master writeByte void i2c master writeByte uint8 wrdata i2c master setAck void i2c master setAck uint8 level i2c masetr getAck uint8 i2c master getAck SPI APIs These functions have to be compiled in from the SPI files in driver lib cache flush spi lcd 9bit write spi mast byte write spi byte write espslave spi slave init spi slave isr handler hspi master readwrite repeat spi test init Page 197 PWM APIs pwm_init Initialize PWM void pwm init uint32 period uint32 duty uint32 num pwm channels uint32 pin info list 3 The period parameter is the PWM period The value is measured in microseconds with a minimum value of 1000 giving a 1KHz period there are 1000 periods of 1000 microseconds in a second The duty parameter is the duty ration of each PWM channel The num pwm channels is the number of PWM channels being defined The pin info list is a pointer to an array of num pwm channels 3 instances of unit32s that provides the PWM pin mappings See also Pulse Width Modulation PWM pwm set duty pwm set period pwm start pwm start void pwm start After configurin
32. ie teet b proie in ede vere Eod al Ode eee 192 struct PING ESD o AA t CO ee EET ee Ge d o E EUR ER ae eR 192 enum phy mode tete itcr dot A a en LR IR 192 GPIO INT TYPE cocida ERES RR EP RR RERO RR ERI ER RRANR REA FIR CURIE ORE 193 System Event Mic eene RISE Yee RAF SERERE EO REX Den ERA Ex VAT Re Re Nee EEUU RENDER IRA 193 ND RUNE A PUES MEIN 194 Reference materials ssssssssssssssssssssseseseeeeeeeee nennen nennen nire rh nnn nn esee nnns esent rns 195 ESPFS breakdOoWfi 5 i einn nar A Pape e d ER ER AEN 195 relati 195 ESPESOPESM eternity ep et etd teu eben uen prete tn ties vataet ates 195 eSpESC OSO rer A Ede FU De NO TO E dese ee eA De heave wk Pe RN 195 espFSFlagS em E 195 CSPFSREAG He M 195 FTUKES PNAS aah t A EEES aai 195 ESPHTTPD breakdown ssssssssssssssssssessssseeenne nennen nennen nnn esee ness nensis sese rr rrr nnne n 196 httpdGetMimetype ccccccccceeeseeeeeeeeeeeeeeeeeeeeeeaeaaaaeasaaaaaeeeeeeeeeeeeeeecaaeeeseeegeeesseseeesenees 196 garoto lU lul BI ecole e eee 196 httpdStartResporise ntt rec e aaa thee Feb Ei Y He EU SERRATIS PERI ME e aeai 196 A E Def e ee rae EA Ede Deren Ged ee ae 196 NPA REGIE Chin 2 oo id ieee copi t e eret eae de iat eur eie cies Es 196 httpd nities hase ahaa ei raed ESME 196 httpd He ade EH 197 httpdGetHeader 2 ee terre A 197 PION GAN Gs conti 197 a ttole late l mS o 1 eee 197
33. info WiFi Protected Setup WPS The ESP8266 supports WiFi Protected Setup in station mode This means that if the access point supports it the ESP8266 can connect to the access point without presenting a password Currently only the push button mode of connection is implemented Using this mechanism a physical button is pressed on the access point and for a period of two minutes any station in range can join the network using the WPS protocols An example of use would be the access point WPS button being pressed and then the ESP8266 device calling wifi wps enable and thenwifi wps start The ESP8266 would then connect to the network See also wifi wps enable wifi wps start wifi set wps cb Simple Questions What is WPS WiFi Protected Setup Wikipedia WiFi Protected Setup Working with TCP IP TCP IP is the network protocol that is used on the Internet It is the protocol that the ESP8266 natively understands and uses with WiFi as the transport Books upon books have already been written about TCP IP and our goal is not to attempt to reproduce a detailed discussion of how it works however there are some concepts that we will try and capture First there 1s the IP address This is a 32bit value and should be unique to every device connected to the Internet A 32bit value can be thought of as four distinct 8bit values 4x8 32 Page 73 Since we can represent an 8bit number as a decimal value between 0 and 255 we commonly
34. language calls into indirect calls mtext section literals Allow literals to be intermixed with the text section Page 55 e mno serialize volatile Special instructions for volatile definitions Linking e nostdlib Don t use standard C or C system startup libraries See also GCC The GNU Compiler Collection ar The archive tool is used to packaged together compiled object files into libraries These libraries end with a archive A library can be named when using a linker and the objects contained within will be used to resolve externals Some of the most common flags used with this tool include e c Create a library e r Replace existing members in the library e u Update existing members in the library The syntax of the command is ar cru libraryName member o member o See also GNU ar objcopy See also GNU objcopy objdump The command is xtensa 1x106 elf objdump located in C Espressif xtensa 1x106 elf bin Wikipedia objdump GNU objdump man page objdump 1 esptool py This tool is an open source implementation used to flash the ESP8266 through a serial port It is written in Python Versions have been seen to be available as windows executables that appear Page 56 to have been generated Exe files from the Python code suitable for running on Windows without a supporting Python runtime installation p port
35. map The value returned is an enum which has the following definitions FLASH SIZE 4M MAP 256 256 FLASH SIZE 2M FLASH SIZE 8M MAP 512 512 FLASH SIZE 16M MAP 512 512 FLASH SIZE 32M MAP 512 512 FLASH SIZE 16M MAP 1024 1024 FLASH SIZE 32M MAP 1024 1024 See also Flashing the ESP8266 system get rst info Information about the current startup Page 146 struct rst info system get rst info Retrieve information about the current device startup See also Exception handling struct rst_info system_get_sdk_version Return the version of the SDK char system get _sdkVersion For example 1 1 1 system_soft_wdt_stop Disable the software watchdog void system soft wdt stop Stop the software watchdog It is recommended not to stop this timer for too long 8 seconds or less otherwise the hardware watchdog will force a reset See also Watchdog timer system_soft_wdt_restart Restart the software watchdog void system soft wdt restart Restart the software watchdog following a previous call to stop it See also Watchdog timer os_memset Set the values of memory void os memset void pBuffer int value size t size Set the memory pointed to by pBuf fer to the value for size bytes Includes e osapi h See also Working with memory Page 147 os memcpy os memcmp Compare two regions of memory int os memcmp uint8 ptrl uint8
36. of adventure and getting in on the ground floor of a new arrival the challenges that we the ESP8266 community are trying to solve may actively excite you rather than dissuade you Page 14 It is also a major reason that folks like myself spend many many hours studying and documenting what we find so others can hopefully build on what has been learned without re inventing the wheel Could the excitement about ESP8266 processors fizzle Yes these devices may just be a flash in the pan and a few years from now the hobbyist won t give a second thought about them But what I ask you is to approach the device with an open mind ESP8266 Modules The ESP8266 integrated circuit comes in a small package maybe five millimeters square Obviously unless you are a master solderer you aren t going to do much with that The good news is that a number of vendors have created breakout boards that make the job much easier for you Here we list some of the more common modules ESP 12 The current most popular and flexible configuration available today is called the ESP 12 It exposes the most GPIO pins for use The basic ESP 12 module really needs its own expander module to make it breadboard and 0 1 strip board friendly Here is what an ESP 12 device looks like when mounted on a breadboard extender board The pin out of the extender board looks as follows rest E 5 To anc 1 n RD O curo I GPo5 P1016 I M cpio4 Q I
37. of code caused the problem For example xtensa 1x106 elf objdump x app out d See also system_get_rst_info struct rst_info Debugging and testing TCP and UDP connections When working with TCP IP you will likely want to have some applications that you can use to send and receive data so that you can be sure the ESP8266 is working There are a number of excellent tools and utilities available and these vary by platform and function Android Socket Protocol The Socket Protocol is a free Android app available from the Google play app store See https play google com store apps details id aprisco app android Android UDP Sender Receiver The UDP Sender Receiver is another free Android app available from the Google play app store What makes this one interesting is its ability to be a UDP as opposed to TCP sender and receiver See https play google com store apps details id com jca udpsendreceive Windows Hercules Hercules is an older app for Windows that still seems to work just fine on the latest releases It looks a little old in the tooth now but still seems to get the job done just fine See http www hw group com products hercules index_en html Curl Curl is powerful and comprehensive command line tool for performing any and all URL related commands It can transmit HTTP requests of all different formats and receive their responses It has a bewildering set of parameters available to it which is both a
38. of the connection is lost the heartbeat request will be sent but no response will arrive at which point the one sending the heartbeat will assume that the partner has gone and we can take appropriate cleanup and shutdown actions There is an API available to us to control the keep alive settings It is called espconn set keepalive It has a number of properties including How long should we wait since the last time we heard from the partner before sending a heartbeat Ifno response how long between subsequent heartbeats Page 80 How many times should we send a heartbeat until we declare the partner dead It is recommended that if keep alive processing is to be used then the keep alive settings be made in the callback handler of the connect callback The keep alive option must also be explicitly enabled using the espconn set opt call prior to setting the keep alive properties If the partner connection is lost we can detect that by registering a callback function with espconn reconnect callback See also espconn set keepalive espconn get keepalive espconn set opt espconn clear opt UDP If we think of TCP as forming a connection between two parties similar to a telephone call then UDP is like sending a letter through the postal system If I were to send you a letter I would need to know your name and address Your address is needed so that the letter can be delivered to the correct house while your name ensure
39. of two places The instruction can in flash memory also called irom or it can be in RAM also called iram It takes less time for the processor to retrieve the instruction from RAM than it does from flash It is believed that an instruction fetch from flash takes four times longer than the same instruction fetched from RAM However on the ESP8266 there is far less RAM than there is flash What this means is that you are far more likely to run out of RAM way before you run out of flash When writing normal applications we shouldn t fixate on having instructions in RAM rather than flash for the performance benefit The execution speeds of the ESP8266 are so fast that if the cost of retrieving an instruction from RAM is blindingly fast then retrieving an instruction from slower flash is still blindingly fast There are however certain classes of instructions that we might wish to place in RAM rather than flash Examples of these are interrupt handlers where the time spent in these should always be as fast as possible and also function that write to flash When we define C functions we can add an attribute by the name of ICACHE FLASH ATTR What this does is place this function in the flash memory address space as opposed to RAM Specifically flagging a function with ICACHE FLASH ATTR tags it as being in the text section of code See also os memset Page 94 os_memcpy os_memcmp os_malloc os_zalloc os_free System get free h
40. parameter defines the timeout interval in seconds The maximum value is 7200 seconds 2 hours The typeFlag parameter can be 0 to indicate that all connections are to be changed or 1 to set just this connection Page 184 Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument espconn_set_keepalive sint8 espconn_set_keepalive struct espconn espconn uint8 level void optArg espconn_get_keepalive sint espconn get keepalive struct espconn espconn unit8 level void optArg 22 espconn_secure_accept Listen for an incoming SSL TCP connection sint8 espconn secure accept struct espconn espconn Return code of 0 on success otherwise the code indicates the error ESPCONN_MEM Out of memory ESPCONN ISCONN Already connected ESPCONN ARG Illegal argument espconn secure set size espconn secure get size espconn secure connect espconn secure sent espconn secure disconnect Secure TCP disconnection espconn tcp get max con Return the maximum number of concurrent TCP connections Page 185 uint8 espconn tcp get max con espconn tcp set max con Set the maximum number of concurrent TCP connections sint8 espconn tcp set max con uint8 num espconn tcp get max con allow Get the maximum number of TCP clients allowed to connect inbound espconn tcp set max con allow Set the maximum number of TCP clients allowed to connect
41. power switch plus a jumper to set 3 3V or 5V outputs You can even have one breadboard rail be 3 3V and the other 5V but take care not to apply 5V to your ESP8266 By having two power rails one at 3 3V and the other at 5V you can power both the ESP8266 and devices circuits that require 5V When the ESP8266 starts to transmit over wireless that can draw a lot of current which can cause ripples in your power supply You may also have other sensors or devices connected to your supply as well These fluctuations in the voltage can cause problems It is strongly recommended that you place a 10 micro farad capacitor between ve and ve as close to your ESP8266 as you can This will provide a reservoir of power to even out any transient ripples This is one of those tips that you ignore at your peril Everything may work just fine without the capacitor until it doesn t or until you start getting intermittent problems and are at a loss to explain them Let me put it this way for the few cents it costs and the zero harm it does why not Multi meter Logic probe Logic Analyzer When your circuit doesn t work and you are staring at it wondering what is wrong you will be thankful if you have a multi meter and a logic probe If your budget will stretch I also recommend a USB based logic analyzer such as those made by Saleae These allow you to monitor the signals coming into or being produced by your ESP8266 Think of this as the best source of
42. ptr2 int size Compare two regions of memory The return is 0 if they are equal Includes e Oosapi h os memcpy Copy the values of memory void os memcpy void destination void source size t size Copy the memory from the buffer pointed to by source to the buffer pointed to by destination for the number of bytes specified by size Includes e osapi h See also Working with memory os_memset os_malloc Allocate storage from the heap void malloc size t size Allocate size bytes from the heap and return a pointer to the allocated storage Includes mem h See also Working with memory os_zalloc os free os zalloc Allocate storage from the heap and zero its values void zalloc size t size Page 148 Allocate size bytes from the heap and return a pointer to the allocated storage Before returning the storage area is zeroed Includes mem h See also Working with memory os_malloc os free os free Release previously allocated storage back to the heap void os free void pBuffer Release the storage previously allocated by os malloc Oros zalloc back to the heap Includes mem h See also Working with memory os_malloc os_zalloc os_bzero Set the values of memory to zero void os bzero void pBuffer size t size Sets the data pointer to by pBuffer to zero for size bytes Includes e Oosapi h See also Working with memory os_delay_us
43. the device based on port numbers And here is where I want to clarify a detail We route within the machine based on the pair of both protocol and port number So for example if a request arrives at a machine for port 25867 over a TCP connection it is routed to the TCP application watching port 25867 If a request arrives at the same machine for port 25867 over UDP it is routed to the UDP application watching port 25867 What this means is that we can have two applications listening on the same port but on different protocols Putting this more formally the allocation space for port numbers is a function of the protocol and it is not allowed for two applications to simultaneously reserve the same port within the same protocol allocation space Although I used the story of a PC running multiple applications in our ESP8266 the story is similar even though we just run one application on the device If your single application should need to listen on multiple ports don t try and use the same port with the same protocol as the second function call will find the first one has already allocated the port This is a detail that I am happy for you to forget as you will rarely come across it but I wanted to catch it here for completeness Now let us look at what it takes to send a datagram Similar to other functions we need a struct espconn control block This must be configured to use UDP and name the remote IP address and port Once populated we can the
44. to inform the downstream device that it may now send data This is commonly connected to the partner input CTS which is Clear to Send which indicates that it is now acceptable to send data Both RTS and CTS are active low DTR which is Data Terminal Ready is used in flow control When flashing the device using the Eclipse tools and recipes the following are the flash commands that are run as an example and the messages logged 22 34 17 Build of configuration Default for project k blinky mingw32 make exe f C Users Userl WorkSpace k blinky Makefile flash c Espressif utils esptool exe p COM11 b 115200 write flash ff 40m fm qio fs 4m 0x00000 firmware eagle flash bin 0x40000 firmware eagle irom0text bin Connecting Erasing flash head 8 total 8 erase size 16384 Page 53 Writing at 0x00000000 3 Writing at 0x00000400 6 Writing at 0x00007000 96 Writing at 0x00007400 100 Written 30720 bytes in 3 01 seconds 81 62 kbit s Erasing flash head 16 total 41 erase size 102400 Writing at 0x00040000 0 5 Writing at 0x00040400 1 Writing at 0x00067c00 99 Writing at 0x00068000 100 Written 164864 bytes in 16 18 seconds 81 53 kbit s Leaving 22 34 40 Build Finished took 23s 424ms As an example of what the messages look like if we fail to put the ESP8266 into flash mode we have the following 13 47 09 Build o
45. tool chains and syntax to achieve the same result with more ESP8266 oriented tools and techniques The name of the game should be to allow folks to tinker with CPUs and sensors without having to have university degrees in computing science or electrical engineering and if the price one pays to get there is to insert a simple to use illusion then why not If I build a paper airplane and throw it out my window I may get pleasure from that A NASA rocket scientist shouldn t scoff at my activities or lack of knowledge of aerodynamics the folded paper did its job and I achieved my goal However if my job was to put a man on the moon the ability to visualize the realities of the technology at the realistic level becomes extremely important Installing the Arduino IDE with ESP8266 support To assemble this environment one must download a current version of the Arduino IDE This will be about 140 Mbytes I download the ZIP file version and then extract its content Next we launch the Arduino IDE and open the Preferences dialog Page 115 r amp 9 sketch jul12a Arduino 1 6 5 c3 mes Edit Sketch Tools Help New Ctrl N Open Ctrl 0 Open Recent oe here to run once j Examples d Close Ctrl W Save Ctrl S Save As Ctrl Shift S ere to run repeatedly Page Setup Ctrl Shift P Print Ctrl P Preferences Ctrl Comma qm Quit Ctrl Q Arduino Pro or Pro Mini ATmeg 6 MHz on COM11 In the Additional Board
46. transmission and then immediately dispose off or change the buffer What we hand off to the OS is a pointer to a buffer and until the OS tells us that it has finished consuming it we must maintain its integrity See also espconn_regist_recvcb espconn_sent TCP Error handling When a connection is formed between two partners it is essential that we realize that there isn t an actual dedicated underlying connection between them Instead there is only a logical connection that appears to be present over the datagram oriented protocol of IP What this might mean is that if one end of the connection abnormally ends the other end won t immediately know about it As an example if in the real world I make a phone call to you then your phone indicates to you that we have a connection If the battery on my phone dies the telephone network detects that and drops the connection Your phone also hangs up and you know we are no longer in communication In the TCP world that doesn t happen If my TCP phone dies your TCP phone isn t told that mine is gone You may be left sitting there indefinitely listening to silence and waiting for me to say something To resolve that situation TCP introduces a concept called keep alive The notion is very simple With keep alive the two partners periodically exchange a heartbeat communication with each other As long as they each hear the heartbeat of the other they are both still present However if one side
47. you are using GPIOO use it as an input pin as opposed to an output pin The reason for this is that when you are developing solutions you need to bring GPIOO low to place the ESP8266 into flash mode where it reads new programs from the UART This means that you will be changing the input signal to GPIOO If you use the pin as an output there is the possibility that when you change your wiring to bring it low or press a button to bring it low if the signal is high at that time you will short the circuit However if the pin is input then that won t be a problem Ideally avoid using GPIOO altogether and leave it specifically for bootstrapping the device in different modes See also PIN_FUNC_SELECT GPIO_OUTPUT_SET GPIO_DIS_OUTPUT GPIO_INPUT_GET gpio_output_set gpio_input_get Page 91 Working with serial There are two UARTS in the system known as UARTO and UART1 UARTO has its own dedicated TX and RX pins while UARTI is multiplexed with GPIO2 UARTI is output only and hence only has a TX line The serial interface to the ESP8266 can be initialized with a call to the function vart init For example uart_init BIT RATE 115200 BIT RATE 115200 To write a string to the serial port we can then use os printf This has the same format as a printf but writes to the serial port In order to work with UART you must include the vart c uart h and uart_register h files from examples driver lib In your application you m
48. 130 system OS MAS A AA A ast A II 130 YIN MEE 131 system get time rep eir despegue EF ee ELTE RE v NE ARE reve FERE Re E EET HER dees 131 system get rtc time eer iris 131 system_rtc_clock_Cali_prOC ooocccccccconococononocononccnnnnnnnnnnnnnnnnnonononnnnnnnnncrnnnnnnnnnnnnrncnnnnanss 131 SYSteM_T C_MemM_Wiit8 ooooooocoocccccooooooooooaaanaccnnnnonnnnnonnnnnno nono nnnnnnnnnnnnrnnnnnnnnnnnnnnnnnnrnncnnnners 131 system _FtC_MEM_LOad cece cece cece cnnnceeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaeaaeaacaeeeeeeesaeeeeseaeeeeessneees 131 system uart SWdp iad di ot 132 SYSTEM uart de SWap acere tat deep et ene Pus eoe CQ I e Oe ERA UP E a POSEE de PUE Oed 132 system_get_bOOt_VErSiON cceeeeeceeeeeeeeeeeeeeeeeeeeeeeaaaaaeaaeceeeeeeeeeeeeeeeeeeeeesaaeeeeesaeeess 132 system_get_USerbDin_ACAM cccccececeeeeeeeceeeeeeeaeaeeeeeeeeeeeeeeeeeeeeeeeeseeeseeeaaesseseseeeeeeees 132 system get boot modens a e A ai aia a 132 system restart Enhance cccccceeeeeeeceeececeeeeaaaeaeesaaeeeeeeeeeeeeeeeeeeseeaeaaaaascsseseseeeeeeees 132 system update Cpu freg srir e E e aE aa RE D E Er a 132 system get cpu freq nennen ne nne n ens enn rts ne nnne nenas 133 system_get_flaSh_SiZ _MaA cccccceeeeeeeeeeeeeeeeeeceaaaaeaeeeeeeceeeeeeeeeeeeeeeeeeeeaeaaaaaneteees 133 SyStem_Get_rst_infO ccc ceececeeeeeeeeeeeeeeeeeeeeeeeeeeeseaaaaaaaaaaaeeeeeeeeeeeeeeeeeeeeaeaaaaaaanes 133 system_get_Sdk_Ve
49. 15 6 41 PM i _ And now the terminal is active For my purposes I connect this terminal to UARTI of the ESP8266 for debugging while leaving UARTO for flashing new copies of my application Here is an example of what my typical window looks like Page 111 B Problems Tasks E Console Properties 4 Search 49 Terminal X Bs ta Ek BB BB O E Serial COM17 7 19 15 6 41 PM 23 Cee UE PE OE Oe SA Ee HE TE GE ee eee EE OH E OH HH POP PP TE GJ GM gg eee Ee TIA IIA IAE 1 261 0 EHi0 u 4AbASA DAAYn CDOAbASAEAAYYASCADOS 1 11 11 11 11 11 od gp og E eAAbYA F mode sta 18 fe 34 f1 ce 53 softAP 1a fe 34 f1 ce 53 add ife add if1 dhcp server start ip 192 168 4 1 mask 255 255 255 0 gw 192 168 4 1 bcn 100 InitDone del if mode softAP 1a fe 34 f1 ce 53 bcn del if1 usl sul 0 0 add if1 dhcp server start ip 192 168 4 1 mask 255 255 255 0 gw 192 168 4 1 bcn 100 You can invert the colors to produce a white on black visualization which many users prefer Page 112 Programming using the Arduino IDE Long before there was an ESP8266 there was the Arduino A vitally important contribution to the open source hardware community and the entry point for the majority of hobbyists into the world of home built circuits and processors One of the key attractions about the Arduino is its relative low complexity allowing someone to build something quickly and easily Th
50. 3 SPIWP GPIO10 19 SD CMD U SD CMD SPICSO GPIO11 20 GPIO0 U GPIOO SPICS2 15 1 12 GPIO2 U GPIO2 DSO WS UITXD 14 1 12 GPIO4 U GPIO4 CLK_XTAL 16 12 GPIO5 U GPIOS CLK_RTC 24 12 The following are the keys to some of the values in the table e Devices column o ESP 1I o 2 ESP 12 Here are the GPIO pins by mapping Page 90 GPIO Pin Name Notes Risk GPIOO GPIOO U Pin controls state of ESP8266 at boot Caution when used as an output pin GPIO1 UOTXD U Pin is commonly used for flashing the device GPIO2 GPIO2 U Used for UARTI output and as such is likely to be used during development time for debugging Written to when flashed with new firmware GPIO3 UORXD U Pin is commonly used for flashing the device GPIO4 GPIO4 U Only use is as a GPIO GPIOS GPIO5_U Only use is as a GPIO GPIO6 SD CLK U Not exposed on current devices GPIO7 SD DATAO U Not exposed on current devices GPIO8 SD_DATA1 U Not exposed on current devices GPIO9 SD DATA2 U Not exposed on current devices GPIO10 SD DATA3 U Not exposed on current devices GPIO11 SD CMD U Not exposed on current devices GPIO12 MTDI U GPIO13 MTCK_U GPIO14 MTMS U GPIO15 MTDO_U Used to control UARTO RTS and hence may have an influence on firmware flashing since the firmware data arrives via UARTO GPIO16 29 The maximum output current from a GPIO pin is only 12mA Given a choice if
51. 66 can execute as a WiFi Station a WiFi access point or both a station and an access point These are considered the three possible global operating modes The operating mode that is used when the device boots is retained in flash memory but can be changed with a call to wifi set opmode This will change the current mode as well as record the mode to be used on next restart To merely change the mode without changing the next boot mode we can use wifi set opmode current To retrieve the current mode we can use wifi get opmode and to retrieve the mode used on boot we can use wifi get opmode default Quite why we have the option to change the current mode without saving it in flash memory is a mystery Presumably there is some occasion when such a feature was needed and thus exposed but what ever that reason may be is not obvious See also wifi get opmode wifi get opmode default wifi set opmode wifi set opmode current Handling WiFi events During the course of operating as a WiFi device certain events may occur that ESP8266 needs to know about These may be of importance or interest to the applications running within it Since we don t know when or even if any events will happen we can t have our application block waiting for them to occur Instead what we should do is define a callback function that will be invoked should an event actually occur The function called wifi set event handler cb does just that It registers a fu
52. 8266 called gpio output set This function takes four 16 bit values to be used as masks against the two 16 bit arrays The first mask is called the set mask A 1 value in the set mask sets the corresponding bit value to be 1 in the value array The second mask is called the clear mask A 1 value in the clear mask sets the corresponding bit value to be 0 in the value array Notice that in both cases if the masks have a 0 value the original values are unchanged The third mask is called the enable output mask A 1 value in the enable output mask sets the corresponding GPIO to be in output mode Page 88 The fourth mask is called the enable input mask A 1 value in the enable input mask sets the corresponding GPIO to be in input mode Take care not to set a GPIO to be both input and output or to have a value of both 1 and 0 The results will be undefined Constants are defined for each of the bit positions Those constants are e BITO 2 0 BITI 2 1 e BIT31 2731 So for example If we want to set GPIO 5 to be input we might code gpio output set 0 0 0 BIT5 to set GPIO 4 to be output and have a high value we might code gpio output set BIT4 0 BIT4 0 to set GPIO 0 and 1 to both be output and the first to be 1 and the second to be 0 gpio output set BITO BIT1 BITO BIT1 0 If we wish to retrieve the values of the GPIOs we can use the gpio input get method This returns a bit mask containing all the b
53. AT CWSAP_ CUR Configuration of softAP mode AT CWSAP_CUR lt ssid gt lt pwd gt lt chl gt lt ecn gt AT CWSAP DEF Configuration of softAP mode AT CWSAP DEF lt ssid gt lt pwd gt lt chl gt lt ecn gt Page 32 AT CWLIF List of IPs connected in softAP mode AT CWDHCP CUR AT CWDHCP_CUR lt mode gt lt en Enable or disable DHCP mode o 0 softAP o 1 station o 2 softAP station en o Q0 Enable o Disable AT CWDHCP DEF AT CWDHCP_DEF lt mode gt lt en Enable or disable DHCP gt mode o 0 softAP o 1 station o 2 softAP station en o 0 Enable o Disable AP CWAUTOCONN lt enable gt AT CIPSTAMAC CUR Set get MAC address of station AT CIPSTAMAC_CUR lt mac gt Set get MAC address of station AT CIPSTAMAC_DEF Set get MAC address of station AT CIPSTAMAC DEF lt mac gt Set get MAC address of station AT CIPAPMAC_CUR Set get MAC address of softAP AT CIPAPMAC_CUR lt mac gt Set get MAC address of softAP AT CIPAPMAC DEF Set get MAC address of softAP AT CIPAPMAC_DEF lt mac gt Set get MAC address of softAP AT CIPSTA CUR lt iP gt Set the ip address of station AT CIPSTA CUR Get the IP address of station For example CIPSTA 0 0 0 0 AT CIPSTA_DEF lt iP gt Set the ip address of station Page 33 AT CIP
54. CHO PIN while val 1 amp amp system get time startTime lt 20 1000 val GPIO INPUT GET ECHO PIN if val 0 uint32 delta system get time startTime Calculate the distance in cm uint32 distance 340 29 100 delta 1000 1000 2 os printf Distance d n distance else os printf No echo n End of timerCallback void user init void uart init BIT RATE 115200 BIT RATE 115200 Setup ultrasonics pins as GPIO SetAsGpio TRIG PIN setAsGpio ECHO PIN setupBlink 15 Set the trigger pin to be default low GPIO OUTPUT SET TRIG PIN 0 os timer setfn amp myTimer timerCallback NULL os timer arm amp myTimer 1000 5 End of user init Once this has been written and tested we will make a second pass at the puzzle but this time using an interrupt to trigger the response to the echo See also e GPIOs Page 134 Sample WiFi Scanner A WiFi scanner is an application which periodically scans for available WiFi networks and shows them to the user In our design we will scan periodically and remember the set of networks we find When we perform re scans we will check to see if each of the networks located is a network we have previously seen and if not list it to the user We will also keep a last seen time for each network and if a network has not been seen for a minute then we will forget about it such
55. COM amp LPT you will find entries for each of the COM ports The COM ports don t provide you a mapping that a particular USB socket is hosting a particular COM port so my poor suggestion is to pull the USB from each socket one by one and make a note of which COM port disappears or appears if you are inserting a USB Page 36 File Action View Help B m gt IEEE 1394 Bus host controllers gt 3 Imaging devices gt EY Intel WiUSB gt Keyboards b Mice and other pointing devices gt Monitors T Network adapters aF Ports COM amp LPT B Processors gt J Security Devices gt gt Smart card readers P m Sound video and game controllers gt My System devices b Universal Serial Bus controllers See also Connecting to the ESP8266 Working with serial Breadboards I find I can never have too many breadboards I suggest getting a few full size and half size boards along with some 24 AWG connector wire and a good pair of wire strippers Keep a trash bin close by otherwise you will find yourself knee deep in stripped insulation and cut wire parts before you know it I also recommend some Dupont male male pre made wires Ribbon cable can also be useful Page 37 Power We need electricity to get these devices working I choose the MB102 breadboard attachable power adapters These can be powered from an ordinary wall wart mains adapter or from USB The devices have a master on off
56. Cs design basic circuits design printed circuit boards and construct pre made boards with the ICs pre attached immediately ready for our use It is these boards that capture our interest and that we can buy for a few dollars on ebay There are a variety of board styles available The two that I am going to focus on have been given the names ESP 1 and ESP 12 It is important to note that there is only one ESP8266 processor and it is this processor that is found on ALL breakout boards What distinguishes one board from another is the number of GPIO pins exposed the amount of flash memory provided the style of connector pins and various other considerations related to construction From a programming perspective they are all the same Maturity It is my belief that the ESP8266 is immature This is not a bad thing Everybody and everything has to start somewhere On the plus side there is a whole new wealth of territory to be explored and new features and functions and usage patterns to be discovered On the down side it does not yet have the richness of tutorials samples and videos that accompany other microprocessor systems Its documentation is not brilliant and some of the core questions on its usage are still being examined How this sits with you is a function of your intent of tinkering in this area If you want to follow the paths that have been followed many times before other processors will be more attractive However if you like a sense
57. D You will be surprised how good a feeling it will give simply knowing that something is alive within the device each time you see it blink The cost of running the timer and changing the I O value to achieve a blinking should not be a problem during development time so I wouldn t worry about side effects of doing this Obviously for a published application you may not desire this and can simply remove it However although this is a trivial circuit it has a lot of uses during development First you will always know that the device is operating If the LED is blinking you know the device has power and logic processing control If the light stops blinking you will know that something has locked up or you have entered an infinite loop Another useful purpose for including the Blinky is to validate that you have entered flash mode when programming the device If we understand that the device can boot up in normal or flash mode and we boot it up in flash mode then the Blinky will stop executing This can be useful if you are using buttons or jumpers to toggle the boot mode as it will provide evidence that you are not in normal mode On occasion I have mis pressed some control buttons and was quickly able to realize that something was wrong before even attempting to flash it as the Blinky was still going Here is some simple code for setting up a Blinky In this example we use GPIO4 as the LED driver First the code we place in user init Page 61
58. Delay for microseconds void os delay us uintl6 us Delay for a maximum interval of 65535 microseconds Includes Page 149 e Oosapi h See also Timers and time os printf Print a string to UART void os printf char format The format flags that are known to work include e d display a decimal e 1d display a long decimal e x display as a hex number e s display as a string An display a newline includes a prefixed carriage return The output text is sent to the function registered with os install putci By default this is UARTO but can be changed to UARTI by setting the uart1 write char function Includes e Oosapi h See also Debugging os install putc1 Register a function print a character void os install putcl void pFunc char c Register a function that will be called by output functions such as os printf that will log output For example this can be used to write to the serial ports When a call is made to the supplied uart init method the writing function is set to write to UARTI Includes e Oosapi h See also os printf os random unsigned long os random Page 150 Includes e osapi h os_get_random int os get_random unsigned char buf size t len Includes e Oosapi h os strlen Get the length of a string int os strlen char string Return the length of the null terminated string Includes e osapi h Os strcat Concatenate two strings
59. EA E E EA EAE A A E ET 197 FORUM Sien a a e aea eaa a Oaa aa ERAS 200 Reference documents ea a e E aa T edea a aeai 200 Clio 201 jb OPERE 201 nlt 201 Max Filippov jomvbkbc GCC compiler for XtenSa oooocccoocoooococcconaccccncnnnnnonncnnnccnnnnnns 201 Mikhail Grigorev CHERTS Eclipse for ESP8266 development 202 Ivan Grokhotkov igrr Arduino IDE for ESP8266 development sssssssse 202 Spritetm HTTP server for ESP8266 sse emen 202 Areas to Research oe dee A AAA abad 202 Page 11 Introduction Howdy Folks Ive been working in the software business for over 30 years but until recently hadn t been playing directly with Micro Processors When I bought a Raspberry PI and then an Arduino I m afraid I got hooked In my house I am surrounded by computers of all shapes sizes and capacities any one of them with orders of magnitude more power than any of these small devices however I still found myself fascinated When I stumbled across the ESP8266 earlier this year it peaked my interest I hadn t touched C programming in decades I m a Java man these days As I started to read what was available in the way of documentation from the excellent community surrounding the device I found that there were only small pockets of knowledge The best source of information was and still is the official PDFs for the SDK from E
60. I recommend using MB102 breadboard power supplies however make sure that you set the jumper cables to be 3 3V You will ruin your ESP8266 if you try and power it at 5V Once it is all wired up you will need a PC with two open USB ports Parts list Page 40 e Breadboards 2 half size 3 50 for 2 e ESP 12 plus mounting boards 3 sets 3 80 each 11 40 e CP2102 USB gt UARTs 2 pieces 3 10 USB male to female extenders 2 pieces 1 00 each 2 00 e 24 AWG wire 5 meters for 1 12 8pin 2 54mm stackable long legged female headers 10 pieces for 3 95 Reddiffuse LEDs A handful 1 00 Resistors Some 10K some 20K some 330Ohm A handful 1 00 Capacitors Some 10 micro farad 1 00 All told it comes to about 30 some shipping I buy all my components through ebay from Chinese suppliers that give me the price quality I am looking for The name of the game though is patience Once you order it usually takes 2 3 weeks for the parts to arrive so be patient and use the time to watch you tube videos on electronics projects and the relevant community forums Eventually you are likely going to want to build a permanent circuit for your development On a strip board the circuit I built looks liked Page 41 Configuration for flashing the device Later on in the book you will find that when it comes time to flash the device with your new applications you will
61. L crio14 1 p 000 O crioiz 4 yn Po 0 9 vcc GND Page 15 Here is a description of the various pins Name Description VCC 3 3V GPIO 13 Also used for SPI MOSI GPIO 12 Also used for SPI MISO GPIO 14 Also used for SPI Clock GPIO 16 CH_PD Chip enable Should be high for normal operation e 0 Disabled e Enabled ADC REST External reset e 0 Reset e Normal TXD UART 0 transmit RXD UART 0 Receive GPIO 4 Regular GPIO GPIO 5 Regular GPIO GPIO 0 Should be high on boot low for flash update GPIO 2 Should be high on boot GND Ground Here is a schematic for connecting an instance Page 16 3 3V 3 3V 3 3V U2 ESP8266 FTDI Basic Programmer GPIOO Reset s2 Next we see an image of this circuit built out on a breadboard Page 17 LAMA IV Bo 444 3224 If we just wish to use our breakout board we have the following when mounted on a breadboard we can have the following setup ifi Ii This gives us two sets of 8 pin connectors The first set is Page 18 Set 1 Pin Color GND GPIO15 GPIO2 GPIOO GPIOS5 GPIO4 Grey RXD White TXD The second set is Set 2 Pin Color VCC GPIO13 GPIO12 GPIO14 GPIO16 CH PD Grey ESP 1 The ESP 1 board is an ESP8266 on an 8 pin board It is not at all breadboard friendly b
62. Lookup a host by a name int hostByName const char hostName IPAddress amp result Page 123 Look up a host by name and get its IP address This function returns 1 on success and 0 on failure WiFi hostname Retrieve and set the hostname used by this station String hostname bool hostname char hostName bool hostname const char hostName bool hostname String hostName WiFi isHidden Determine if the scanned network item is flagged as hidden bool isHiddem uint8 t networkItem Determine if the scanned network item is flagged as hidden WiFi locallP Get the station IP address IPAddress localIP Get the IP address for the station WiFi macAddress Get the station interface MAC address uint t macAddress uint8 t mac String macAddress Get the station interface MAC address WiFi mode Set the operating mode void mode WiFiMode mode Set the operating mode of the WiFi This is one of WIFI OFF Switch off WiFi WIFI STA Bea WiFi station wWIFI AP Bea WiFi access point WIFI AP STA Be both a WiFi station and a WiFi access point Page 124 See also Defining the operating mode WiFi printDiag Log the state of the WiFi connection void printDiag Print amp dest Log the state of the WiFi connection WiFi RSSI Retrieve the RSSI value of the scanned network item int32 t RSSI uint8 t networkItem Retrieve the RSSI value of the scanned network item WiFi scanComp
63. Ls for all attributes This serves as a termination record Here is an example definition for a minimal set of built in URLs HttpdBuiltInUrl builtInUrls NULL NULL NULL Y The cgiSendCallback is a function with the following signature int functionName HttpdConnData connData Includes httpd h httpdGetMimetype char httpdGetMimeType char url Examine the ur1 passed in and by looking at its file type determine the MIME type of the data If no file type is found then the default MIME type is text html Includes httpd h Page 212 httpdUrlDecode int httpdUrlDecode char val int valLen char ret int retLen Decode a URL according to URL decoding rules The encoded url is supplied in va1 with a length of valLen bytes The resulting decoded url string will be stored at ret with a maximum length of retLen The actual length is returned by the function call itself Includes httpd h httpdStartResponse void httpdStartResponse HttpdConnData conn int code Start sending the response data down the TCP connection to the browser The coae value is the primary browser response code Includes e httpd h httpdSend int httpdSend HttpdConnData conn const char data int len Send data to the browser through the TCP connection The data is supplied as data and the len parameters is the number of bytes to write If len 1 then data is assumed to be a NULL terminated string
64. Name void pingOpt void pingResp The parameters passed in are pingopt which is a pointer to the struct ping option and pingResp Which is a pointer to a struct ping resp Page 187 Includes ping h See also s Ping request struct ping_option mDNS APIs espconn_mdns_init void espconn mdns init struct mdns info info espconn mdns close void espconn mdns close espconn mdns server register void espconn mdns server register espconn mdns server unregister void espconn mdns server unregister espconn mdns get servername char espconn mdns get servername espconn mdns set servername char espconn mdns set servername espconn mdns set hostname void espconn mdns set hostname char name espconn mdns get hostname char espconn mdns get hostname Page 188 espconn_mdns_disable void espconn mdns disable espconn_mdns_enable void espconn mdns enable GPIO Pin names are PERIPHS IO MUX GPIOO U PERIPHS IO MUX GPIO2 U PERIPHS IO MUX MTDI U PERIPHS IO MUX MTCK U GPIO 13 PERIPHS IO MUX MTMS U GPIO 14 Pin Name Function 1 Function 2 Function 3 Function 4 Physical pin MTDI U MTDI D2S8I DATA HSPIQ MISO GPIO12 10 MTCK U MTCK DSI BCK HSPID MOSI GPIO13 12 MTMS U MTMS DSI WS HSPICLK GPIO14 9 MTDO U MTDO DSO BCK HSPICS GPIOI5 13 UORXD U UORXD ID280 DATA GPIO3 25 UOTXD U UOTXD SPICS1 GPIO1 26
65. P NOW dida 186 TOMUS 186 ESP NOW lia AAA eee ee eo a Team a anid da mele 186 ESP_NOW_regiSter_POCV_CD ccccccceseeeeeeseeeeeeeeeeeeeeceeeeaaaaaaaeaaaaceeeeeeeeeeeeesseesaageeessanaeess 186 ESP_NOW_UNregister_FECV_CD cccceeeeeeeeeeeeeeeeeeeeeeeceeeeeeeeeaaaaeeeaeceeeeeeeeeeeesaaeeeseeaaneeees 186 esp NOW ui a doo 186 A A coctueandagadcadenheercsnendeae 186 esp now MN 186 esp now set self role ssssssssesssssssssssssssssseeeenene enne nennen irren nnn rns n nnne 186 esp rniow get self ole neci aeree eoi deep iie e reb eot ea EE Ede ees 186 esp riow sel peer role ne eee eese t d dae aE EUER EE XR PH Foe 186 esp now get peer rolean eon dpi a e nnn nnne nnns enhn EERE An raeas 186 esp now set peer Key e c Ede da aa 186 esp now get peer Key arerin i eae i e a era r nri r nnn nnne herren nnns nnne 186 Data structures c repere daa 186 station eoo W 186 struct softap config oed da PUER ERE IR AS 187 SUPUCT STATION fO NN 187 struct dhcps lease seesssssssssssssseseeeeeee seen E E nini rn nnns rsen nnns 188 struct DSS IO vital d eea EYE FARE EE NER Le du d EET NER e ERR ea 188 struct IP uo 189 SIFUCE FESESIBIO 5s e aed weds etes eod voe E DO NEN CL ete Pet asa 189 gerente M 190 CSP ICD ES 191 Page 10 SUCEDA nt d eio E AA iae rens 191 ipaddr mE 191 struct PING OPM b er
66. R6 10kQ GPIOQ Reset TX Blue RX Black CH_PD Green RST Yellow GPIOO White GPIO2 Grey VCC Orange GND Purple s s s 9 s s The default serial connection speed seems to be 115200 Page 24 Adafruit HUZZAH The Adafruit HAZZAH is a breakout board for the ESP8266 It is the most breadboard friendly of the solutions I have encountered so far See also Adafruit HUZZAH SparkFun WiFi Shield ESP8266 SparkFun have produced a WiFi shield for the Arduino This is an ESP8266 mounted on a well designed PCB that mates with the Arduino This makes communicating with the ESP8266 via AT commands extremely easy with no wiring required Simply push the shield board into the sockets of the Arduino and you are done See also SparkFun WiFi Shield ESP8266 Connecting to the ESP8266 The ESP8266 is a WiFi device and hence we will eventually connect to it using WiFi protocols but some bootstrapping is required first The device doesn t know what network to connect to which password to use and other necessary parameters This of course assumes we are connecting as a station if we wish the device to be an access point or we wish to load our own applications into it the story gets deeper This implies that there is a some way to interact with the device other than WiFi and there is the answer is UART Serial The ESP8266 has a dedicated UART interface with pins labeled TX and RX
67. SD CLK U SD CLK SPICLK GPIO6 21 SD_DATAO U SD_DATAO SPIQ GPIO7 22 SD_DATA1 U SD DATAI SPID GPIO8 23 SD DATA2U SD DATA2 SPIHD GPIO9 18 SD DATA3 U SD_DATA3 SPIWP GPIO10 19 SD CMD U SD CMD SPICSO GPIO11 20 GPIOO U GPIOO SPICS2 15 GPIO2 U GPIO2 DSO WS UITXD 14 GPIO4 U GPIO4 CLK XTAL 16 GPIO5 U GPIOS CLK_RTC 24 Pin functions are e FUNC GPIOO e FUNC GPIOI2 Page 189 FUNC GPIO13 FUNC GPIO14 FUNC GPIOI5 FUNC_UORTS FUNC GPIO3 FUNC_U0TXD FUNC GPIOI FUNC_SDCLK FUNC_SPICLK FUNC SDDATAO FUNC_SPIQ FUNC UITXD FUNC SDDATAI FUNC SPID FUNC_UIRXD FUNC SDATA1 UIRXD FUNC SDDATA2 FUNC SPIHD FUNC_GPIO9 FUNC SDDATA3 FUNC SPIWP FUNC_GPIO10 FUNC SDCMD FUNC_SPICSO FUNC_GPIO0 FUNC GPIO2 FUNC UITXD BK FUNC UOTXD BK FUNC GPIO4 Page 190 FUNC GPIOS LED GPIO FUNC PIN_PULLUP_DIS Disable pin pull up PIN PULLUP DIS PIN NAME See also GPIOs PIN PULLUP EN Enable pin pull up PIN PULLUP EN PIN NAME See also GPIOs PIN_FUNC_SELECT Set the function of a specific pin PIN FUNC SELECT PIN NAME FUNC See also GPIOs GPIO ID PIN Get the id of a logical pin GPIO ID PIN pinNum Convert a logical pin number into the identity of a pin This is an interesting function as GPIO ID PIN x is coded to equal x The question now becomes whether or not one still needs to code GPIO_ID_PIN when accessing GPIO functions
68. STA DEF Get the IP address of station For example CIPSTA 0 0 0 0 AT CIPAP CUR Set the ip address of softAP AT CIPAP CUR lt IP gt lt gat eway gt lt netmask gt Set the ip address of softAP AT CIPAP DEF Set the ip address of softAP AT CIPAP DEF lt IP gt lt gat eway gt lt netmask gt Set the ip address of softAP AT CIFSR Returns the IP address and gateway IP address TCP IP networking AT CIPSTATUS Information about connection Response format is STATUS lt stat gt CIPSTATUS lt id gt lt type gt lt addr gt lt port gt lt tetype gt stat o 2 GotIP o 3 Connected o 4 Disconnected e id Id of the connection e type TCP or UDP e addr IP address e port Port number tetype o 0 ESP8266 runs as client o 1 ESP8266 runs as server AT CIPSTART lt type gt lt addr gt lt port gt lt local port gt lt mode gt Start a connection when CIPMUX 0 e type TCP or UDP addr Remote IP address port Remote port e local port For UDP only e mode For UDP only o 0 destination peer entity of UDP is fixed o destination peer entity may change once o 2 destination peer entity may change AT CIPSTART lt id gt lt type gt lt addr gt lt port gt lt local port gt lt mode gt Start a connection when CIPMUX 1 e id 0 4 value of connection e type TCP
69. UDP datagram sint8 espconn regist recvcb struct espconn espconn espconn recv callback recv cb Page 178 The format of the callback function is void functionName void arg char pData unsigned short len Where args is a pointer to a struct espconn pData is a pointer to the data received and len is the length of the data received Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument See also Sending and receiving TCP data UDP espconn_create espconn_sent Send data through the connection to the partner sint8 espconn sent struct espconn pEspconn uint8 pBuffer uint16 length The pEspconn parameter identifies the connection through which to transmit the data The pBuffer parameter points to a data buffer to be transmitted The length parameter supplies the length of the data in bytes that is to be transmitted Return code of 0 on success otherwise the code indicates the error ESPCONN MEM Out of memory ESPCONN ARG Illegal argument See also Sending and receiving TCP data UDP ipaddr_addr Build a TCP IP address from a dotted decimal string representation unit32 ipaddr addr char addressString Return an IP address 4 byte value from a dotted decimal string representation supplied in the addressString parameter IP4_ADDR Set the value of a variable to an IP address from its decimal representation P
70. Upgrade APIs system_upgrade_userbin_check uint8 system upgrade userbin check Page 172 system_upgrade_flag_set void system upgrade flag set uint8 flag system_upgrade_flag_check uint8 system_upgrade flag check system_upgrade_start bool system_upgrade_start struct upgrade server info server system_upgrade_reboot void system upgrade reboot Sniffer APIs wifi_promiscuous_enable void wifi promiscuous enable uint8 promiscuous wifi promiscuous set mac void wifi promiscuous set mac const uint8 t address wifi promiscuous rx cb void wifi promiscuous rx cb wifi promiscuous cb t cb wifi get channel wifi set channel Smart config APIs smartconfig start bool smartconfig start sc callback t cb uint8 log Page 173 smartconfig_stop bool smartconfig stop void SNTP API Handle Simple Network Time Protocol request sntp setserver Set the address of an SNTP server void sntp serverserver unsigned char index ip addr t addr Set the address of one of the three possible SNTP servers to be used The index parameter must be either 0 1 or 2 and specifies which of the SNTP server slots is to be set The addr parameter is the IP address of the SNTP server to be recorded Includes sntp h See also Working with SNTP sntp getserver Retrieve the IP address of the SNTP server ip addr t sntp getserver unsigned char index Retrieve the IP address of a previously registered SNTP server The index
71. W struct espconn or the original one See also The ESPConn architecture espconn_accept espconn_regist_disconcb Register a function that will be called back after a disconnection sint8 espconn regist disconcb struct espconn espconn espconn connect callback discon cb The signature of the disconnect callback function is the same as the connect callback void functionName void arg where arg is a struct espconn pointer See also TCP The ESPConmn architecture espconn_regist_reconcb Register a function that will be called when an error is detected sint8 espconn regist reconcb struct espconn espconn espconn reconnect callback recon cb The signature of the callback function is void functionName void arg sint8 err The arg parameter is a pointer to a struct espconn The err parameter is one of the following Page 182 ESPCONN TIMEOUT ESPCONN ABRT ESPCONN RST ESPCONN_CLSD ESPCONN CONN ESPCONN HANDSHAKE ESPCONN PROTO MSG See also The ESPConn architecture TCP espconn_accept struct espconn espconn_regist_write_finish See also The ESPConn architecture espconn_set_opt Define which options to turn on for a connection sint8 espconn set opt struct espconn espconn uint8 opt This function should be called in an espconn connect callback The espconn parameter is the control block for the connection that is to be modified The opt parameter is
72. X106 Espressif SDK Documentation L Utilites Examples The result of this will be a new directory structure at C Espressif Page 105 There are other dependencies that you will need which are listed at the link above These include A Java runtime environment I use the latest Java 8 from Oracle Eclipse environment with C C developer tools I use the latest Mars release e MinGW Unix tools and utilities that execute on Windows MinGW installation helper A cache and list of the MinGW packages that need to be installed for correct operation The Makefiles supplied with the package are key They have been crafted to provide the easiest compiles The targets contained within the Makefiles include e all Compile all the code but do not flash e clean Clean any previous builds e flash Compile the code if needed and then flash e flashboot flashinit flashonefile There are some flags that are used with the Makefile that you can edit These include VERBOSE 1 Enable verbosity which includes debug information Specifically the compilation commands are shown See also Eclipse org Eclipse C C Development Tooling CDT Primary forum thread Installing the Eclipse Serial terminal Although there are many excellent serial terminals available as stand alone Windows applications an alternative is the Eclipse Terminal which also has serial support This allows a
73. a bit encoding of flags that are to be set on The opt parameter is an enum of type espconn option Enum Name Value ESPCONN_REUSEADDR 0x01 ESPCONN_NODELAY 0x02 ESPCONN_COPY 0x04 ESPCONN_KEEPALIVE 0x08 Bits that are not set on are left unchanged from their current existing values Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument Page 183 See also espconn clear opt espconn_set_keepalive espconn_get_keepalive espconn_clear_opt Define which options to turn off for a connection sint8 espconn clear opt struct espconn espconn uint8 opt Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument The opt value is an enum of type espconn option Enum Name Value ESPCONN REUSEADDR 0x01 ESPCONN_NODELAY 0x02 ESPCONN_COPY 0x04 ESPCONN KEEPALIVE 0x08 See also TCP Error handling espconn_set_opt espconn_set_keepalive espconn_get_keepalive espconn_regist_time Define an idle connection timeout value sint8 espconn regist time struct espconn espconn unit32 interval uint8 typeFlag If a connection is idle for a period of time the ESP8266 is configured to automatically close the connection It appears that the default is 10 seconds The espconn parameter describes the connection that is to have its timeout changed The interval
74. ad as aeu il dtm el 100 Installing the Eclipse Serial terminalis ieee cere eat e ecd ca deese etu ete ts 103 Programming using the Arduino IDE urit abi 110 Implications of Arduino IDE SUPPOTt cccceeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaeaeaaeeeeeeeeeeaaaeeeeeaeneeees 111 Page 3 Installing the Arduino IDE with ESP8266 suppott cccceeeeeeeeeeeeeeaeeeeeeeaeeeeeesaeneeees 112 The Arduino IDE ESP8266 Libraries ccccccceeeeeeeeeeeeeeeaeeeeeeeeeeeeeeeeeeeeeeeeeeeeseaaaaeaaanees 117 O o H 117 Sample applications etc e ede Eee i esc id vs e e i POE PUE Dre Ak 117 Sample Light an LED based on the arrival of a UDP datagram sessssssss 117 Sample Ultrasonic distance MeasureMent oocococococccccccnccnnnnnnnncnnnnnnnnnnnnnncnnnnnnnnnnnnnnnncnnnnnnn 119 Sample WIFI Scanner sce ce edi des 122 Sample Libraries ei rrr aed dias 123 EUNCUON II EHE EM 123 thM de TOSUING oaa doen oe esto e eh Ae ek oe Anne dca ee MERE du a ah RE neus 123 GhieckETrTOF 4o de c p p AE ec OE m D eee hana dn es 123 CelayMINISCCOMGS me E does aoise 123 GUMPBSSINFO sai AA tang eee teh weston is 123 GUMPESPCONN iiris n hese Ad tens aes der tee 123 dumpResta buin ad hate a de ee a ee deed 123 GUMP State inicios 124 error TOS UNG ci a 124 A HEURE 124 flashisizeAndMap TOSI G io te petu e drea ti di da 124 sre ER EMITE 124 rds sce
75. aer eg Eae eer Pear idus 182 i2c master readByte aede deve t eite idet e os te etd vase dee eue EVEN EY 182 I2c_master_writeByte cccccceseseeeseeeeeeeeeeeeeeeeeeeeeeaaaaaaaaeaaaaaeeeceeeeeeeeseeeseseeeaaaaaeseseneees 182 120 Master SAC iii A einai atalino 182 Page 9 I2c miasetr getACk edet E E E E T 183 PLA iiie et e E a 183 cache MUSH e E 183 Spl leds 9bIE WITO 4 dai e A reete e ER o d dde E RE Tele ae 183 spi mast Byte WTO Pe e eve orn i net nee Eee A E AAA a 183 spi byte write espslave sssssssssssssssssssseseeeeeeeennnennnmnn nnn nenne nennen nennen rris 183 SPIS VE Milani a a a a a a a Nae 183 Spi Slave isr handler dettes eee rrt Rode RR Xx eR EUER EXER EN RER ER ERY TR ea ads 183 hspi master readwrite repeat ssssssssssssssssssssssssseeeeennne menn ennemis 183 SDISteSEIFIU Ses Saved reet ndo deese ad c andere eene ede ER RR Ee Bees ee tb rer e ten 183 PAM API Sica ct He dette e Dex eere ra de tet ed E A Be Ced e CVE RE e REN 183 DWITL ANIL 1i cer dete raro bett bodies 183 DWID Stat tese Bee t eb ih Pe eor ur Edel E 184 pwrmzset QUEy A er e eere th EV Nee Tyee eevee ex ede o vv PT 184 pwm gedit A a ii a is 184 pwm set period rcm Re XR ERCO WES EROR Fen RN MES RNC RRMERE ER S FA Fe EURIE ee Pu debe tens 185 pwm get period CE 185 CDAS EA E S 185 set_pwm_debug_en uint8 print_eN cocccccnccccccnnnonoononanncccnnononnnnnnnnnnnnnnnonnnnnnnnnnnnnnnnnnnnns 185 A O E 185 ES
76. age 179 IP4 ADDR struct ip addr addr a b c d The addr parameter is a pointer to storage to hold an IP address This may be an instance of struct ip addr auint32 uint8 4 It must be cast to a pointer to a struct ip addr if not already of that type The parameters a b c and d are the parts of an IP address if it were written in dotted decimal notation Includes e ip addr h See also struct ip_addr IP2STR Generate four int values used in a os printf statement IP2STR ip_addr t address This is a macro which takes a pointer to an IP address and returns four comma separated decimal values representing the 4 bytes of an IP address This is commonly used in code such as os printf d d d sd n IP2STR amp addr TCP APIs espconn_accept Listen for an incoming TCP connection sint8 espconn accept struct espconn espconn After calling this function the ESP8266 starts listening for incoming connections Any callback functions registered with espconn regist connectcb will be invoked when new connections arrive Return code of 0 on success otherwise the code indicates the error ESPCONN MEM Out of memory ESPCONN ISCONN Already connected ESPCONN ARG Illegal argument See also TCP espconn_regist_connectcb espconn_delete Page 180 espconn_get_connection_info sint8 espconn get connection info struct espconn espconn remot info pcon info uint8 typeFlags
77. age level from a pin between 0 and some maximum value and convert that analog voltage into a digital representation Varying the voltage applied to the pin will change the value read The ESP8266 has an analog to digital converter built into it with a resolution of 1024 distinct values What that means is that 0 volts will produce a digital value of 0 while the maximum voltage will produce a digital value of 1023 and voltage ranges between these will produce a correspondingly scaled digital value To read the digital value of the analog voltage the function called system adc read should be called The pin on the physical ESP8266 from which the voltage is read is called Tout and serves no other purpose The input range on the pin is from OV to 1V This implies that the input voltage to the ADC can not be the maximum voltage used to power the ESP8266 itself 3 3V So we will need to use a voltage divider circuit Vin Ry Vout The formula to map these out is Vout Re Vin R1 R2 Since we know Vout is going to 1V and vin is 3V and we choose R2 to be 10K we find R2 Vin p gt Vout R1 and for our values Page 96 gR1 10000 3 3 _10000 23000 1 0 A common 22K resistor will work well Here is an example What this example does is print the value read from the ADC every second os timer t myTimer void timerCallback void pArg uintl6 adcValue system adc read os printf adc din adcValue End of t
78. ally is as simple as that Here is an example application package kolban import import impor impor impor impor public Lott java io OutputStream java net Socket org apache commons cli CommandLine org apache commons cli CommandLineParser org apache commons cli DefaultParser org apache commons cli Options class SocketClient private String hostname private int port public static void main String args Options options new Options options addOption h true hostname options addOption p true port CommandLineParser parser new DefaultParser try CommandLine cmd parser parse options args SocketClient client new SocketClient client hostname cmd getOptionValue h client port Integer parselnt cmd getOptionValue p client run catch Exception e e printStackTrace public void run try int SIZE 65000 byte data new byte SIZE for int i 0 i lt SIZE i data i X Socket sl new Socket hostname port OutputStream os sl getOutputStream os write data sl close System out println Data sent catch Exception e e printStackTrace End of class End of file To configure a Java application as a socket server is just as easy This time we create an instance of the SocketServer class using Page 101 SocketServer serverSocket new SocketS
79. an Scan for available access points bool wifi station scan struct scan config config scan done cb t callbackFunction We can scan the WiFi frequencies looking for access points We must be in station mode in order to execute the command When the function is executed we provide a callback function that will be asynchronously invoked at some time in the future with the results The scan config structure contains e uint8 ssid uint8 bssid e uint8 channel uint8 show hidden If we supply this structure then only access points that match are returned The scan config parameter can be NULL in which case no filtering will be performed and all access points will be returned The scan done cb t is a function with the following structure void functionName void arg STATUS status The arg parameter is a pointer to a struct bss info It is important to note that the first entry in the chain must be skipped over as it is the head of the list To get the next entry we can use STAILQ NEXT pBssInfoVar next Page 162 The AUTH_MODE is an enum Enum name Value AUTH_OPEN 0 AUTH_WEP 1 AUTH_WPA_PSK 2 AUTH_WPA2 PSK 3 AUTH_WPA_WPA2 PSK 4 STATUS is an enum containing Enum name Value OK 0 FAIL 1 PENDING 2 BUSY 3 CANCEL 4 On success the function returns true and false on a failure The name of this function is peculiar Given that it appears to locat
80. anation to fully appreciate them e dhcpe DHCP client e dhcps DHCP server e softap Access point implemented in software wps Unknown e sntp Simple Network Time Protocol e mdns Multicast Domain Name System e uart Universal asynchronous receiver transmitter e pwm Pulse width modulation Timer functions Timer functions allow us to register functions that will be executed at a time in the future or periodically after time passes We also group functions that manipulate or retrieve time values in this set os timer arm Enable a millisecond granularity timer void os timer arm os timer t pTimer uint32 t milliseconds bool repeat Arm a timer such that is starts ticking and fires when the clock reaches zero The pTimer parameter is a pointed to a timer control structure The milliseconds parameter is the duration of the timer measured in milliseconds The repeat parameter is whether or not the timer will restart once it has reached zero Includes e Oosapi h See also Timers and time os_timer_disarm os_timer_setfn Page 139 os_timer_disarm Disarm Cancel a previously armed timer void os timer disarm os timer t pTimer Stop a previously started timer which was started by a call to os timer arm The pTimer parameter is a pointer to a timer control structure Includes e osapi h See also Timers and time os_timer_arm os_timer_setfn os_timer_setfn Define a function to be called when
81. ardo Arduino Micro Arduino Esplora Arduino Mini Arduino Ethernet Arduino Fio Arduino BT LilyPad Arduino USB LilyPad Arduino O Arduino Pro or Pro Mini Arduino NG or older Arduino Robot Control Arduino Robot Motor Arduino Gemma Arduino Pro or Pro Mini ATmeg 16 MHz on COM11 ESP8266 Modules amb Generic ESP8266 Module Olimex MOD WIFI ESP8266 DEV NodeMCU ESP8266 ESP 12 Module Now we are ready to start building compiling and running sketches A simple and sample sketch I recommend for testing is void setup Seriall begin 115200 void loop Seriall println Hello millis String millis When run a loop of messages will appear on the UART1 output saying hello and the number of milliseconds since last boot As much as anything this will validate that the environment has Page 120 been setup correctly you can compile a program and that deployment to the ESP8266 is successful See also Github esp8266 Arduino Arduino IDE The Arduino IDE ESP8266 Libraries There is no question our language is going to get odd here We are using the Arduino IDE with Arduino API libraries to compile and deploy to an ESP8266 More than likely there isn t an actual Arduino device in sight here but yet the word Arduino keeps being used Take care to understand in your mind that we are piggybacking on a technology which has become as much a philosophy as physical implementation Maybe I m showing my a
82. are expected there is nothing further to say Ignore it The ESP8266 has a second UART associated with it that is output only One of the primary purposes of this second UART is to output diagnostics and debugging information This can be extremely useful during development and as such I recommend attaching two USB UART converters to the device The second UART is multiplexed with pin GPIO2 TX GPIO2 ESP8266 See also USB to UART converters AT Command Programming Flashing the ESP8266 esptool py Page 26 WiFi Theory When working with a WiFi oriented device it is important that we have at least some understanding of the concepts related to WiFi At a high level WiFi is the ability to participate in TCP IP connections over a wireless communication link WiFi is specifically the set of protocols described in the IEEE 802 11 Wireless LAN architecture Within this story a device called a Wireless Access Point access point or AP acts as the hub of all communications Typically it is connected to or acts as as TCP IP router to the rest of the TCP IP network For example in your home you are likely to have a WiFi access point connected to your modem cable or DSL WiFi connections are then formed to the access point through devices called stations and TCP IP traffic flows through the access point to the Internet wa wirele mm rae The devices that connect to the access points are called stations Page 27
83. ash_erase_sector Erase a flash sector SpiFlashOpResult spi flasg erase sector uint16 sec Includes e spi flash h See also spi_flash_write Write data to flash SpiFlashOpResult spi flash write uint32 des addr uint32 src_addr unit32 size Includes e spi flash h See also spi_flash_read Read data from flash SpiFlashOpResult spi flash read uint32 src addr uint32 des_addr uint32 size Includes Page 153 e spi flash h See also spi_flash_set_read_func void spi flash set read func user spi flash read read Includes e spi flash h See also system_param_save_with_protect Memory saving bool system_param_save_ with protect unitl6 start sec void param uint16 len Includes e spi flash h See also system_param_load Read data saved with flash protection bool system param load uint16 start sec uint16 offset void param unit16 len Includes e spi flash h See also Wifi wifi_get_opmode Get the operating mode of the WiFi uint8 wifi get_opmode Return the current operating mode of the device There are three values defined STATION MODE Station mode Page 154 SOFTAP MODE Soft Access Point AP mode STATIONAP MODE Station Soft Access Point AP mode Includes user interface h See also Defining the operating mode wifi_get_opmode_default wifi_set_opmode wifi_set_opmode_current wifi_get_opmode_default Get the default op
84. at networking code doesn t Since we only have one thread of control we can t be in two places at once The recommended duration to spend in user code at a single sitting is less than 10msecs See also System init done cb WiFi at startup The ESP8266 stores WiFi startup information in flash memory This allows is to perform its functions at startup without having to do any special work In my opinion this is more trouble than it is worth If I am going to write an ESP8266 application I want to control when how and to what it will connect or be an access point Thankfully there is a function called wifi station set auto connect and its partner called wifi station get auto connect These allow us to override the auto connection functions when we are a station See also Page 65 wifi_station_get_auto_connect wifi_station_set_auto_connect Working with WiFi The ESP8266 can either be a station in the network an access point for other devices or both This is a fundamental consideration and we will want to choose how the device behaves early on in our design Once we have chosen what we want we set a global mode property which indicates which of the operational modes our device will perform station access point or station AND access point See also wifi set opmode wifi set opmode current Scanning for access points If the ESP8266 is performing the role of a station we will need to connect to an access
85. blessing and curse You can be pretty sure that if it can be done Curl can do it however be prepared to wade through a lot of documentation See also Curl Page 64 Architecture To start thinking about writing applications for the ESP8266 we need to understand the high level architecture of the device Custom programs Custom programs are applications that you can write and are the core focus of this book These programs can be written in C or C and then compiled into the binary files The programs are expected to have well known functions defined within that serve as architected entry points and callbacks Programmers write a C language file with a suggested name of user main c Contained within is a function with the signature void user init void This provides the initial entry into application code It is called once during startup While executing within this function realize that not all of the environment is yet operational If you need a fully functioning environment register a callback function that will be invoked when the environment is 100 ready This callback function can be registered with a call to System init done cb RF initialization must also be provided via void user rf pre init void When running in user code we need to be sensitive that the primary purpose of the device is network communications Since these are handled in the software when user code gets control that simply means th
86. both cases only the last one is remembered and will be executed when a task of that priority is posted See also Page 92 System os task 5 system_os_post Timers and time Within our code we may wish to delay for a period of time We can use the os delay us function to suspend processing for a given period measured in microseconds There are 1000 microseconds in a millisecond and a 1000 milliseconds in a second We can configure a timer to be called on a periodic basis A data structure called os timer t holds the state of the timer We can define the user function to be called when the timer fires using the os timer setfn function Note that we can only set the callback function when the timer is disarmed When ready we can arm the timer so that it starts ticking and fires when ready We do this using the os timer arm function The repeat flag indicates whether the timer should restart after it has fired We can suspend or cancel the firing of the timer using os timer disarm Here is an example os timer t myTimer void timerCallback void pArg os printf Tick End of timerCallback void user init void uart init BIT RATE 115200 BIT RATE 115200 os timer setfn amp myTimer timerCallback NULL os timer arm amp myTimer 1000 1 End of user init Another aspect of working with time is time calculations and measurement The function system get time returns a 32 bit unsigne
87. bought separately and you need to Page 39 validate that when you order and assume you are getting both that you are not just buying the mounting boards without the ESP8266 You will be disappointed The ESP 12 is then soldered onto the mounting board so you will need a soldering iron and some fine grained hand control The soldering is not the easiest in the world as the pins are extremely close together For this reason and for others I d suggest buying multiple ESP 12s and mounting boards instead of just one It is also not difficult to fry your ESP 12 if you get some wiring wrong Once assembled it should look as follows Mine never look this clean when build as my solder resin seems to discolor the original attractive white base of the mounting board However looks aren t important Assuming you now have a mounted ESP 12 with pins your next question will be now what This is where you will want a few breadboards and connector wire You could use dupont connectors with female sockets attached to the ESP 12 and male pins on the other to attach to your breadboard but you will find that wires inevitably come loose at the worse possible times You can mount the ESP 12 to a breadboard but I tend to find that there is not enough space for connector wires underneath it Once secured I recommend two USB UART connectors Why two One dedicated for flashing the device and one for debugging insert diagrams here gt For power
88. c1 0x40243182 epc2 0x00000000 epc3 0x00000000 excvaddr 0x00000050 depc 0x00000000 The codes are as follows e epcl Exception program counter Page 62 e excvaddr Virtual address that caused the most recent fetch load or store exception For example if a write to memory occurs and that memory is not RAM an exception will be thrown and the value here will be the address that was attempted to be written The primary exception codes are Code Cause name 0 IllegalInstructionCause 1 SyscallCause 2 InstructionFetchErrorCause 3 LoadStoreErrorCause 4 LevellInterruptCause 5 AllocaCause 6 IntegerDivideByZeroCause 7 Reserved 8 PrivilegedCause 9 LoadStoreAlignmentCause 10 Reserved 11 Reserved 12 InstrPIFDataErrorCause 13 LoadStorePIFDataErrorCause 14 InstrPIFAddrErrorCause 15 LoadStorePIFAddrErrorCause 16 InstTLBMissCause 17 InstTLBMultiHitCause 18 InstFetchPrivilegeCause 19 Reserved 20 InstFetchProhibitedCause 21 Reserved 22 Reserved 23 Reserved 24 LoadStoreTLBMissCause 25 LoadStoreTLBMultiHitCause 26 LoadStorePrivilegeCause 27 Reserved 28 LoadProhibitedCause 29 StoreProhibitedCause 30 Reserved 31 Reserved Page 63 32 39 CoprocessornDisabled 40 63 Reserved If we know the location of the exception we can analyze the executable app out to figure out what piece
89. cal port 25867 connl type ESPCONN TCP connl state ESPCONN NONE connl proto tcp amp tcpl We can now start our server listening for incoming TCP connections using espconn accept This takes the struct espconn as input which is used to indicate on what port we should listen among other things Here is an example espconn accept amp connl After calling this the ESP8266 will now be passively listening for incoming TCP connections on the port specified in the 16ca1 port field It is important to note that your API does not block waiting for an incoming request Somewhere in the heart of the ESP8266 it now know to accept connections on that port The next question is a simple one what happens when a connection eventually arrives The answer to that is part of the core architecture of the device and revolves around the notion of callbacks In your own application code it is your responsibility to register a callback function that will be invoked when the connection arrives This is where the espconn regist connectb function comes into play This function registers a user supplied callback function that will be called when a connection arrives void connectCB void arg struct espconn pNewEspConn struct espconn arg espconn regist connectcb amp connl connectCB espconn accept amp connl Page 76 Seen as a sequence flow diagram we can see the relationships between some of the compon
90. cccccnnnnnnnnccnnonoooonnnonnnnnnnnnonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnncnnnnnn 54 MAS ai anta tidad 54 El APEE TE E E Detactete ct i om ee pte Adare thet da didt feste fus dut Pedes acest eats 54 cip HERE 54 pes c p 55 ojo rojo E 55 eese EE 55 GEN APP PY ET 57 DebuggiN g e ita dla 58 Eoggind to VAR TL a a M e e tok RI ts 58 A AA 58 Dumping IP AdOreSSeS Tc 9 59 Page 2 Excepliori Tiaridlinig aee oa 60 Debugging and testing TCP and UDP connections sssee 61 Android Socket ns rn 61 Android UDP Sender Recelver eit et ee teet exuit ERR tr i rias 61 Windows Hercules neo coined A ane a AeA 62 A ea kats ae oea ei eana aa AEREE EIE TE EAEE PNE TE iE OANE AS 62 PACING COU cient 62 CUSTOM PLOMO sce idest cope Fee p m ROO ENG d CR Ede RO IER Salen ERSUN EEES Aaa Eria 62 Working verbi WIE paese oisi takes cia comte adatta do aiit eee i diei recu du Le 63 Scanning for access POMS a sues beide Made de Pec easy esate he cede nip aes 63 Defining the operating Mode esc erede Eo i c E Reese iia 64 Handling VVIEI BVelllSs octo A bae u tede aUud 64 ce EC TER NEN EE 66 Connecting to an access POM ies oce eret Eae eH de oes ap esa qea bees noes AE ee 66 Control and data flows when connecting as a Stati0N oonnnnccccccccnncccccnncnonnnannnnnnnnnnns 67 Being an access PO QD 68 The DHCP SOTVOl ect Roo ai
91. cccncooononnnnnnnnnccnnnnnnnnonnnnnonrnnnnnnnnnnnnnnnnss 159 system upgrade Staind A Mere da ea 159 system upgrade rebOOt ccccccccccccecccccecaeaaeeeeseeeeeeeeeeeeeeeeeeeeeeeeaaaaseaceeeeessaeeeeseaageees 159 Sniffer APIs et ee vinx tere ann a S VERE MR TER SEE VAREYR 159 wifi promiscuous enable sssssssssssssssssssssssssseeeeeeeee nennen hnnhnn nnne n enne n nennen 159 wifi promiscuous set MAC iooocccccnnccnncccncnononnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnaneninns 159 wifi promiscuous rx Cb sssssssssesssssssseneeee eene nnnnmrt rrr n nnne nnne nnns nsns nennen 159 Witiget channel c err etie b erba roe pede eae id bu qu Ra 159 Wifi set charnnel iuc pea de dba 159 a C 159 emiarteonfig SISIT o o ad ween i rudi a deal M nestle Ss 159 Cinese RD 160 SNTP AP Iiic atate ee a lesan XX AUR aia ERR ERR E EXER FW OE MR Een ra 160 sntp Setserver eiecti ds babe Pi ed teenaged 160 CUN TM rem 160 sntp setservernaime es 160 SIP GEISCrVErMAME 5 c ccesecceeeteceesneeeetttensdeneceateseevecednaaaesersceencucesteeeaeaedeteaeaeeesesesenereas 161 eMe 161 SMP oo P 161 sntp_get_current_timestaMp cccccnncnnccccccccccnoocnnnnnnnnccnnnnnnnnnnnnnnnnnnnnannnnnnnncnnnnnnnnrnnnnnnnnss 162 sntp get real tme ys uero sabes nde eager eee e d rere eee dn ree dele ek a 162 shtp set tImbezories 2 s A v r
92. ccncccconcccnccccnonncnnnnccnnnnnnnnonononnnnnnnnononnnnnnnnnnnnnnnnnnnonanennnnnnncnns 172 UDPAPIS es f a o c o E rue A a O A 172 ESpPCONT Cell nia ie ted adie 172 SSPCOMML AGM 2 OM A rears vibeh hdl hat rte Wa alittle Deatin loans od asinus 173 ESPEONN IMP le Vii A ie 173 PI AP Sica A AE EA A IS 173 DIO di A A os 173 Page 8 DIS NECV s s 22 s dao ede ede acon DER ERN Ree e Ee eene esp tc Rb A eee een 173 ping regist sent oon e ct e e RE PE Ede E FO coe E RE EE need bot e LT REY RT ERA 173 MmDNS APlS iii a a aaa aida 173 ESPEONN MANS ii A A ae 173 ESPCONN mans COS iii a en ee AAA 174 eSpconn_Mdns_server_ eQiSter ceeecceeeeeeeeeeeeeeeeeaeaaaeeeeeeeeeeeeeeeeeeeeeeeeeeseaaaanneees 174 espconn_mdns_server_UNreQiStel cecceeeeeeeeeeeeeeeeeeaaaeaeeceeeeeeeeeeeeeseeeeeeesaaneeeees 174 espconn_Mmdns_get_Servername cesececeeeeeeeeeeeeeeeeeeeaeaaaaaeeeeeseeeeeeeeeeeeeeeeesaaneeees 174 ESPCONN_MdnNS_Set_SErVernamMe cccceecece cece ce ceeeeeeeeeeeseeeeeeeeeeeeeeeeeeeeaeaaaaeaeaeeeesaeeeess 174 espconn_mdns_set_hostname cccceeeeeeeeeeeeeeeeeeeeeeeeeceaaaaaaeeaaeeeeeeeeeeesaeneeesanteees 174 espconn mdns get hostname sssssssssssssssssssssseseeeeenenee nennen nenne rennen 174 espconn_mdns_disable ooooooonnnncccnnnnnnnncccccnnncnononnnnnncnnnccnnnnnnnnnnnnnnnnnonnrnnnncnnnnnnnrnnennnness 174 espconn mdns emable ooooooocccccncnccccccccnccnc
93. cnnnnnnnnnnnccnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnrrrnnnnnnnnnnnnennnnaeos 174 ile EE 174 PIN PULLCUP DIS E 176 PIN PULLUB EN ici 177 PIN FUNC SELECT i e terr is 177 SPIO N D 2 EA N sees HL HDD PEE 177 GPIO OUTPUT SET A eterne da dando 177 GPIO DIS QUIPU Tia sates hr e Eee Re ne RAS pta rire R EHE Rx e ear dasguasadedcaadvanensens 178 GPIO INPUT GET ista dedicas 178 gpio output SO kasa a da ra rE 178 OPIO INPUT Elli Aid A E EA ted 179 gpio_intr_handler_register cccccccccecccccecceeeaeeeeeeseceeeeeeeeeeeeeeeeeeeeeeeaaaaeeeesaageeessanseees 179 gpio pin intr state Sete ien a e nn enne nennen a 179 OPIO intr PON citaciones a Ex HER RUN Edere RI RV Re ES geek Revver dep vs 179 eje oie PME 180 gpio_pin_wakeup_enable ooooooooooonncccccnncccnnnccccccnnnnnnnnnnnnnnnncnnnnnnnnnnnnnnnnnnnnnnnrnnnnnnnrnncnnanirs 180 gpio_pin_wakeup_disSable oooooooooonnnnnnccccoconnnnnnnononnnonononnnnncnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnanannnnss 180 UARTCAPIS iia ato ER eerte eo EUR IEEE EU roga C RE QR SENE ERERRR 180 Ur la Malle 181 artO e Duffer O 181 arto rx intr handler er A aati eats 181 I2G Master durum 182 i2c master Opina a AA Ri 182 i2C Master Miu eds 182 I2c master dd a a ii 182 AOI IMEEM 182 i2c master send ack ssssssssssssssssssssseeeeneneeerer hh hhnn nnn en nennen sensns nnns nnenas 182 i2c imaster send nackte ptt e E aA P ERU chosen NER RH 182 I2c master checkAGCK eiecit des ries va ei rue c
94. cps_offer_option Page 169 wifi_softap_set_dhcps_lease Define the IP address range that will be leased by this DHCP server bool wifi softap set dhcps lease struct dhcps lease pLease The pLease parameter is a pointer toa struct dhcps lease which contains an IP address range of IP addresses that will be leased by this DHCP server The difference between the upper and lower bound of the IP addresses must be 100 or less This function will not take effect until the DHCP server is stopped and restarted assuming it 1s already running Includes user interface h See also The DHCP server wifi_softap_dhcps_start wifi_softap_dhcps_stop wifi_softap_dhcps_status wifi_softap_dhcps_offer_option struct dhcps_lease wifi_softap_dhcps_status Return the status of the DHCP server service enum dhcp status wifi softap dhcps status Retrieve the status of the DHCP server service The returned value will be one of e DHCP STOPPED DHCP STARTED Includes user interface h See also The DHCP server wifi softap dhcps start wifi softap dhcps stop wifi softap set dhcps lease wifi softap dhcps offer option wifi softap dhcps offer option Set DHCP server options bool wifi softap set dhcps offer option uint8 level void optarg Page 170 Currently the level parameter can only be OFFER_ROUTER with optarg being a bit mask with values e 0b0 Disable router information 0b1 Enable ro
95. d unit32 value which is the microseconds since the device booted This value will roll over after 71 minutes We can also explicitly block execution for a period of time using os delay us See also system_get_time os_timer_arm os timer disarm os timer setfn Page 93 Working with memory When working in C you have to think in terms of computer memory With great power comes great responsibility The amount of available RAM is likely to be less than 45KBytes We can allocate memory using os malloc Oros zalloc The first function allocates and returns memory and the second does exactly the same but zeros the memory before returning When your logic no longer needs the memory it can return it back to the heap with os_free To determine how much heap size is available we can call system get free heap size Once we have the memory pointer we can start to manipulate it through a series of memory commands The os memset command will set a block of memory to a specific value The os memcpy will copy a block of memory to a different block The os bzero function will set the values of a block of memory to zero Memory on the ESP8266 is made up of a number of components We have data rodata e bss heap The values of these can be found through the system print meminfo function When the ESP8266 needs to read an instruction from memory in order to execute it that instruction can come from one
96. d espFsClose EspFsFile fileHandle Close the file that was previously opened by a call to espFsOpen No further reads should be performed espFsFlags int espFsFlags EspFsFile fileHandle espFsRead int espFsRead EspFsFile fileHandle char buffer int length Read up to length bytes from the file and store them at the memory location pointed to by buffer The actual number of bytes read is returned by the function call mkespfimage This is not a function but a command which builds the binary data of the files to be placed in flash memory mkespfimage c compressor 1 compression level e C o 0 None o Heatshrink Page 211 ESPHTTPD breakdown The ESPHTTPD library provides an implementation of an HTTP server running on an ESP8266 In order to use this we may wish to understand it better httpdlnit void httpdInit HttpdBuiltInUrl fixedUrls int port Initialize the HTTP server running in the ESP The port parameter is the port number that the ESP will listen upon for incoming browser requests The default port number used by browsers is 80 The HttpdBuiltInUrl is a typedef that provides mapping to URLs available on the HTTP server The fields contained within are char url The url to match e cgiSendCallback cgiCb The callback function to call when matched const void cgiArg Parameters to pass into the callback function It is vital that the last element in the array have NUL
97. d to restart accept yes We are not ready to use it yet we must add serial port support into Eclipse Go back to Help gt Install new software and add a new repository Available Software Select a site or enter the location of a site Work with type Find more software by working with the Available Software Sites preferences type filter text Page 107 The repository URL is http archive eclipse org tm updates rxtx Name http archive eclipse org tm updates rxtx Location http archive eclipse org tm u pdates rxtx Now we can select the Serial port runtime support library Page 108 Available Software Check the items that you wish to install Work with http archive eclipse org tm updates rxtx http archive eclipse org v Find more software by working with the Available Software Sites preferences type filter text Name Version b E 00 RXTX 2 1 7r3 4 ll 000 RXTX 2 1 7r4 2 RXTX End User Runtime 2 1 7 4 v20071016 7B57e7UAXMAAqGAGf 2 RXTX Extender SDK 2 1 7 4 v20071016 417C7DP1Bh eEaQJBrHBHg Deselect All Litem selected Details Y Show only the latest versions of available software V Hide items that are already installed Y Group items by category What is already installed Show only software applicable to target environment Contact all update sites during install to find required software
98. data and based on its value change the output value of the GPIO The physical GPIO is wired to an LED and a resistor If a character of 1 is transmitted the output of GPIO15 goes high and the LED lights If the character value is 0 the output of GPIO15 goes low and the LED is extinguished Sample Ultrasonic distance measurement The HC SR 04 is an ultrasonic distance measurement sensor Send a minimum of a 10us pulse to Trig low to high to low Later Echo will go low high low The time that Echo is high is the time it takes the sonic pulse to reach a back end and bounce back Speed of sound is 340 29 m s 340 29 39 3701 inches sec Call this V oun Page 132 distance d a e Tx Rx Target Object If Tecno 1s the time for echo response then d Tecno Vesouna 2 Also the equation for expected Tecno lengths is given by Tecto 2d V sound For example Distance Time lem 2 0 01 340 0 058 msecs 59 usecs 10cm 2 0 1 340 0 59 msecs 590 usecs im 2 1 340 5 9 msecs 5900 usecs 5 9 msecs Because the Echo response is a 5V signal it is vital to reduce this to 3 3V for input into into the ESP8266 A voltage divider will work The pins on the device are vcc The input voltage is SV e Trig Pulse low to high to trigger a transmission minimum of 10usecs e Echo Pulses low to high to low when an echo is received Warning t
99. debugging available to you Page 38 See also Saleae logic analyzers Sundry components You will want the usual set of suspects for sundry components including LEDs resistors capacitors and more Physical construction When you have breadboarded your circuit and written your application there may come a time where you wish to make your solution permanent At that point you will need a soldering iron solder and some strip board I also recommend some female header sockets so that you don t have to solder your ESP8266s directly into the circuits Not only does this allow you to reuse the devices should you desire but in the unfortunate event that you fry one it will be easier to replace Recommended setup for programming ESP8266 Obviously in order to program an ESP8266 you will actually need to obtain an ESP8266 but it isn t that easy The actual ESP8266 itself is a tiny integrated circuit and you are unlikely to be able to use it directly Instead you will buy one of the many styles of breakout boards that already exist The common ones are the ESP 1 which exposes 2 GPIO pins and the ESP 12 which exposes 9 I recommend the ESP 12 as it is only marginally more expensive for the extra pins exposed You will also need a mounting board as the ESP 12 by itself doesn t have connector pins You can commonly buy both the ESP 12 and the mounting board together at the same time However check carefully the mounting boards can be
100. ding the buttons Page 51 U2 ESP8266 ESP 12 FTDI Basic ESP626b Programmer Wifi Module GPIOO Reset s2 Notice that there is a voltage divider from the output of the USB to UART converter TX pin The thinking behind this is to handle the case where the output TX voltage is greater than the desired 3 3V wanted on the RX input of the ESP8266 Is this required The belief is that it is not required if you are sure that the output TX voltage will be 3 3V This appears to be the case for the CP2102 range of USB to UARTs however I am have no knowledge on other devices What I can claim is that having a voltage divider that reduces 5V to 3 3V still results in a usable output level voltage to indicate a high signal when fed with a 3 3V actual output I don t know how close I am coming to the minimum RX input voltage on the ESP8266 indicating a high When built out on a breadboard it may look as follows Page 52 This however suffers from the disadvantage that it requires us to manually press some buttons to load a new application This is not a horrible situation but maybe we have alternatives When we are flashing our ESP8266s we commonly connect them to USB gt UART converters These devices are able to supply UART used to program the ESP8266 We are familiar with the pins labeled RX and TX but what about the pins labeled RTS and DTR what might those do for us RTS which is Ready to Send is an output from the UART
101. e Imagine a directory structure with a al c a2 c b bl c b2 c goal is to compile these to build a al o a2 0 b bl o b2 0 We know how to compile x c x o MODULES a b BUILD_BASE build BUILD DIRS addprefix BUILD_BASE MODULES SRC foreach dir MODULES wildcard dir c Replace all x c with x o OBJS patsubst c 0 SRC all echo OBJS echo wildcard OBJS c echo foreach dir OBJS wildcard dir c echo SRC SRC test checkdirs OBJS Page 216 echo Compiled SRC C 0 echo Compiling basename lt CC c lt o build addsuffix o basename lt checkdirs BUILD DIRS BUILD_ DIRS mkdir p clean rm f BUILD_ DIRS See also GNU make Forums There are a couple of excellent places to ask questions answer other folks questions and read about questions and answers of the past gt Espressif ESP8266 BBS A moderated forum run by Espressif The primary source for SDK downloads and the source of much of the core materials ESP8266 Community Forum A set of fora dedicated to the ESP8266 run for and by the ESP8266 user community Reference documents Espressif distributes PDF and Excel spreadsheets containing core information about the ESP8266 These can be downloaded freely from the web OA ESP8266 Datasheet v4 3 OB ESP8266 Hardware User Guide v1 1 OC ESP8266 WROOM WiFi Module Data
102. e separate 32KB on chip Operating Voltage 3 3V 5V Max current per I O 12mA 40mA UART hardware 1 1 Networking Built in Separate Documentation Poor Excellent Maturity Early Mature Note Because the Arduino has no native networking no further comparisons of network capability were included above Do remember that at this time when one is using an ESP8266 the chances are high it is because you need network access Page 99 Partner TCP IP APIs If the ESP8266 can act as one end of a TCP IP connection something else has to act as the other of course there is nothing to prevent two ESP8266s from communicating between themselves Here we look into some technologies that allow partners to interact with the ESP8266 over the TCP IP protocol For the TCP IP protocol the programming API originally developed for the Unix platform and written in C was called sockets The notion of a socket is that it logically represents an endpoint of a network connection A sender of data sends data through the socket and the receiver of data receives data through the socket The implementation of the socket itself is provided by the libraries but the logical notion of the socket remains You will find yourself working with an instance of a socket and you should think of it as an opaque data type that refers to a communication link Sockets remains the primary API and is present in the majority of languages Here we discuss some of the varian
103. e Integrated Development Environment IDE for the Arduino has always been free of charge for download If a professional programmer were to sit down with it they would be shocked at its apparent limited capabilities However the subset of function it provides compared to a full featured IDE happen to cover 90 of what one wants to achieve Combine that with the intuitive interface and the Arduino IDE is a force to be reckoned with Here is what a simple program looks like in the Arduino IDE r ES ESP Serial1 Arduino 1 6 5 p Lop _ File Edit Sketch Tools Help ESP_Serial1 vo J l void setup o 2 put your setup code here to run once Seriall begin 115200 1 5 void loop put your main code here to run repeatedly Seriall println Hello millis String millis 9 odule SO MHz 115 In Arduino parlance an application is termed a sketch Personally I m not a fan of that phrase but I m sure research was done to learn that this is the least intimidating name for a C language program that would scare the least number of people Page 113 The IDE has a button called Verify which when clicked compiles the program Of course this will also have the side effect that it will verify that the program compiles cleanly but compilation is what it does A second button is called Upload and when clicked what it does is deploy the application to the Arduino In addition to p
104. e access points and not stations I believe a more appropriate name would have been wifi access point scan Includes user interface h See also Scanning for access points struct bss_info STATUS wifi_station_ap_number_set Number of stations that will be cached bool wifi station ap number set uint8 ap number Includes user interface h wifi station get ap info Get the information of access points cached uint8 wifi station get ap info struct station config configs Page 163 Includes user interface h wifi station ap change Change the connection to another access point bool wifi station ap change uint newApId Includes user interface h wifi station current ap id Get the current access point id uint8 wifi station get current ap id Includes user interface h wifi station get auto connect Determine whether or not the ESP will auto connect to the last access point on boot unit8 wifi station get auto connect Determine whether or not the device will attempt to auto connect to the last access point on restart A value if 0 means it will not while non 0 means it will Includes user interface h See also wifi_station_connect wifi_station_disconnect wifi_station_set_auto_connect wifi_station_set_auto_connect Set whether or not the ESP will auto connect to the last access point on boot bool wifi station set auto connect uint8 setValue Set whether or not
105. e also GPIOs gpio_input_get Get the values of the GPIOs unit32 gpio input get Retrieve the values from the GPIOs and return a bitmask of their values Includes e gpio h See also GPIOs gpio_intr_handler_register Register a callback function that will be invoked when a GPIO interrupt occurs void gpio intr handler register gpio intr handler fn t callbackFunction void arg The signature of the handler function must be void functionName uint32 interruptMask void arg Includes e gpio h gpio pin intr state set void gpio pin intr state set uint32 pinId GPIO INT TYPE intr state The pinta is the GPIO pin id value returned from GPIO ID PIN num Page 193 The intr state parameter defines what triggers the interrupt Includes e gpio h See also GPIOs GPIO INT TYPE gpio intr pending Obtain the set of pending interrupts uint32 gpio intr pending Includes e gpio h gpio intr ack Flag a set of interrupts as having been handled This should be called from an interrupt handler function void gpio intr ack uint32 ack mask Includes e gpio h gpio pin wakeup enable Define that the device can wakeup from light sleep mode when an IO interrupt occurs void gpio pin wakeup enable uint32 pin GPIO INT TYPE intr state The pin parameter defines the pin number used to wake the device The intr state defines which type of transition will wake the device The choice
106. e is an API for that To get your current IP address there is an API for that and to get the time since the device was started there is an API for that In fact there are a LOT of APIs available for us to use The good news is that no one is expecting us to memorize all the details of their use Rather it is sufficient to broadly know that they exist and have somewhere to go when you want to look up the details of how to use them To sensibly manage the number and variety of these exposed APIs we can collect sets of them together in meaningful groups of related functions This gives us yet another and better way to manage our knowledge and learning of them The primary source of knowledge on programming the ESP8266 is the ESP8266 SDK API Guide Direct links to all the relevant documents can be found at Reference documents See also Espressif Systems Manufacturers of the ESP8266 Espressif Bulletin Board System Place for SDKs docs and forums Boot mode When the ESP8266 boots the values of the pins known as MTDO GPIOO and GPIO2 are examined The combination of the high or low values of these pins provide a 3 bit number with a total of 8 possible values from 000 to 111 Each value has a possible meaning interpreted by the device when it boots Page 43 Value 15 0 2 Value Meaning 000 0 Remapping details unknown 1 Boot from the data received from UARTO Also includes flashing the flash memory for subse
107. e t e eei ted 162 Page 7 shitp A O A 162 Generic TCP UDP APIS 3000 dep eee A eer 163 espconn delete ter tere pipe dd dea ER ee b P UR EXER nidos 163 espconri dns setserVer si A ec tr e Pr dor PR Odd ia 163 espconrn getliostbynaiTie oss nete te etre A ele Se 163 OSPCOMNO oro acm 164 esSpconn_regist_SenNtCb oooooooooooooooooooancccnononnnnnnnnnnnnnnnnnonnnnnnnncrnnnnnnnnnnnnnnnnnnnnnnnnrnnnnnnness 164 espconn MICA rene n nenne nenne enses nnn EEE n rr nnne nnns 164 espconriSeritz itte m ttr ibt tra tates EM iio 165 WP AGG AO e cose essay LECCE 165 IP 4 ADDR oe orn de eee ea ed ee 165 l2 d cc ieee sadeats foiled E N E E dde 166 TCP APIS a A A ds 166 ESPEONN ACCC m m 166 espconn_get_connection_iMfo oooooonnnncccnnnnnnnncconcnnncoonnnnnnnnnccnnnnnnnnnnnnnnnrnnnnnnncnncnnnanoss 167 espcorin _COMNECE we sais ecce da paaa aa reaa KEEN E AKEE XXe E a EEA aa Taa leu Crap E NANE 167 ESPCONN GISCONME Cdi e utr ade ete NTA 167 ESPCONN_FeGiSt_CONMECLCD cceccecceceeecceececeaeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaeeeeeesaeeeeesaaneeees 168 ESPCONN_reGiSt_CISCONCD ccccsceeeeeeeeeeeeeeeeeeeeeeeeeeeeeaeaaaaaaeeaacedeeeeesseeeeessaeeeeesaaneess 168 ESPCONN_FeGiSt_FECONCD ececcccece cece cece eee eeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaeaaaeaseeeeeeeeeeeeeeeeeesaaeees 168 espconn_regist_write_fiNiSh cccccceeeeeeeeeeeeeeeeeaeeaeeeeeeceeeeeeeeeeeeeeeeeeeeeeaaaaaaeeseeeeeeees 169 espconn Set o
108. e uint8 local ip 4 e intlocal port uint8 remote ip 4 intremote port e Other fields there are other fields in the structure but they are not meant to be read or written to by user applications Ignore them Using their values is undefined and may have unexpected effects See also struct espconn esp_udp This data structure is used in the proto property of the struct espconn control block intremote port e intlocal port uint8 local ip 4 e uint8 remote ip 4 See also UDP struct ip addr A representation of an IP address It contains the following field uint32 addr The actual 4 byte IP address Includes e ip addr h Page 205 See also ipaddr_addr IP4_ADDR ipaddr_t ipaddr_t A typedef for struct ipadar See also struct ip_addr struct ping_option The fields contained within the structure are uint32 count The number of times to transmit a ping e uint32 ip The IP address that is the target of the ping uint32 coarse time ping recv function recv function ping sent function sent function void reverse Includes ping h See also Ping request ping start ping regist recv ping regist sent struct ping resp The fields contained within the structure are e uint32 total count e uint32 resp time e uint32 seqno e uint32 timeout count uint32 bytes e uint32 total bytes Page 206 e uint32 total time e sint8 ping err An
109. eap size System print meminfo Pulse Width Modulation PWM The idea behind pulse width modulation is that we can think of regular pulses of output signals encoding information as a function of how long the signal is kept high Let us imagine that we have a period of 1HZ one thing per second Now let us assume that we raise the output voltage to a level of 1 for 2 of a second at the start of the period This would give us a square wave which starts high lasts for 500 milliseconds and then drops low for the next 500 milliseconds This repeats on into the future The duration that the pulse is high relative to the period allows us to encode an analog value onto digital signals If the pulse is 10096 high for the period then the encoded value would be 1 0 If the pulse is 100 low for the period then the encoded value would be 0 0 If the pulse is on for n milliseconds where n is less than 1000 then the encoded value would be n 1000 Typically the length of a period is not a second but much much smaller allowing us to output many differing values very quickly The ratio of the on signal to the period is called the duty cycle This encoding technique is called Pulse Width Modulation or PWM There are a variety of purposes for PWM Some are output data encoders One commonly seen purpose is to control the brightness of an LED If we apply maximum voltage to an LED it is maximally bright If we apply 2 the voltage it is about Y the brightn
110. eceiving them upon We achieve that through the poorly named espconn create function This function causes the ESP8266 to start listening for incoming datagrams on the local port defined in the struct espconn After calling this function you should then call espconn regist recvcb toregister a callback function that will be invoked when a datagram arrives Page 81 Here is a high level example of setting up a UDP listener once an IP address has been allocated jOCAL struct espconn connl OCAL esp udp udpl jOCAL void setupUDP sint8 err connl type ESPCONN UDP connl state ESPCONN NONE udpl local port 25867 connl proto udp amp udpl M err espconn create amp connl err espconn regist recvcb amp connl recvCB End of setupUDP Should we wish to stop the ESP8266 from listening for datagrams we can call the function called espconn delete Now is a good time to come back to IP addresses and port numbers We should start to be aware that on a PC only one application can be listening upon any given port For example if my application is listening on port 25867 then no other application can also be listening on that same port not your application nor another copy instance of mine When an incoming connection or datagram arrives at a machine it has arrived because the IP address of the sent data matches the IP address of the device at which it arrived We then route within
111. ected Mac ted aid ED ta disconnected mac ta disconnected aid This is a C Union containing data that is available as a function of the event type Got taMode Connected t connected taMode Disconnected t disconnected taMode AuthMode Change t auth change IP t got ip Oo Event S Event S Oo Event S Oo Event StaMode O Event SoftAPM O Event SoftAPM See also wifi_set_event_handle_cb STATUS ode StaConnected t sta connected ode StaDisconnected This is an enum defined as follows t sta disconnected Page 209 Enum Name Value OK 0 FAIL 1 PENDING 2 BUSY 3 CANCEL 4 See also wifi_station_scan Page 210 Reference materials There is a wealth of information available on the ESP8266 from a variety of sources ESPFS breakdown The ESPFS is a library which stores files within the flash of the ESP8266 and allows an application to read them It is part of the ESPHTTPD project EspFslnit EspFsInitResult espFsInit char flashAddress Initialize the environment pointing to where the file data can be found The return will be one of ESPFS INIT RESULT OK ESPFS INIT RESULT NO IMAGE ESPFS INIT RESULT BAD ALIGN espFsOpen EspFsFile espFsOpen char fileName Open the file specified by the file name and return a structure that is the handle to the file or NULL if the file can not be found espFsClose voi
112. ed 11 of which are GPIO Page 86 For GPIO here are the exposed mappings Pin ESP 1 ESP 12 GPIO 0 GPIO 1 GPIO 2 GPIO 3 GPIO 4 GPIO 5 GPIO 6 GPIO 7 GPIO 8 GPIO 9 GPIO 10 GPIO 11 GPIO 12 GPIO 13 GPIO 14 GPIO 15 GPIO 16 Totals 11 It is also good to remind ourselves of the pin outs of the device REST anc cu ro erio16 cPio14 erio12 erio13 vcc To RxD Q GPIOS GPIO4 cPio0 GPIO2 GPIO15 GND As you can see there is no obvious pattern to the layout of the pins and as such you must take great care when wiring up a circuit It is easy to make a mistake Page 87 Another vital consideration about working with GPIOs is voltage The ESP8266 is a 3 3V device You need to be extremely cautious of you are working with 5V or above partner MCUs or sensors Unfortunately devices like the Arduino are typically 5V as are USB UART converters and many sensors This means you are as likely as not to be working in a mixed voltage environment Under no circumstances think you can power the ESP8266 with a direct voltage of more than 3 3V Obviously you can convert higher voltages down to 3 3V but never try and connect a greater voltage directly Another subtler consideration is when using GPIOs for signal input and supply greater than 3 3V as a high signal value I
113. em Here we retrieve the SSID of the current station or the SSID of the scanned network id WiFi status Retrieve the current WIFi status wl status t status The status returned will be one of Page 126 WL CONNECTED e WL NO SSID AVAIL WL CONNECT FAILED WL IDLE STATUS WL DISCONNECTED WiFi stopSmartConfig void stopSmartConfig WiFi subnetMask IPAddress subnetMask WiFi waitForConnectResult Wait until the WiFi connection has been formed or failed uint8 t waitForConnectResult If we are a station then block waiting for us to become disconnected or failed The return code is the status WiFi Client WiFiClient WiFiClient available int available WiFiClient connect Connect to the given host at the given port using TCP int connect const char host uintl6 t port int connect IPAddress ip uint16 t port Connect to the given host at the given port using TCP This function returns 0 on a failure WiFiClient connected uint8_t connected Page 127 WiFiClient flush void flush WiFiClient getNoDelay bool getNoDelay WiFiClient peek int peek WiFiClient read Read data from the partner int read int read uint8 t buf size t size Read data from the partner These functions read either a single byte or a sequence of bytes from the partner WiFiClient remotelP Retrieve the remote IP address of the connection IPAddress remoteIP Retrieve the remote IP address of
114. ents We assume that in the event callback when we have been allocated an IP address we then register that we are interested in connections and that we are willing to accept incoming new connections Then at some time in the future we receive a new connection request and the connection callback is invoked eventCB espconn regist connectcb espconn_accept connectCB O The content of the struct espconn passed into the callback will include the remote IP address of the partner that connected with us We can use that information for logging or for authorization For example if the IP address is not one we wish to allow we can disconnect at this point using espconn_disconnect Realize that this data structure represents the new connection with the partner that just invoked up and is not the same as struct espconn that was used to register that we wanted to accept new connections A new struct espconn will be passed in for each new connection formed This covers the ESP8266 receiving incoming connection requests but what if it should desire to form a connection outbound to a remote TCP application To perform an outbound connection request we can use the espconn connect call Just like the receiving an inbound connection making an outbound connection will result in an invocation to the connection callback when the connection is established Once the connection has been formed once again the two ends of the connection w
115. eprocessor Include Paths Macrc Profiling Categories Linux Tools Path Project References mi Move Down 4 Create the folders called user and include a 5 Sample gt E Includes include user 5 Create the file called user_config h in include 4 5 Sample gt A Includes 4 gt include b B user config h 5 user 6 Create the C file called user main c in user 4 5 Sample gt E Includes 4 gt include b B user config h 4 gt user gt e user main c 7 Create a Makefile Base directory for the compiler XTENSA TOOLS ROOT c Espressif xtensa 1x106 elf bin SDK_BASE c Espressif ESP8266 SDK SDK_TOOLS c Espressif utils ESPPORT COM18 ESPBAUD 115200 Page 48 ESPBAUD 230400 select which tools to use as compiler librarian and linker CG S XTENSA TOOLS ROOT xtensa 1x106 elf gcc AR XTENSA_TOOLS_ROOT xtensa 1x106 elf ar LD XTENSA TOOLS ROOT xtensa 1x106 elf gcc OBJCOPY XTENSA TOOLS ROOT xtensa 1x106 elf objcopy OBJDUMP XTENSA TOOLS ROOT xtensa 1x106 elf objdump ESPTOOL SDK_TOOLS esptool exe compiler flags using during compilation of source files TARGET myApp CFLAGS Os g 02 std gnu90 Wpointer arith Wundef Werror W1 EL fno inline functions nostdlib mlongcalls mtext section literals mno serialize volatile D ets
116. er interface h See also e Broadcast with UDP wifi_get_broadcast_if uint8 wifi get broadcast if Includes user interface h See also Page 156 e Broadcast with UDP wifi_set_event_handle_cb Define a callback function to sense WiFi events void wifi set event handler cb wifi event handler cb t callbackFunction Registers a function to be called when an event is detected by the WiFi subsystem The signature of the registered callback function is void functionName System Event t event Includes user interface h See also Handling WiFi events System_Event_t wifi_get_ip_info Retrieve the current IP info about the station bool wifi get ip info uint8 if index struct ip info info The if index parameter defines the interface to retrieve Two values are defined STATION IF 0 The station interface SOFTAP IF The Soft Access Point interface The info parameter is populated with details of the current ip address netmask and gateway Includes user interface h See also Current IP Address netmask and gateway struct ip_info wifi_set_ip_info Set the interface data for the device bool wifi set ip info uint8 if index struct ip info info The if index parameter defines the interface to retrieve Two values are defined e STATION IF 0 The station interface Page 157 SOFTAP_IF l The Soft Access Point interface The info parameter is a poin
117. erating mode uint8 wifi get opmode default Return the default operating mode of the device following startup There are three values defined e STATION MODE Station mode SOFTAP MODE Soft Access Point AP mode STATIONAP MODE Station Soft Access Point AP mode Includes user interface h See also Defining the operating mode wifi_get_opmode wifi_set_opmode wifi_set_opmode_current wifi_set_opmode Set the operating mode of the WiFi including saving to flash bool wifi set opmode uint8 opmode There are three values defined STA SOF STAT Includes IONAP MODI ION MODE Station mode AP MODE Soft Access Point AP mode E Station Soft Access Point AP mode Page 155 user interface h See also Defining the operating mode wifi_get_opmode wifi_get_opmode_default wifi_set_opmode_current wifi_set_opmode_current Set the operating mode of the WiFi but don t save to flash bool wifi set opmode current uint8 opmode There are three values defined STATION MODE Station mode SOFTAP MODE Soft Access Point AP mode STATIONAP MODE Station Soft Access Point AP mode Includes user interface h See also Defining the operating mode wifi_get_opmode wifi_get_opmode_default wifi_set_opmode wifi_set_broadcast_if bool wifi_set_broadcast_if uint8 interface Includes us
118. erver port The port supplied is the port number on the machine on which the JVM is running that will be the endpoint of remote client connection requests Once we have a ServerSocket instance we need to wait for an incoming client connection We do this using the blocking API method called accept Socket partnerSocket serverSocket accept This call blocks until a client connect arrives The returned partnerSocket is the connected socket to the partner which can used in the same fashion as we previously discussed for client connections This means that we can request the InputStream and OutputStream objects to read and write to and from the partner Since Java is a multi threaded language once we wake up from accept we can pass off the received partner socket to a new thread and repeat the accept call for other parallel connections Remember to close any partner socket connections you receive when you are done with them So far we have been talking about TCP oriented connections where once a connection is opened it stays open until closed during which time either end can send or receive independently from the other Now we look at datagrams that use the UDP protocol The core class behind this is called DatagramSocket Unlike TCP the DatagramSocket class is used both for clients and servers First let us look at a client If we wish to write a Java UDP client we will create an instance of a DatagramSocket using
119. es of these raw processors on ebay for under 2 with fully constructed boards containing them for under 3 This is 10 20 times cheaper than the Raspberry PI Of course one gets dramatically less than the Raspberry PI so comparison can become odd however if what one wants to do is tinker with electronics or make some simple devices that connect to LEDs switches or sensors then the functional features needed become closer Between them the Arduino and the Raspberry PI appear to have all the needs covered If that were the case this would be a very short book Let us add the twist that we started with wireless networking To have a device move a robot chassis or flash LED patterns or make some noises or read data from a sensor and beep when the temperature gets too high these are all great and worthy projects However we are all very much aware of the value of the Internet Our computers are Internet connected our phones are connected we watch TV Netflix over the Internet we play games over the Internet we socialize over the Internet and so on The Internet has become such a basic commodity that we would laugh if someone offered us a new computer or a phone that lacked the ability to go on line Now imagine what a microprocessor with native wireless Internet could do for us This would be a processor which could run applications as well as or better than an Arduino which would Page 13 have GPIO and hardware protocol
120. ess By applying a fast period PWM signal to the input of an LED the duty cycle becomes the brightness of the LED The way this works is that either full voltage or no voltage is applied to the LED but because the period is so short the average voltage over time follows the duty cycle and even though the LED is flickering on or off it is so fast that our eyes can t detect it and all we see is the apparent brightness change For the ESP8266 the period of the PWM can range from 1 millisecond to 10 milliseconds This is a frequency of IKHz to 100Hz The resolution of the duty cycle is down to 45 nanoseconds which is 14 bits of resolution data The device provides support for up to 8 PWM channels where each channel can be associated with its own pin and duty cycle The period is the same for all PWM channels To start using the ESP8266 PWM support a call to pwm_init is needed which sets up which pins are to be used for PWM and for which channels A call to this function also sets up an initial period and duty cycle A call to pwm start can then be made to start the PWM outputs The period of PWM as a whole and duty cycles for each channel can be changed using the pwm set period and pwm set duty functions Page 95 See also Wikipedia Pulse width modulation pwm_init pwm_start pwm_set_duty pwm_get_duty pwm set period pwm get period Analog to digital conversion Analog to digital conversion is the ability to read a volt
121. event info disconnected bssid t8 32 event info disconnected ssid t8 ssid len t8 event info disconnected reason The reason is one of the following REASON UNSPECIFIED 1 REASON AUTH EXPIRE 2 REASON AUTH LEAVE 3 REASON ASSOC EXPIRE 4 REASON ASSOC TOOMANY 5 REASON NOT AUTHED 6 REASON NOT ASSOCED 7 REASON ASSOC LEAVE 8 REASON ASSOC NOT AUTHED 9 REASON DISASSOC PWRCAP BAD 10 REASON DISASSOC SUPCHAN BAD 11 REASON IE INVALID 13 REASON MIC FAILURE 14 REASON 4WAY HANDSHAKE TIMEOUT 15 REASON GROUP KEY UPDATE TIMEOUT 16 REASON IE IN 4WAY DIFFERS 17 REASON GROUP CIPHER INVALID 18 REASON PAIRWISE CIPHER INVALID 19 REASON AKMP INVALID 20 I INT STAMODE I REASON UNSUPP RSN IE VERSION 21 REASON INVALID RSN IE CAP 22 REASON 802 1X AUTH FAILED 23 REASON CIPHER SUITE REJECTED 24 REASON BEACON TIMEOUT 200 REASON NO AP FOUND 201 T event_info event info INT STAMODE event_info event_info event_info I in event inf event EV in event event_in fo LO ES Fo T _AUTHMODE CHANGE auth change old mode auth change new mode GOT IP got ip ip got ip mask got ip gw INT SOFTAPMODE STACONN S S ENT SOFTAPMODE STADISCONNECT S S Event Info u event info ECT ED ta conneci ta conn
122. f configuration Default for project k_blinky mingw32 make exe f C Users Userl WorkSpace k blinky Makefile flash c Espressif utils esptool exe p COM11 b 115200 write flash ff 40m fm gio fs 4m 0x00000 firmware eagle flash bin 0x40000 firmware eagle iromOtext bin Connecting Traceback most recent call last File esptool py line 558 in module File esptool py line 160 in connect Exception Failed to connect C Users Userl WorkSpace k blinky Makefile 313 recipe for target flash failed mingw32 make exe flash Error 255 13 47 14 Build Finished took 5s 329ms The tool called esptoo1 py provides an excellent environment for flashing the device but it can also be used for reading what is currently on it This can be used for making backups of the applications contained within before re flashing them with a new program This way you can always return to what you had before over writing For example on Unix esptool py port dev ttyUSBO read flash 0x00000 OxFFFF backup 0x00000 bin esptool py port dev ttyUSBO read flash 0x10000 Ox3FFFF backup 0x10000 bin See also gt USB to UART converters gt Recommended setup for programming ESP8266 esptool py What is a UART Page 54 Programming environments We can program the ESP8266 using the Espressif supplied SDK on Windows using Eclipse A separate chapter on setting that up is supplied We also have the ability to program the ESP8266 using
123. fe853c len 1340 rodata Ox3ffe8540 Ox3ffe8af0 len 1456 bss Ox3ffe8af0 0x3fff1c18 len 37160 heap 0x3fff1c18 0x3fffc000 len 41960 The data section is where global and static local initialized variables are kept The rodata section is where read only global and static data is kept The bss is where un initialized global and local static data is kept The heap is where the heap of the program can be found See also e Wikipedia bss e Wikipedia Data segment system get free heap size Get the size of the available memory heap int system get fr heap size For example 40544 See also os_malloc os free Page 143 system_os_task Setup a task for execution bool system os task os task t task uint8 priority os event t queue uint queueLength The os task t is a pointer to a task function which has the signature void functionName os event t event The os event tisa structure which contains os signal t signal os param t param Both of these are unsigned 32bit integers The return is true on success and false on failure See also Task handling system_os_post Post a message to a task bool system os post uint8 priority os signal t signal os param t parameter The return is true on success and false on failure See also Task handling system_os_task system_get_time Get the system time This is measured in microseconds since last device s
124. g the parameters for PMW this function can be called See also Pulse Width Modulation PWM pwm set duty void pwm set duty uint32 duty uint8 channel The resolution of a duty step is 45 nanoseconds Here we can set the number of duty steps in a cycle For example imagine we have a period of IKHz This means that 1 cycle is 1000 microseconds If we want the duty cycle to be 50 then the output has to be high for 500 microseconds 500 microseconds is 11111 units of 45 nanoseconds and that would become the duty value Formulaically the duty ratio is duty 45 period 1000 The duty parameter supplies the number of 45 nanosecond intervals that the output will be high in one period The channel parameter specifies which of the PWM channels is being changed Page 198 See also Pulse Width Modulation PWM pwm_get_duty pwm_init pwm_get_duty uint32 pwm get duty uint8 channel Get the duty value of the specified channel See also Pulse Width Modulation PWM pwm_get_duty pwm_init pwm_set_period Set the period for PWM operations void pwm set period uint32 period The period parameter is the PWM period The value is measured in microseconds with a minimum value of 1000 giving a 1KHz period there are 1000 periods of 1000 microseconds in a second See also Pulse Width Modulation PWM pwm_get_period pwm_init pwm_get_period uint32 pwm get period Get the current setti
125. ga 2560 Arduino Mega ADK Arduino Leonardo Arduino Micro Arduino Esplora Arduino Mini Arduino Ethernet Arduino Fio Arduino BT LilyPad Arduino USB LilyPad Arduino Arduino Pro or Pro Mini Arduino NG or older Arduino Robot Control Arduino Robot Motor Arduino Gemma Arduino Pro of Pro Mini ATme 16 MHz on COM11 Install the ESP8266 support Page 118 Filter your search Intel i686 Boards by Intel Boards included in this package Edison More info AMEL Tech Boards by AMEL Technology Boards included in this package SmartEverything Fox Online help More info esp3266 by ESP8266 Community Boards included in this package Generic ESP8266 Module Online help More info This will contact the Internet and download the artifacts necessary for ESP8266 support Once completed in the Arduino IDE Board selections you will find the Generic ESP8266 Module Page 119 e sketch jul12a Arduino 1 6 5 File Edit Sketch Tools Help arog x Auto Format Ctrl T pum Archive Sketch sketch Ju a Fix Encoding amp Reload l void setuP Serial Monitor Ctrl Shift M put ya i Board Arduino Pro or Pro Mini Boards Manager Processor ATmega328 5V 16 MHz Arduino AVR Boards 6 void loop Port COM11 Arduino Yun E Programmer AVR ISP e Hir mr 8 Arduino Duemilanove or Diecimila 3 Burn Bootloader q Arduino Nano Arduino Mega or Mega 2560 Arduino Mega ADK Arduino Leon
126. ge here but there are times when I still think to myself Hmm my carpet needs cleaning I think I ll hoover it I don t think I ve owned a Hoover brand vacuum cleaner in decades but the nomenclature has become ingrained The WiFi library The Arduino has a WiFi library for use with its WiFi shield A library with a similar interface has been supplied for the Arduino environment for the ESP8266 To use the ESP8266 WiFi library you must include its header include lt ESP8266WiFi h gt To be a station and connect to an access point execute a call to wiFi begin ssid password Now we need to to poll wiFi status When this returns WL_CONNECTED then we are connected to the network See also Arduino WiFi library WiFi begin Start a WiFi connection as a station int begin const char ssid const char passPhrase NULL int32 t channel 0 uint8 t bssid 6 NULL int begin char ssid char passPhrase NULL int32 t channel 0 uint8 t bssid 6 NULL Page 121 Begin a WiFi connection as a station The ssid parameter is mandatory but the others can be left as default The return value is our current connection status WiFi beingSmartConfig bool beginSmartConfig WiFi beginWPSConfi bool beginWPSConfig WiFi BSSID Retrieve the current BSSID uint8 t BSSID uint8 t BSSID uint8 t networkItem Retrieve the current BSSID WiFi BSSIDstr Retrieve the current BSSID as a string representation
127. guration station_config Page 160 wifi_station_connect Connect the station to an access point bool wifi station connect If we are already connected to a different access point then we first need to disconnect from it using wifi station disconnect There is also an auto connect attribute which can be used to allow the device to attempt to connect to the last access point seen when it is powered on This can be set with the wifi station set auto connect function Includes user interface h See also Connecting to an access point wifi_station_disconnect wifi_station_set_auto_connect wifi_station_get_auto_connect wifi_station_disconnect Disconnect the station from an access point bool wifi station disconnect We should presume that we have previously connected viaa wifi station connect We can determine our current connection status through wifi station get connect status Includes user interface h See also wifi_station_connect wifi_station_get_connect_status wifi_station_get_connect_status Get the connection status of the station uint8 wifi station get connect status The result is an enum with the following possible values Page 161 Enum name Value STATION_IDLE 0 STATION CONNECTING 1 STATION_WRONG_PASSWORD STATION_NO_AP FOUND STATION_CONNECT_FAIL STATION GOT IP JAIN Includes user interface h wifi station sc
128. has wired an ESP8266 to a serial converter the next question will be Is it working When we connect a serial monitor the first command we can send is AT which should respond with a simple OK An instruction passed to the device follows one of the following syntax options Page 29 Type Format Description Test AT lt x gt Query the parameters and its range of values Query AT lt x gt Return the current value of the parameter Set AT lt x gt lt Set the value of a parameter Execute AT lt x gt Execute a command All AT instructions end with the r n pair Page 30 Command Description AT Returns OK AT RST Restart the ESP8266 AT GMR Returns firmware version for both the AT command processor and the SDK in use Currently the response returned looks like AT version 0 21 0 0 SDK version 0 9 5 AT GSLP lt time gt Put the device into a deep sleep for a time in milliseconds It will wake up after this period ATE 0 1 Echo AT commands ATEO Echo commands off ATEI Echo commands on AT RESTORE Restore the defaults of settings in flash memory AT UART_CUR lt baundrate gt lt databits gt lt stopbits gt lt parity gt lt flow control gt AT UART_DEF lt baundrate gt lt databits gt lt stopbits gt lt parity gt lt flow control gt AT SLEEP AT SLEEP
129. have to set some of the GPIO pins to be low and then reboot This is the signal that it is now ready to be flashed Obviously you can build a circuit that you use for flashing your firmware and then place the device in its final circuit but you will find that during development you will want to flash and test pretty frequently This means that you will want to use jumper wires and to allow you to move the links of pins on your breadboards from their flash position to their normal use position Page 42 Programming The ESP8266 allows you to write applications that can run natively on the device You can compile C language code and deploy it to the device through a process known as flashing In order for your applications to do something useful they have to be able to interact with the environment This could be making network connections or sending receiving data from attached sensors inputs and outputs In order to make that happen the ESP8266 contains a core set of functions that we can loosely think of as the operating system of the device The services of the operating system are exposed to be called from your application providing a contract of services that you can leverage These services are fully documented In order to successfully write applications for deployment you need to be aware of the existence of these services They become indispensable tools in your tool chest For example if you need to connect to a WiFi access point ther
130. he wifi station set config current We should not try and perform any WiFi operations until the device is fully initialized We know we are initialized by registering a callback using the system init done cb function For example void initDone wifi set opmode current STATION MODE struct station config stationConfig strncpy stationConfig ssid myssid 32 strncpy stationConfig password mypassword 64 wifi station set config amp stationConfig See also System init done cb wifi station get config wifi station get config default wifi station set config wifi station set config current wifi set opmode current station config Connecting to an access point Once the ESP8266 has been set up with the station configuration details which includes the SSID and password we are ready to perform a connection to the target access point The function wifi station connect Will form the connection Realize that this is not instantaneous and you should not assume that immediately following this command you are connected Nothing in the ESP8266 blocks and as such neither does the call to this function Some time later we will actually be connected We will see two callback events fired The first is Page 69 EVENT STAMODE CONNECTED indicating that we have connected to the access point The second event is EVENT STAMODE GOT IP which indicates that we have been assig
131. his is a 5V output e Gnd Ground To drive this device we need to utilize two pins on the ESP8266 that we will logically call Trig and Echo In my design I set Trig to be GPIO4 and Echo to be GPIOS Our design for the application will not include any networking but it should be straightforward to ass it as needed We will setup a timer that fires once a second which is how often we wish to take a measurement When the timer wakes up we will pulse Trig from low to high and back to low holding high for 10 microseconds We will now record the time and start polling the Echo pin waiting for it to go high When it does we will record the time again and subtracting one from the one will tell us how long it took the sound to bounce back From that we can calculate Page 133 the distance to an object If no response is received in 20 msecs we will assume that there was no object to detect We will then log the result to the Serial console An example program that performs this design is shown next define TRIG PIN 4 define ECHO PIN 5 os timer t myTimer void user rf pre init void void timerCallback void pArg os printf Tick n GPIO OUTPUT SET TRIG PIN 1 os delay us 10 GPIO OUTPUT SET TRIG PIN 0 uint32 val GPIO INPUT GET ECHO PIN while val 0 val GPIO INPUT GET ECHO PIN uint32 startTime system get time val GPIO INPUT GET E
132. ho is the transmitter is purely up to the design of the application For example imagine we had a project to turn on an LED at an ESP8266 when it receives a 1 character and turn it off when it receives a 0 character In that story the ESP8266 would be exclusively a receiver and simply by our choices need not transmit data The partner would be exclusively a transmitter Now let us consider a second example In this case the ESP8266 is connected to a temperature sensor and every few seconds it sends the current temperature to the partner In that story the ESP8266 is exclusively a transmitter and the partner only a receiver Finally we can image an ESP8266 connected to multiple sensors It receives commands from the partner as input which it interprets Based on the received data the correct sensor is chosen its value read and the results transmitted back In this story the ESP8266 is at first a receiver and then becomes a transmitter while the partner is the opposite To receive data from a partner we register a callback function using espconn regist recvcb We pass in the struct espconn that was supplied in the connected callback that identifies our connection This registered callback function is invoked when new data becomes available from the partner The callback function is passed a buffer containing the data and an indicator of how much data was received The following is an example of logging data that is received over the
133. iFi events wifi_set_event_handle_cb eventReasonToString Convert an event reason to a string representation char eventReasonToString int reason Some of the WiFi event callbacks can return a reason value that is an encoding of the reason that something failed This function returns a string representation of the int value code flashSizeAndMapToString Return a string representation of the flash size and map char flashSizeAndMapToString setAsGpio Set a pin to be used as a GPIO void setAsGpio uint8 pin Set the GPIO supplied as pin to be GPIO function See also GPIOs setupBlink Setup a blinking LED on the given pin void setupBlink uint8 blinkPin The blinkPin parameter is the pin to use for blinking Page 137 toHex Convert an array of bytes to a hex string uint8 toHex uint8 ptr int size uint8 buffer Convert the bytes pointed to by ptr for size bytes into a hex string The buffer parameter will be where the result will be stored It must be 2 size 1 bytes in length or more Each byte is 2 hex characters plus a single byte NULL terminator at the end The function returns the start of the buffer Page 138 API Reference Now we have a mini reference to the syntax of many of the ESP8266 exposed APIs Do not use this reference exclusively Please also refer to the published Espressif SDK Programming Guide Some acronyms and other names are used in the naming of APIs and may need some expl
134. ibe some of the components that we have found extremely useful while building ESP8266 solutions Page 35 USB to UART converters You can t program an ESP8266 without supplying it data through a UART The easiest way to achieve this is through the use of a USB to UART converter I use the devices that are based upon the CP2102 STC which can be found cheaply on ebay for under 2 each Another popular brand are the devices from Future Technology Devices International FTDI You will want at least two One for programming and one for debugging I suggest buying more than two just in case When ordering don t forget to get some male female USB extender cables as it is unlikely you will be able to attach your USB devices to both a breadboard and the PC at the same time via direct connection and although connector cables will work plugging into the breadboard is just so much easier USB connector cables allow you to easily connect from the PC to the USB socket to the UART USB plug Here is an image of the type of connector cable I recommend Get them with as short a cable length as possible 12 24 inches should be preferred When we plug in a USB UART into a Windows machine we can learn the COM port that the new serial port appears upon by opening the Windows Device Manager There are a number of ways of doing this one way is to launch it from the DOS command window with mmc devmgmt msc Under the section called Ports
135. ill be peers of each other If the partner in our conversation should close the connection we will be informed of that through the function we register with espconn regist disconcb The state field of the struct espconn will contain CLOSE Detection the graceful shutdown of a partner allows us to perform logic that we may need such as releasing resources or persisting data If a TCP connection is formed and no traffic flows over the connection for at least 10 seconds default then the connection is automatically closed from the ESP8266 end The idle connection timeout property can be set with the espconn regist time function See also espconn accept espconn connect espconn disconnect espconn regist connectcb espconn regist disconcb espconn regist time Page 77 struct espconn 5 esp_tcp Sending and receiving TCP data At this point let us now assume that we have a connection between an ESP8266 and a partner application Having a connection is great but now we need to have a conversation Information and data needs to flow in one or both directions There are two considerations we may receive data from the partner or we may wish to send data to the parter It is important to note that in TCP a connection is bidirectional Once the connection has been established either party can send data at any time There is no concept of one party having exclusive sending or receiving rights The choice of who is the receiver and w
136. imerCallback void user init void uart init BIT RATE 115200 BIT RATE 115200 os timer setfn amp myTimer timerCallback NULL os timer arm amp myTimer 1000 1 End of user init If we build out on a breadboard a circuit which includes a light dependent resistor such as the following MM eee cocuga ceuta earan Page 97 Then when we change the amount of light falling on the resistor we can see the values change as data is written in the output log This can be used to trigger an action for example when it becomes dark Open question What is the sample rate of the ADC See also system_adc_read Wikipedia Voltage divider Watchdog timer The ESP8266 is a single threaded processor This means it can only do one thing at a time as there are no parallel threads that can be executed An implication of this is that when the OS gives control to your application it doesn t get control back until you explicitly relinquish it However this can cause problems The ESP8266 is primarily a WiFi and TCP IP device that expects to be able to receive and transmit data as well as respond to asynchronous events within a timely manner As an example if your ESP8266 device is connected to an access point and the access point wants to validate that you are still connected it may transmit a packet to you and expect a response You have no control over when that will happen If your own application program ha
137. inbound espconn recv hold Suspend receiving TCP data espconn_recv_unhold Unblock receiving TCP data UDP APIs espconn_create Create a UDP control block in preparation for sending datagrams sint8 espconn create struct espconn espconn Return code of 0 on success otherwise the code indicates the error ESPCONN ARG Illegal argument ESPCONN_ISCONN Already connected ESPCONN MEM Out of memory See also UDP espconn_regist_sentcb espconn_regist_recvcb espconn_sent espconn_delete Page 186 espconn_igmp_join Join a multicast group espconn_igmp_leave Leave a multicast group ping APIs ping_start bool ping start struct ping option ping opt Includes ping h See also Ping request struct ping_option ping_regist_recv bool ping regist recv struct ping option ping opt ping recv function ping recv Register a function that will be called when a ping is received The signature of the function is void functionName void pingOpt void pingResp The parameters passed in are pingopt which is a pointer to the struct ping option and pingResp Which is a pointer to a struct ping resp Includes ping h See also Ping request struct ping_option struct ping_resp ping_regist_sent bool ping regist sent struct ping option ping opt ping sent function ping sent Register a function that will be called when a ping is sent The signature of the function is void function
138. indication of whether or not an error occurred A value of 0 means no error Includes ping h See also Ping request ping start ping regist recv ping regist sent enum phy mode The 802 11 physical mode to be used or being used PHY MODE 11B PHY MODE 11G PHY MODE 11N See also wifi_set_phy_mode wifi_get_phy_mode GPIO_INT_TYPE These are the possible triggers for an interrupt This is an enum defined as follows GPIO PIN INTR DISABLE Interrupts are disabled GPIO PIN INTR POS EDG E Interrupt on a positive edge transition GPIO PIN INTR N EG EDG E Interrupt on a negative edge transition GPIO PIN INTR ANY GPIO PIN INTR LOLEFE EDG E Interrupt on any edge transition EL Interrupt when low GPIO PIN INTR HILE See also gpio_pin_wakeup_enable System_Event_t The event type contains EL Interrupt when high e uint32 event The type of event that occurred Can be Page 207 Page 208 lt E ENT uin STAMODE CONNECTED We have successfully connected to an access point t8 32 event_info connected ssid The SSID of the access point uint8 ssid_len uint8 6 bssid eve nt info connected channel The channel used to connect to the access point ENT_ STAMODE DISCONNECTED t8 6
139. ion We start by introducing an absolutely vital data structure that is called struct espconn This data structure contains much of the state of our connection and is passed into most of our TCP APIs We initialize it by setting a number of its fields e type This is the type of connection we are going to use Since we want to use a TCP connection as opposed to a UDP connection we supply ESPCONN_TCP as the value e state The state of the connection will change over time but we initialize it to have an initial empty state by supplying ESPCONN_NONE For example jOCAL struct espconn connl jOCAL void init connl type ESPCONN TCP connl state ESPCONN NONE M Page 75 Now we introduce another structure called esp tcp This structure contains TCP specific settings For our story this is where we supply the port number upon which our TCP connection will listen for client connections This is supplied in the property called local port OCAL esp tcp tcpl jOCAL void init tcpl local port 25867 Within the struct espconn data type there is a field called proto which is a pointer to a protocol specific data structure For a TCP connection this will be a pointer to an esp tcp instance and this is where we get to glue the story together The full code becomes jOCAL struct espconn connl OCAL esp tcp tcpl jOCAL void init tcpl lo
140. ir responses It is important to note that immediately after calling sntp_init you will not yet know what the current time may be This is because it may take a few seconds for the ESP8266 to sends the time requests and get their responses and this will all happen asynchronously to your current commands and won t complete till sometime later When ready we can retrieve the current time with a call to sntp get current timestamp which will return the number of seconds since the 1 of January 1970 UTC We can also call the function called sntp get real time which will return a string representation of the time See also sntp_setserver sntp_setservername sntp_init Page 85 sntp_set_timezone sntp_get_current_timestamp sntp_get_real_time IETF RFC5905 Network Time Protocol Version 4 Protocol and Algorithms Specification GPIOs The ESP8266 has 17 GPIO pins When we think of a GPIO we must realize that at any one time each instance has two modes It can either be an input or an output When it is an input we can read a value from it and determine the logic level of the signal present at the physical pin When it is an output we can write a logic level to it and that will appear as a physical output Remember to distinguish between the ESP8266 integrated circuit which is a tiny device which differs from the various models of breakout board such as the ESP 1 which has 16 pins expos
141. is complete and we also register a function called eventCB to be called when WiFi events arrive indicating a change of state With these items having been setup we return control back to the OS We expect to be called back through initDone when the device is fully read for work In initDone we define ourselves as a Wifi Station and name the access point with its password that we wish to use Finally we ask for a connection to the access point If all goes well we will be connected to the access point and then be allocated an IP address Both of these will result in events being generated which will cause us to wake up in eventCB The only event we are interested in seeing is the allocation of the IP address When we are notified of that we call the function called setupupP to initialize our UDP listening environment Page 131 In setupUDP we create a struct espconn control block defined for UDP and configured to listen on our chosen port of 25867 We also register a receive callback to the function recvcB This will be called when new data arrives At this point all our setup is completed and we have a device connected to the WiFi network listening on UDP port 25867 for datagrams When a datagram arrives we wake up in recvCB having been passed in the datagram data We check that we actually have data and that it is good if not we end the callback straight away Finally we look at the first character of the
142. its We have some helper macros that are available These are useful wrappers around gpio output set and gpio input get PIO OUTPUT SET GPIO NUMBER value Sets the corresponding GPIO to be output Q and sets its value GPIO DIS OUTPUT GPIO NUMBER Sets the corresponding GPIO to be input disabled output GPIO INPUT GET GPIO NUMBER Gets the value of the input GPIO Since pins on an ESP8266 can serve multiple purposes we must first declare what function that pin will have To do this we use a macro which sets the function of the logical pin PIN FUNC SELECT pinName functionUsage For example to define GPIO2 as a GPIO pin and set its value we might code PIN FUNC SEL ERIPHS IO MUX GPIO2 U FUNC GPIO2 GPIO OUTPUT SET 2 1 zin 3 FU Here is the complete table of mappings Page 89 Pin Name Function 1 Function 2 Function 3 Function 4 Physical pin Devices MTDI U MTDI PSI DATA HSPIQ MISO GPIO12 10 12 MTCK_U MTCK PSI BCK HSPID MOSI GPIO13 12 12 MTMS U MTMS DSI WS HSPICLK GPIO14 9 12 MTDO_U MTDO DSO BCK HSPICS GPIO15 13 12 UORXD U UORXD DSO DATA GPIO3 25 1 12 UOTXD U UOTXD SPICS1 GPIO1 26 1 12 SD CLK U SD CLK SPICLK GPIO6 21 SD DATAO U SD DATAO SPIQ GPIO7 22 SD DATA U SD DATA SPID GPIO8 23 SD DATA2U SD DATA2 SPIHD GPIO9 18 SD DATA3 U SD DATA
143. l simply sit there for as long as needed until a connection request arrives The other side of the connection is responsible for initiating the connection and it actively asks for a connection to be formed Once the connection has been constructed both sides can send and receive data In order for the client to request a connection 1t must know the address information on which the server is listening This address is composed of two distinct parts The first part is the IP address of the server and the second part is the port number for the specific listener If we think about a PC you may have many applications on it each of which can receive an incoming connection Just knowing the IP address of your PC is not sufficient to address a connection to the correct application The combination of IP address plus port number provides all the addressing necessary As an analogy to this think of your cell phone It is passively sitting there until someone calls it In our story it is the listener The address that someone uses to form a connection is your phone number which is comprised of an area code plus the remainder For example a phone number of 817 555 1234 will reach a particular phone However the area code of 817 is for Fort Worth in Texas calling that by itself is not sufficient to reach an individual the full phone number is required No we will look at how an ESP8266 can set itself up as a listener for an incoming TCP IP connect
144. lete Determine the status of a previous scan request int8 t scanComplete If the result is gt 0 then this is the number of WiFi access points found Otherwise the value is less than 0 and the codes are SCAN RUNNING A scan is currently in progress SCAN FAILD A scan failed WiFi scanDelete Delete the results from a previous scan void scanDelete Delete the results from a previous scan A request to scan the network results in the allocation of memory This call releases that memory WiFi scanNetworks Scan the access points in the environment int8 t scanNetworks bool async false Scan the access points in the environment We can either perform this synchronous or asynchronous On a synchronous call the result is the number of access points found Page 125 WiFi smartConfigDone bool smartConfigDone WiFi softAP Setup an access point void softAP const char ssid void softAP const char ssid const char passPhrase int channel 1 int ssid_hidden 0 WiFi softAPConfig void softAPConfig IPAddress local_ip IPAddress gateway IPAddress subnet WiFi softAPdisconnect int softAPdisconnect bool wifiOff false WiFi softAPmacAddress uint8 t softAPmacAddress uint8 t mac WiFi softAPIP Get the IP address of the access point interface IPAddress softAPIP Return the IP address of the access point interface WiFi SSID Retrieve the SSID char SSID const char SSID uint8 t networkIt
145. mand interface When we think about an ESP8266 device we find that it has a built in UART Serial connection This means that it can both send and receive data using the UART protocol We also know that the device can communicate with WiFi What if we had an application that ran on the ESP8266 Page 28 that took instructions received over the serial link executed them and then returned a response This would then allow us to use the ESP8266 without ever having to know the programming languages that are native to the device This is exactly what a program that has so far been found to be pre installed on the ESP8266 does for us The program is called the AT command processor named after the format of the commands sent through the serial link These commands are all prefixed with AT and follow roughly the style known as the Hayes command set AT Command Processor sore ESP8266 If we think of an application wishing to use the services of the ESP8266 as a client and the ESP8266 as a server capable of servicing those commands as a server then the client sends strings of characters through the UART connection to the server and server responds with the outcome Espressif publish a complete set of AT command documentation which can be found in their forum page at http bbs espressif com viewforum php f 5 There are two primary documents ESP8266EX AT Instruction Set ESP8266EX AT Command Examples Commands When one
146. n action has completed or an asynchronous events occurs For example when we wish to receive an incoming network connection we can t simply wait for that connection to arrive Instead we register a connection callback function and then return control back to the OS When the connection eventually arrives in the future the callback function that we previously registered is invoked on our behalf The following table lists the callback functions that the ESP8266 provides supporting TCP connections and events Register Function Callback Description espconn_regist_connectcb espconn_connect_callback TCP connected successfully espconn_regist_disconcb espconn disconnect callback TCP disconnected successfully espconn regist reconcb espconn reconnect callback Error detected or TCP disconnected espconn regist sentcb espconn sent callback Sent TCP or UDP data espconn regist recvcb espconn recv callback Received TCP or UDP data espconn regist write finish espconn write finish callback Write data into TCP send buffer See also espconn regist connectcb espconn regist disconcb espconn regist reconcb espconn regist sentcb espconn regist recvcb Page 74 espconn_regist_write_finish TCP A TCP connection is a bi directional pipe through which data can flow in both directions Before the connection is established one side is acting as a server It is passively listening for incoming connection requests It wil
147. n initialize the data structure with a call to espconn create and now we are ready to send data We use the espconn sent function Page 82 When we have sent all our data we can conclude with an espconn_delete to release the resources that the ESP8266 maintains for data sending Here is an example jOCAL struct espconn sendResponse OCAL esp udp udp void sendDatagram char datagram uintl6 size sendResponse type ESPCONN UDP sendResponse state ESPCONN NONE sendResponse proto udp amp udp IP4 ADDR ip addr t sendResponse proto udp remote ip 192 168 1 7 sendResponse proto udp remote port 9876 Remote port err espconn create amp sendResponse err espconn sent amp sendResponse hil23 5 err espconn delete amp sendResponse See also espconn_create espconn_delete espconn_sent espconn_regist_recvcb espconn_regist_sentcb struct espconn Broadcast with UDP One of the features available to us with UDP is the concept of broadcast This is the notion that a sender of data can build a datagram and transmit it such that all the devices on the same subnet can receive a copy of it Receivers choose a UDP port and start listening upon it just as they normally would A transmitting application transmits a message on the same port but with an IP address where the host part of the IP address is all binary ones For example if we have a netma
148. nction that will be called when the ESP8266 detects certain types of WiFi related events The registered function is invoked and passed a rich data structure that Page 67 includes the type of event and associated data corresponding to that event The types of events that cause the callback to occur are e We connected to an access point We disconnected from an access point e The authorization mode changed e We got a DHCP issued IP address e A station connected to us when we are in Access Point mode Astation disconnected from us when we are in Access Point mode Here is an example of an event handler function that simply logs the name of the event that was seen LOCAL void eventHandler Syst m Event t event switch event event case EVENT STAMODE CONNECTED os printf Event EVENT STAMODE CONNECTED break case EVENT STAMODE DISCONNECTED os printf Event EVENT STAMODE DISCONNECTED break case EVENT STAMODE AUTHMODE CHANGE os printf Event EVENT STAMODE AUTHMODE CHANGE break case EVENT STAMODE GOT IP os printf Event EVE T STAMODE CONNECTED break case EVENT SOFTAPMODE STACONNECTED os printf Event EVENT SOFTAPMODE STACONNECTED break case
149. nd report it Try not to roll your eyes and ask why no one caught it before now instead help everyone and report it and feel good that you helped push the ball forward I anticipate that over time the API will change to correct such potential defects so check often You may find that code you write today using espconn sent won t work when a new patch or release is applied because the function was renamed to espconn_send This command takes the struct espconn which identifies which connection to send data through The function also takes a pointer to a buffer of data and the length of the data to send Page 79 A vital consideration is that the data to be sent is not sent immediately When we call espconn sent what we are doing is handing off a buffer of data to be transmitted at some time in the future We anticipate this will be a few microseconds but it could be longer We must honor the contract When the ESP8266 does successfully transmit the data a callback will be made to a function that was registered with the espconn_regist_sentcb Only after having seen a confirmation that the last transmission request has been completed should we execute another espconn sent request When we ask for data to be transmitted we provide a pointer to a buffer that contains the data It is important to realize that we must maintain that data until after we are sure its content has been sent For example we can t request a
150. ne is in software the other in hardware This function stops the software timer It can be restarted with system soft wdt restart however a second timer called the hardware watchdog timer will fire after about 8 seconds and doesn t appear able to be trapped See also Page 98 system_soft_wdt_stop system_soft_wdt_restart Mapping from Arduino Without argument the Arduino has become the most successful microprocessor programming environment to date There are tons and tons of existing sketches in existence and let us not forget about the wealth of libraries Tools and utilities exist to compile and run Arduino sketches on ESP8266s What if instead we wanted to port those Arduino sketches to native ESP8266 code Can we find mappings between the Arduino APIs and the corresponding ESP8266 APIs Arduino ESP8266 digitalWrite pin value GPIO_OUTPUT_SET pin value digitalRead pin GPIO INPUT GET pin delay ms os delay us ms 1000 Note ms lt 65535 delayMicroseconds us os delay us us millis system get time 1000 From a functional perspective here are some comparisons between an Arduino and an ESP8266 ESP8266 Arduino Uno GPIOs 17 Fewer typically exposed 14 20 including analog Analog input 1 6 PWM channels 8 6 Clock speed 80MHz 16MHz Processor Tensilica Atmel SRAM 45KBytes 2KBytes Flash 512Kb or mor
151. ned an IP address by the DHCP server Only at that point can we truly participate in communications If we are using static IP addresses for our device then we will only see the connected event There is one further consideration associated with connecting to access points and that is the idea of automatic connection There is a boolean flag that is stored in flash that indicates whether or not the ESP8266 should attempt to automatically connect to the last used access point If set to true then after the device is started and without you having to code any API calls it will attempt to connect to the last used access point This is a convenience that I prefer to switch off Usually I want control in my device to determine when I connect We can enable or disable the auto connect feature by making a call to wifi station set auto connect See also Handling WiFi events wifi_station_set_auto_connect wifi_station_connect wifi_station_disconnect Control and data flows when connecting as a station We are now at the stage where we can draw a sequence flow of the parts Some functions you are responsible and must supply including e user init Entry point into the application e initDonecB Callback when initialization has been completed e eventcB Callback when a WiFi related event is detected The other functions we are responsible for calling We will consider this part of the sequence completed when we have an indication
152. network LOCAL void recvCB void arg char pData unsigned short len struct espconn pEspConn struct espconn arg os printf Received data length d n len int i 0 for i20 i lt len i os printf sc pDatali os printf An End of recvCB Page 78 The function called recvcB is registered as a callback when data is available for the connection With this in mind we can start running some experiments and the results will be interesting If we send data we see the callback being invoked as expected However as the size of the data transmitted which is received by the ESP8266 increases at about 1460 bytes a strange thing happens Instead of recvcB being called once we see it being called twice The first time it gets the first 1460 bytes and the second time it gets what remains This is repeated for increments of 1460 byte transmission sizes For example if we send 5000 bytes recvcB is called 4 times The first three times with 1460 bytes of data and the last with 620 bytes giving a total of 5000 Why would this be Part of the answer is that the ESP8266 has only a very small amount of RAM available to it and needs to be able to support parallel connections As such it can apparently throttle the data being sent from the sender until space is available to process it It can t be stressed enough the importance of this concept Data sent from the server over a TCP connection i
153. ng of the PWM period See also Pulse Width Modulation PWM pwm set period pwm_init get_pwm_version uint32 get pwm version See also Pulse Width Modulation PWM Page 199 set_pwm_debug_en uint8 print_en Used to enable or disable debug print Bit twiddling e BIT b The 2 b value ESP Now esp now init esp now deinit esp now register recv cb esp now unregister recv cb esp now send esp now add peer esp now del peer esp now set self role esp now get self role esp now set peer role esp now get peer role esp now set peer key esp now get peer key Mystery ets wdt enable perhaps enables the watch dog timer ets wdt disable perhaps disables the watch dog timer ESP DBG system mktime e atoi Page 200 Data structures station_config A description of a station configuration Contains the following fields uint8 ssid 32 The SSID of the access point uint8 password 64 The password to access the access point uint8 bssid_set Flag to indicate whether or not to use the bssid property A value of 1 means to use and a value of 0 means to not use uint8 bssid 6 Ifseveral access points have the same SSID BSSID can contain a MAC address to indicate which of the access points to connect to See also Station configuration wifi station get config wifi station get config default wifi station set config wifi station set config current s
154. o NULL os printf Station IP d d d d n IP2STR amp stationInfo ip stationInfo STAILQ NEXT stationInfo next wifi softap free station info See also wifi set opmode wifi set opmode current wifi softap get station num wifi softap get station info wifi softap free station info The DHCP server When the ESP8266 is performing the role of an access point it is likely that you will want it to also behave as a DHCP server so that connecting stations will be able to be automatically assigned IP addresses and learn their subnet masks and gateways The DHCP server can be started and stopped within the device using the APIs called wifi softap dhcps start andwifi softap dhcps stop The current status started or stopped of the DHCP server can be found with a call to wifi softap dhcps status The default range of IP addresses offered by the DHCP server is 192 168 4 1 upwards The first address becomes assigned to the ESP8266 itself It is important to realize that this address range is not the same address range as your LAN where you may be working The ESP8266 has formed its own network address space and even though they may appear with the same sorts of numbers 192 168 x x they are isolated and independent networks If you start an access point on the ESP8266 and connect to it from your phone don t be surprised when you try and ping it from your Internet connected PC and don t get a response See al
155. ons related to the esp now support ets sys h Unknown gpio h Definitions for GPIO interactions ip addr h IP address definitions and macros Page 44 mem h Definitions for memory manipulation and access os_type h OS type definitions osapi h Includes a user supplied header called user_config h ping h Definitions for the ping capability pwm h Definitions for PWM queue h Queue and list definitions smartconfig h Definitions for smart config sntp h Definitions for SNTP spi_flash h Definitions for flash upgrade h Definitions for upgrades user_interface h Definitions for OS and WiFi I have no explanation for why this file is named user interface as there is obviously no UI involved with ESP8266s Compiling Application code for an ESP8266 can be written in C Before we can deploy an application we must compile the code into binary machine code instructions To do this we need a set of development tools My personal preference is the package for Eclipse which has everything pre built and ready for use However these tools can also be downloaded from the Internet as open source projects on a piece by piece basis The macro LOCAL is a synonym for the C language keyword static From reading the docs no published example of how to compile was found However when one uses the Eclipse open source project one can see the Makefiles that are used and this exp
156. or UDP addr Remote IP address Page 34 port Remote port e local port For UDP only e mode For UDP only o 0 destination peer entity of UDP is fixed o destination peer entity may change once o 2 destination peer entity may change AT CIPSTART 222 AT CIPSEND lt length gt Send length characters AT CIPCLOSE Close a connection AT CIFSR Get the local IP address AT CIPMUX lt mode gt Enable multiple connections e 0 Single connection e Multiple connections AT CIPMUX Returns the current value for CIPMUX e 0 Single connection e Multiple connections AT CTPSERVER lt mode gt lt p Configure as a TCP server If no port is supplied default is 333 A server may ort gt only be created when CIPMUX 1 allow multiple connections mode o 0 Delete server needs a restart after o Create server AT CIPMODE lt mode gt Set the transfer mode 0 Normal mode e 1 Unvarnished mode AT CIPSTO lt time gt Set server timeout A value in the range of 0 7200 seconds AT CIUPDATE 222 See also YouTube ESP8266 Tutorial AT Commands Assembling circuits Since the ESP8266 is an actual electronic component some physical assembly is required This book will not attempt to cover non ESP8266 electronics as that is a very big and broad subject in its own right However what we will do is descr
157. ors has caught the imagination of countless folks The boards containing these Atmel chips combined with a convention for connections and also a free set of development tools has lowered the entry point for playing with electronics to virtually nill Unlike a PC these processors are extremely low end with low amounts of ram and storage capabilities They won t be replacing the desktop or laptop any time soon For those who want more oomph in their processors the folks over at Raspberry PI have developed a very cheap 45 board that is based on the ARM processors that has much more memory and uses micro SD for persistent data storage These devices run a variant of the Linux operating system I m not going to talk further about the Raspberry PI as it is in the class of computer as opposed to microprocessor These microprocessors and architectures are great and there will always be a place for them However there is a catch and that is networking These devices have an amazing set of capabilities including direct electrical inputs and outputs GPIOs and support for a variety of protocols including SPI I2C UART and more however none of them so far come with wireless networking included No question in my mind that the Arduino has captured everyone s attention The Arduino is based on the Atmel chips and has a variety of physical sizes in its open hardware footprints The primary microprocessor used is the ATmega328 One can find instanc
158. oses examples of compilation A typical compilation looks like 17 57 16 Build of configuration Default for project k blinky mingw32 make exe f C Users IBM ADMIN Documents RaspberryPi ESP8266 EclipseDevKit WorkSpace k blinky Make file all CC user user main c AR build app app a LD build app out Section info build app out file format elf32 xtensa le Sections Idx Name Size VMA LMA File off Algn 0 data 0000053c 3ffe8000 3ffe8000 000000e0 2 4 CONTENTS ALLOC LOAD DATA 00000878 3ffe8540 3ffe8540 00000620 2 4 CONTENTS ALLOC LOAD READONLY DATA 1 rodata Page 45 2 bss 00009130 3ffe8db8 3ffe8db8 00000e98 2 4 ALLOC 3 text 00006 22 40100000 40100000 00000e98 2 2 CONTENTS ALLOC LOAD READONLY CODE 4 irom0 text 00028058 40240000 40240000 00007dc0 2 4 CONTENTS ALLOC LOAD READONLY CODE Section info Section Description Start hex End hex Used spac data Initialized Data RAM 3FFE8000 3FFE853C 1340 rodata ReadOnly Data RAM 3FFE8540 3FFE8DB8 2168 bss Uninitialized Data RAM 3FFE8DB8 3FFFIEE8 37168 text Cached Code IRAM 40100000 40106F22 28450 irom0 text Uncached Code SPI 40240000 40268058 163928 Total Used RAM 40676 Free RAM 41244 Free IRam 4336 Run objcopy please wait objcopy done Run gen appbin exe No boot needed Generate eagle flash bin and eagle iromOtext bin success
159. parameter is the index of the SNTP server to be retrieved It may be either 0 1 or 2 Includes sntp h See also Working with SNTP sntp setservername Set the hostname of a target SNTP server void sntp setservername unsigned char index char server Specify an SNTP server by its hostname The index parameter is the index of an SNTP server to be set It may be either 0 1 or 2 Page 174 The server parameter is a NULL terminated string that names the host that is an SNTP server See also Working with SNTP sntp_getservername Get the hostname of a target SNTP server char sntp setservername unsigned char index Retrieve the hostname of a specific SNTP server that was previously registered The index parameter is the index of an SNTP server that was previously set It may be either 0 1 or 2 The return from this function is a NULL terminated string Includes sntp h See also Working with SNTP sntp_init void sntp_init Initialize the SNTP functions Includes sntp h See also Working with SNTP sntp_stop void sntp_stop Includes sntp h See also Working with SNTP Page 175 sntp_get_current_timestamp Get the current timestamp as an unsigned 32 bit value representing the number of seconds since January 1 1970 UTC uint32 sntp get current timestamp Includes sntp h See also Working with SNTP sntp_get_real_time char sntp get real time long t
160. point We can request a list of the available access points against which we can attempt to connect We do this using the wifi station scan function This function takes a callback function pointer as one of its parameters This callback will be invoked when the scan has completed The callback is necessary because it can take some time a few seconds for the scan to be performed and we can t afford to block operation until complete The scan callback function receives a linked list of BSS structures Contained within a BSS structure are The SSID for the network The BSSID for the access point e The channel The signal strength e others For example LOCAL void scanCB void arg STATUS status struct bss_ info bssInfo bssInfo struct bss info arg skip the first in the chain it is invalid bssInfo STAILQ NEXT bssInfo next while bssInfo NULL os printf ssid s n bssInfo ssid bssInfo STAILO NEXT bssInfo next LT utis Page 66 Ensure we are in station mode wifi set opmode current STATION Request a scan of the network calling scanCB on completion wifi station scan NULL scanCB Note the use of the sTA1LO NEXT macro to navigate to the next entry in the list The end of the list is indicated when this returns NULL See also Sample WiFi Scanner wifi station scan wifi set opmode struct bss info STATUS Defining the operating mode The ESP82
161. pt 5 eei bue EP rien e omo eire 169 espcontn clear Opt 2a a eee ete bike ar diee eve evade ee ade eles ovt des ep ee aya aede 170 CSPCONN TEGISE TIME A etre ee tovt oa ad Pr Lodo Pe Ea der toute Re 170 espconn set keepalive ssessssssssssssseeeneneneee nennen ne ene n nnns enne nnns 171 espconn_get_keepalive oooooooinnnnccccccnccccccccccononocnnnnncnnnccnnnnnnnnnnnnonnnnnnnnnnnncnnnnnnnrnrnnnaness 171 espcornn Secure accept annen duende ja nen RR ek A RR RR aree HERR RB res ener AE Rn enun 171 espconn secure Set SiZe oncccccccooncccnncconnoncnnnnononannnnnnnonnnnnnnnonononnnnnnnnnnnonnnnnnnnnnnnnnnnnncnns 171 ESPCONN_SECUPE_Get_SIZE ececeecccecccececceececeaeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaeaaaaeeeeesaaeeeeesaneeees 171 espconn SECUFE_CONMECL ccccsecccceseecceeeccceueecceecesseuseeceuscecsegseessueceesuaeeessueceeesaeenees 171 ESPCONN Secure adicta 171 espconn Secure disconnect edet Hor dere seed em aaeeea eraat 171 espconn tcp get Max COM ced eee eee me x i Heo eet Er A 171 espconn tcp set max COn sssssesssssssseeeee nennen nnn nenne nnn ssn sns sura se sn a nsa ssa nnns 172 espconn tcp _get_Max_cCon_allOW oooooonccccnccccccncccccccccnonononnnnnnnnnnnnnnnnnnnnnnnnnnnnnnncnnnonanenos 172 espconn_tcp_set_Max_COn_allOW ooocccnnccccconnnnnncccnonncnnnnonnnnnnnnnnnononncnnnnnonnnonannnns 172 espcorin recv hold rete e ee e rib ias 172 espconn_recv_ UMO d ooocc
162. quent normal starts 010 2 Jump start ou 3 Boot from flash 100 4 SDIO low speed V2 101 5 SDIO high speed V1 110 6 SDIO low speed V1 111 7 SDIO high speed V2 From a practical perspective what this means is that if we wish the device to run normally we want to boot from flash with the pins having values 011 while when we wish to flash the device with a new program we want to supply 001 to boot from UARTO Note that MTDO is also known as GPIO15 The ESP8266 SDK Include directories The C programming language uses a text based pre processor to include test in the compilation units This is commonly called CPP CPP has the ability to include addition C source files that by convention are called header files and end with the h prefix Within these files we commonly find definitions of data types and function prototypes that are used during compilation The ESP8266 SDK provides a directory called include which contains the include files supplied by Espressif for use with the ESP8266 The list of header files that we may use are as described in the following table File Notes at_custom h Definitions for custom extensions to the AT command handler c_types h C language definitions eagle soc h Low level definitions and macros Heavily related to bit twiddling at the CPU level No idea why the file is called eagle espconn h TCP and UDP definitions espnow h Functi
163. r incoming HTTP requests we can convert a current request into a socket connection between the server and the browser such that either end can send data to be received by its partner Programming using Eclipse Eclipse is a popular open source framework primarily used for hosting application development tools Although primarily geared for building Java applications it also has first class C and C support A project for building ESP8266 applications using Eclipse can be found here http www esp8266 com viewtopic php f 9 amp t 820 Do not include spaces in any of the path parts pointing to the workspace Here are some notes on installing this project however always read the documentation accompanying the project Download the Espressif ESP8266 DevKit vxxx x86 This is a large download of approx 125MBytes Run the installer It will ask you for your choice of installation language Select Setup Language S cd to use during the English z Next comes the splash screen Page 103 Welcome to the Unofficial Development Kit for Espressif ESP8266 Setup Wizard Now on your PC will be installed Unofficial Development Kit for Espressif ESP8266 The DevKit includes a unofficial compiler for SoC Xtensa LX106 and ESP8266 SDK v1 2 0 utilities and examples of writing firmware Click Next to continue or Cancel to exit Setup License Agreement Please read the following importan
164. rite Page 129 Sample applications Reading and reviewing sample applications is good practice It allows you to study what others have written and see if you can understand each of the statements and the program flow as a whole Sample Light an LED based on the arrival of a UDP datagram In this sample we will have the ESP8266 become a WiFi station and connect It will start to listen for incoming datagrams and if the first byte of received data is the character 1 it will light an LED If the character is 0 it will extinguish the LED Here is the full code of the application with commentary following include ets sys h include osapi h include os type h include gpio h include user interface h include espconn h include lt mem h gt include driver uart h define LED GPIO 15 jOCAL struct espconn connl OCAL esp udp udpl OCAL void recvCB void arg char pData unsigned short len OCAL void eventCB System Event t event jOCAL void setupUDP jOCAL void initDone jOCAL void recvCB void arg char pData unsigned short len struct espconn pEspConn struct espconn arg os printf Received data length d n len if len pData 0 0 amp amp pData 0 1 return int v pData 0 1 H GPIO OUTPUT SET End of recvCB ED GPIO v LOCAL void initDone wifi se
165. roviding a C language editor plus tools to compile and deploy the Arduino IDE provides pre supplied libraries of C routines that hide complex implementation details that might be needed when programming to the Arduino boards For example UART programming would undoubtedly have to set registers handle interrupts and more Instead of making the poor users have to learn these technical APIs the Arduino folks provided high level libraries that could be called from the sketches with cleaner interfaces which hide the mechanical gorp that happens under the covers This notion is key as these libraries as much as anything else provide the environment for Arduino programmers Interesting as this story may be you may be asking how this relates to our ESP8266 story Well a bunch of talented individuals have built out an Open Source project on Github that provides a plugin or extension to the Arduino IDE tool remember that the Arduino IDE is itself free What this extension does is allow one to write sketches in the Arduino IDE that leverage the Arduino library interfaces which at compile and deployment time generate code that will run on the ESP8266 What this effectively means is that we can use the Arduino IDE and build ESP8266 applications with the minimum of fuss Implications of Arduino IDE support The ESP8266 is still new as of July 2015 and no one knows where this little chip will be in a year or five years time Will it become the
166. rsiOn cseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaeeaaceseeeeeeeeeeeeeeeesaaeeesesaneeees 133 SYSTEM SOM WAL SLOP TR 134 syst m SOM Wat TOS Adi ec ace eee ieee Aas A eeu des 134 OS MEMS Et M code eee A A Gee Bee ede Re Se Ge 134 OS MOMO Putin ati scares a A A eel ened deta Sates 134 OS MEMCPY ad 135 erm 135 OS e EE A eere evade doe atcha be ee are re ENS 135 CLITA HE NI KETTE Md EM 135 OS PZETO viveveectace 136 E EA MES 136 OS Puan 136 os install Putin is eee eee Reed ee ee ts 137 OS TU E 137 OSA MO Mii da 137 OS SITlen itte dt 137 OS SlrCat i edet fete eU ee Sesh eoa ee guam eint ee ge d PORE ER ERN Oe ares 138 ferreae SEE MM ME 138 A AVETE TD T E 138 owes MEE 138 MEET 139 OS SINC sees o eig aes dore ote ded tu D te Dre od ve ee usce etu ore ada 139 emis LP n 139 A S oe oed ese t e eee ete tiec iu soe ee rode etes E tna 139 Page 5 SFr PIAS ice Sots EN A 139 SPU flash Get o E 139 Spl flash erase sector eco at catidenel ca ceed exp dae ein nea t Fe De Fede PUENTE 140 ISI I A UE M 140 spi flash read ioco tt emo Free toe eve Cre to mentre pese prede Gere nel 140 Spl flash set read UNC cerco eet eene ent E metet pace de ees bri a Des 140 system param save With_protect oooconccnnnnccccccnocoooooonannconccnnnnnnnnnnnnnnnnnnnnnnnnanancnnnnnnnnnns 140 system param lO ccoo EROR HER e Ee XR E VV XXE KEIN M PEE RE S SYRRE OY TER
167. rver char numdns ip addr t dnsservers The numdns is the number of DNS servers supplied which must be 1 or 2 No more than 2 DNS servers may be supplied This function should not be called if DHCP is being used The dnsservers parameter is an array of or 2 IP addresses See also Name Service espconn_gethostbyname err t espconn gethostbyname struct espconn espconn const char hostname ip addr t addr dns found callback found Page 177 The parameters are e espconn hostname e addr found The dns found callback is a function with the following signature void functionName const char name ip addr t ipAddr void arg where the arg parameter is a pointer to a struct espconn Return code of 0 on success otherwise the code indicates the error ESPCONN OK Succeeded ESPCONN INPROGRESS already connected ESPCONN ARG Illegal argument espconn port uint32 espconn port espconn regist sentcb Register a callback function that will be called when data has been sent sint8 espconn regist sentcb struct espconn espconn espconn sent callback sent cb The format of the callback function is void functionName void arg The arg parameter is a pointer to a struct espconn that describes the connection See also Sending and receiving TCP data struct espconn espconn_regist_recvcb Register a function to be called when data becomes available on the TCP connection or
168. s streamed to the ESP8266 There is no concept of a unit of data transmission Instead data sent in the pipe at the sender will arrive at the ESP8266 but it may very well arrive at different rates The order of the transmitted data is preserved obviously In principle making two transmissions at the sender of 5 bytes each could result in one receive at the ESP8266 of 10 bytes Don t make any assumptions about the bracketing of TCP data To transmit data to a partner we use the function called espconn_sent Note Espressif is a Chinese company based out of Shanghai My knowledge of the Chinese language is nill I only speak one language English and even that poorly and I am in awe of those who can juggle more than one However we are all human and we all have the opportunity to make mistakes Take for example the command espconn_sent When called its purpose is to send data If you are a native English speaker it is likely to be obvious the difference in meaning between sent and send however spare a thought for those whose native language is not English and also whose character set is not the Latin set you are reading now There are a few places in the ESP8266 API documentation where there are items that either read oddly in English or are plain wrong from an English grammar perspective What you should do if you find one of these is check the bug log at the Espressif BBS and if not already reported be a good citizen a
169. s Manager URLs field enter the URL for the ESP8266 package which 1S http arduino esp8266 com package esp8266com index json Page 116 Sketchbook location C Users IBM_ADMIN Documents Arduino Editor language System Default requires restart of Arduino Editor font size 14 Show verbose output during compilation upload Compiler warnings Display line numbers Enable Code Folding Verify code after upload Use external editor Y Check for updates on startup V Update sketch files to new extension on save pde gt ino V Save when verifying or uploading Additional Boards Manager URLs http arduino esp8266 com package esp8266com index json More preferences can be edited directly in the file C Users IBM_ADMIN AppData Roaming Arduino15 preferences txt edit only when Arduino is not running Select the Boards Manager from the Tools gt Board menu Page 117 sketch jul12a Arduino 1 6 5 o ms File Edit Sketch Help Auto Format Ctrl T i Archive Sketch sketch jul12a j 3 Fix Encoding amp Reload l void setup Serial Monitor Ctrl Shift M 2 put ya Board Arduino Pro or Pro Mini i Boards Manager Processor ATmega328 5V 16 MHz Arduino AVR Boards 6 void loop Port COM11 r Arduino Y n Pat Y Programmer AVR ISP AUN anio a Arduino Duemilanove or Diecimila 9 Burn Bootloader Arduino Nano Arduino Mega or Me
170. s are e GPIO PIN INTR LOLEVEL GPIO PIN INTR HILEVEL Includes e gpio h See also GPIOs Page 194 gpio_pin_wakeup_disable void gpio pin wakeup disable GPIO_INT_TYPE Includes gpio h UART APIs These functions have to be compiled in from the uart files in driver_lib uart_init void uart init UartBautRate uart0BaudRate UartBautRate uartlBaudRate There appears to be a typo in the data type but likely we will be stuck with that now The UartBautRate is an enum that contains BIT RATE 9600 BIT RATE 19200 BIT RATE 38400 BIT RATE 57600 BIT RATE 74880 BIT RATE 115200 BIT RATE 230400 BIT RATE 460800 BIT RATE 921600 See also Working with serial uartO tx buffer Transmit a buffer of data via UARTO void uart0 tx buffer uint8 buffer uintl16 length Transmit the data pointed to by the buffer for the given length See also Working with serial Page 195 uartO rx intr handler Handle the receiving of data via UARTO void uart0 rx intr handler void parameter The parameter is a pointer to a RcvMsgBuff structure My best guess on how to use this function is to create itin user main c and its mere existence will cause it to be invoked at the appropriate time See also Working with serial I2C Master APIs These functions have to be compiled in from the i2c master files in driver lib i2c master gpio init void i2c master gpio init i2c master init void i2c master init
171. s called when a ping request is sent See also ping start ping regist recv ping regist sent struct ping option Name Service On the Internet server machines can be located by their Domain Name Service DNS names This is the service that resolves a human readable representation such as google com into the necessary IP address value eg 216 58 217 206 In order for this transformation to happen the ESP8266 needs to know the IP address of one or more DNS servers that it will then use to perform the name to IP address mapping If we are using DHCP then nothing else need be done as the DHCP server automatically provides the DNS server addresses However if we should not be using DHCP then we need to instruct the ESP8266 of the locations of the DNS servers manually We can do this using the espconn dns setserver function This takes an array of one or two IP addresses as input and from that point onwards these servers will be used for DNS resolution If two addresses are supplied and the first is unresponsive the second will be used Google publicly makes available two name servers with the addresses of 8 8 8 8 and 8 8 4 4 See also espconn dns setserver espconn gethostbyname Wikipedia Domain Name System Google Public DNS Page 84 Multicast Domain Name Systems Using the Multicast Domain Name System mDNS an ESP8266 can attempt to resolve a hostname of a machine on the local network to its IP address It does this by
172. s control over the execution at the time when the request arrives that request will not be responded to until after you return control back to the OS Meanwhile the access point may be expecting a response within some predetermined time period and if does not receive a reply within that interval may assume that you have disconnected This means that your application code has to return control back to the OS in a timely manner It is recommended that your code return control within 50 milliseconds of gaining control If you take longer you run the risk of requests to your device timing out If your own code fails to return control back to the OS the OS must assume that things are going wrong As such it has a timer that we call the watchdog When control is given to your own code the watchdog timer starts ticking If you have not returned control back to the OS by the time the watchdog timer reaches zero it takes matters into its own hands Explicitly what it does is reboot the device This may sound like a pretty drastic action but the thinking is that it is better to do this and hope that whatever was blocked is now unblocked than just sit there dead Reports claim that the watchdog timer may be about 1 second 1000 milliseconds However in my tests I find that the timer fires at about 3 2 seconds 3200 msecs A function called system soft wdt stop stops the watchdog timer or at least one of them There appears to be two timers O
173. se ek a abes Que ta Ce edel et sa EEEE EEEn 69 Current IP Address netmask and gateWaY ooooooococococcccccccccccccccncnnnnnanann nono nn nnnnnnnnnonnnannnnnns 69 WiFi Protected Setup WPS ccc cece cece cece nceeeeeeeeeeeeeeeeeeeeeeeeeeeeeaaaaaaeaeeadeceeseseeeeeesaeeeeees 70 WOMAN tl de HE 70 The ESPOoOnmarcnit amp lupe enden btstot dem oleh dla chides posee epit bedae ste epe lat sedie Da secs 71 WT Gs Psa mosaic ed was Be sacks cate SUME DM d LU ML CM ted ae aca heu ede tcd 72 Sending and receiving TCP Gates sox vans cinc dai 75 TOP Error handing aae etc id D Lads 77 Blu VM E 78 Broadcast with DP ere 80 b upEe puMe c 81 Multicast Domain Name Systems ssssssssssssssss eene meme eee 81 NVOKIPIE Wi S BNET TOR EEE TEATA c auteni dd ME cun ndi D ha x ee cert 81 POS mE 82 Working WIKI SEA s vores Sank a a on diste iio 89 EE Suelo eet rr em 89 LE poi e E 90 Working witiWiletfioby occ ceso A cgo eu teda educ a dee mee epe de ale 91 Pulse Width Modulation PWI cocinar coria ce 92 Analog to digital GOTWerslor cue acea ec hee e aea raed Reka aed 93 Watchdog time tie eb A eee eed 95 Mapping from Arduino ceceeeeeeeeeeeeeeeeeecaaaaeeaeeeaeceeeeeeeeeeeeeeeeeeaeaaaeaaeeeeeeeseneeeesaeneeesea 96 Partner HORAE APISS a oracio tut cd us T Ces dd 97 Jaya Sockets MC C T E RCM 97 PROGFaMMING using ECIDSe censal dalt dos etnicid
174. sheet v0 3 OD ESP8266 Pin List Release 2014 11 15 2A ESP8266 IOT SDK User Manual Supplied with SDK 2B ESP8266 SDK IOT Demo Supplied with SDK 2C ESP8266 SDK Programming Guide Supplied with SDK 4A ESP8266 AT Instruction Set Supplied with SDK gt 4B ESP8266 AT Command Examples Supplied with SDK gt 4C ESP8266 AT upgrade example 8A ESP8266 Interface GPIO Not yet published 8B ESP8266 Interface GPIO Registers Release 2014 11 15 8C ESP8266 Interface 12C Not yet published Page 217 8D ESP8266 Interface PWM v1 1 8E ESP8266 Interface UART v0 2 8F ESP8266 Interface UART Registers v0 1 8G ESP8266 Interface Infrared Remote Control v0 3 gt 8H ESP8266 Interface SDIO SPI Mode Not yet published gt 8l ESP8266 Interface SPI WiFi Passthrough 1 interrupt mode Not yet published 8J ESP8266 Interface SPI WiFi Passthrough 2 interrupt mode Not yet published 8K ESP8266 Sniffer Introduction v0 3 8L ESP8266 Interface SPI Registers Release 2014 11 18 8M ESP8266 Interface Timer Registers Release 2014 11 18 8N ESP8266 SPI Reference v1 0 gt 80 ESP8266 SPI Overlap 8 Display Application Guide Not yet published 8Q ESP8266 HSPI Host Multi device API v1 0 gt 9A ESP8266 FRC Timer Introduction not yet published 9B ESP8266 Sleep Function Description v1 0 20A ESP8266 RTOS SDK Programming Guide V1 0 3 99A ESP8266 Flash RW Operation v0 2 gt 99B ESP8266 Timer
175. sk of 255 255 255 0 and our network is 192 168 1 x then transmitting on the IP address 192 168 1 255 will be a broadcast A special IP address of 255 255 255 255 represents a broadcast on our local network For the ESP8266 there is an API called wifi set broadcast if which determines which interfaces will be available for broadcast The choices are the station the access point or both the station and access point A corresponding API called wifi get broadtcast if can be used to retrieve the current broadcast configuration state See also wifi_set_broadcast_if wifi_get_broadcast_if Page 83 Ping request At the TCP IP level a device with an IP address can ping another device with an IP address What this means is that messages are transmitted between them that allows them to know that they have a route through the network to each other If the destination is either not running or no route is available we will also be informed that there was a failure The ESP8266 provides a structure called struct ping option that contains the details of a ping request This is passed in as a parameter to the function called ping start which initiates the ping Before calling this function the target IP address and the number of ping requests should be set within the struct ping option Two callback functions can be registered with ping regist recv and ping regist sent The first is called when a ping response is received and the other i
176. so wifi softap dhcps start wifi softap dhcps stop wifi softap set dhcps lease wifi softap dhcps status Current IP Address netmask and gateway Should we need it we can query the OS environment for the current IP address netmask and gateway The values of these are commonly set for us by a DHCP server when we connect to an access point The function called wifi get ip info returns our current information while the function called wifi set ip info allows us to set our addresses Page 72 When we connect to an access point and have chosen to use DHCP when we are allocated an IP address an event is generated that can be used as an indication that we now have a valid IP address To correctly setup static IP addresses in the init done callback call wifi station dhcpc stop to disable the DHCP client running in the ESP8266 After this call wifi station connect to start the access point connection phase When the event arrives that indicates we are connected to an access point as a station EVENT STAMODE CONNECTED we can call wifi set ip info and pass in the IP address gateway and netmask that we wish to use Note that when we use a static IP address we will not receive the callback event that indicates we have received an IP address EVENT STAMODE GOT IP as we already have it See also Handling WiFi events wifi get ip info wifi set ip info wifi station dhcpc stop struct ip
177. spressif the makers of the ESP8266 but even that is quite light on examples and background As I studied the device I started to make notes and my pages of notes continued to grow and grow This book if we want to call it that is my collated and polished version of those notes Rather than keep them to myself I offer them to all of us in the ESP8266 community in the hope that they will be of some value My plan is to continue to update this work as we all learn more and share what we find in the community forums As such I will re release the work at regular intervals As you read make sure that you fully understand that there are undoubtedly inaccuracies errors in my understanding and errors in my writing Only by feedback and time will we be able to correct those Please forgive the grammatical errors and spelling mistakes that my spell checker hasn t caught Please don t email me directly with technical questions Instead let us use the forum and ask and answer the questions as a great community of ESP8266 minded enthusiasts hobbyists and professionals Neil Kolbam Texas ASA Page 12 Overview A microprocessor is an integrated circuit that is capable of running programs There are many instances of those on the market today from a variety of manufacturers The prices of these microprocessors keeps falling In the hobbyist market an open source architecture called Arduino that uses the Atmel range of process
178. sssseeeeeneennene nennen nennen enne na 147 Wifi_Station_CONMMECE cccccccceccc cece eee e eee eaeeeeeeeeeeeeeeeeeeeeeeeeeaeaaaaaaeaeeeesseaeeeesaeneeeesnneeeees 147 Wifi Station disconnect erit tne eb penati ruri eee ep rai b e e eoe Ee Pea E PR aenea Ta 147 wifi_station_get_Connect_Status ccccecceeccceee cece ceaeeeeeeeeeeeeeeeeeeeeeeeeeesaaeeeeseeeeeseae 148 Wifi STATION SCAN iia eio a Cedo aee oe km EE E e AE OEE setae 148 wifi station ap number set nnn nen nn nnn rennen nnns 149 Wifi Station get ap IMO si iot eere nea cubes ier e aeree duty vara UV Ra Erreur dad 150 ME IS antn nenE Enen En Eeen nnee 150 wifi station current ap iooooooiicccccccnncccccccnnnonononnnnnnnnncnnncnnnnnnnnnnnnnnnnnnnnnnnnrnnnnnnnannnnnmannnnns 150 wifi_station_get_AUtO_CONMECE cece ccccee eee e cece eee ea ae eee eeeeeeeeeeeeeeeeeeeeeeeeeaaaaeaeeeeeeeeeeseaes 150 wifi station set auto _CONNECt ococcccccccccccccccnnnnnnnncncnncnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnncnnnrnnnnns 151 ME IM RO 151 wifi Station dhicpc stop dere he ad did aia 151 Wifi station dhcpc status ice ee tee reden ERE TREINTA 152 wifi_station_set_reconnect_poliCy oooooooonoccconnnnncccnononnnnnnnnnononnnnnnnnnnncnnnnnnnnnnnnnnnnnnnnnnns 152 WITL Station JE A it 152 wifi_station_sSet_hOStNaMe oooooooooccncccnnnnnnnnnccncnnnnonnnnnnnnnncnnnnnnnnnnnnnnnnnnnnnnnnnnnnnarrnnnnnnnininnns 152 Page 6 wifi station get hostname ssssssssss
179. sssseeeeseeee nnnm enn enhn nnn nennen nnne nn 152 Wifi softap get conflg ici ae te P e ed e ae Ede eg b eon d ee ee T d ERES 153 wifi softap get config default nnnm nne 153 Wifi s ftap Set CONTIG vcs heic cse ear ido ad ea ud 153 wifi softap set config current nennen nennen nnne 154 wifi softap get station num sssssssssssssseeeneeeneerr III nenne enne ener nennen 154 wifi softap get station info nnn nennen nennen nna 154 wifi softap free StatiON_IMfO o oooocooooooocooocconoccnnnnnnnnonnnnnnnnnonnnnnnnnnncnncnnnnnnnnnnnnnnnnnnnnennnns 155 E MAA enne nenne enne Ee 155 ME MS 155 wifi softap set dhcps lease oooooooooooconoccnccccnccnnnnnnnccnnnonononnnnnncnnnnnnnnnnnnnnnnnnnnnnnnnnnnnanennnns 156 Wifi softap dhcps status iier rit eri er eco ek lee e eerie e igi o rait 156 wifi_softap_dhcps_offer_OPtiON oooococcccncnnocooncconnncccnonnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnns 157 WITLESOU POMO iii A iren AA ca a EA 157 Wifi get DAY mode ioni dro dd A td 157 wifi WPS ale iii ias 157 Wifi WPS disable iere etr a ere Y EX DER ais 158 VATIC NEIN cc LEE EET LM 158 Wifi Set WS CDs aici de cccvccncecenccsbeseuut d add 158 Uparade APIS a6 A etate E ist boa utto E 158 system upgrade _Userbin_CNECK ccccccccceeeceeeeceeeeaaaeeeeeeeeeeeeeeeeeeeeaaeeeeesseneesesaeeeeees 158 system upgrade flag set nnne nennen nennen nnns 159 system_upgrade_flag_Check oooooooooonnnnncncnccnnnnccc
180. station_get_config Get the current station configuration bool wifi station get config struct station config config Retrieve the current station configuration settings Includes user interface h See also Station configuration station_config Page 159 wifi_station_get_config_default Get the default station configuration Includes user interface h See also Station configuration wifi_station_set_config Set the configuration of the station bool wifi station set config struct station config config This function can only be called when the device mode includes Station support Specifically the details of which access point to interact with are supplied here The details are persisted across a restart of the device A return value of true indicates success and a value of false indicates failure Includes user interface h See also Station configuration station_config wifi_station_set_config_current Set the configuration of the station but don t save to flash bool wifi station set config current struct station config config This function can only be called when the device mode includes Station support Specifically the details of which access point to interact with are supplied here The details are not persisted across a restart of the device A return value of true indicates success and a value of false indicates failure Includes user interface h See also Station confi
181. strongly suggest not doing it Some folks may claim you can get away with it and if you experiment it may seem to work but you are taking an unnecessary risk for no obviously good reason If it works then it will work till it doesn t at which point it will be too late and you may cook your device In my own experiments I have accidentally over powered ESP8266s reverse voltage powered ESP8266s and applied too high a voltage as input In each case the result was a dead chip and in a few cases attempting to see if it still worked by applying normal voltage resulted in the device not only not working but getting so hot to the touch it burned my fingers Because accidents happen when building GPIO based circuits I recommend buying more ESP8266 instances than you need That way if you do happen to find yourself needing a second or third or fourth you will have them at your disposal The way that the ESP8266 thinks of GPIOs is as though each GPIO was a bit in a 16bit array 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 We will come back to how 17 GPIOs maps to 16 bits at a later time One array contains an indication of whether or not the GPIO is input or output We will call this the direction array A second array indicates the values of the GPIOs For input GPIOs the value is the value on the pin For output GPIOs the value is the value to be written to the pin We will call this the value array A function is supplied by the ESP
182. support would have RAM and flash memory but would have the killer new feature that it would also be able to form Internet connections And that simply put is what the ESP8266 device is It is an alternative microprocessor to the ones already mentioned but also has WiFi and TCP IP Transmission Control Protocol Internet Protocol support already built in What is more it is also not much more expensive than an Arduino Searching ebay we find ESP8266 boards under 3 The ESP8266 The ESP8266 is the name of a microprocessor designed by Espressif Systems Espressif is a Chinese company based out of Shanghai The ESP8266 advertises itself as a self contained WiFi networking solution offering itself as a bridge from existing microprocessors to WiFi and is also capable of running self contained applications Volume production of the ESP8266 didn t start until the beginning of 2014 which means that in the scheme of things this is a brand new entry in the line up of processors And in our technology hungry world new commonly equates to interesting A couple of years after IC production 3 party OEMs are taking these chips and building breakout boards for them If I were to hand you a raw ESP8266 straight from the factory it is unlikely we would know what to do with one They are very tiny and virtually impossible for hobbyists to attach wires to allow them to be plugged into breadboards Thankfully these OEMs bulk purchase the I
183. t 4 Soft restart 5 Deep sleep wake up See also struct Exception handling System get rst info espconn This data structure is the representation of a connection between the ESP8266 and a partner It contains the control blocks and identification information however it is important to note that it is not always an opaque piece of data Page 204 enum espconn type type The type can be one of ESPCONN TCP Identifies this connection as being of type TCP ESPCONN UDP Identifies this connection as being of type UDP enum espconn state The state can be one of o ESPCONN NONE o ESPCONN WAIT o ESPCONN LISTEN o ESPCONN CONNECT o ESPCONN WRITE o ESPCONN READ o ESPCONN CLOSE union esp tcp tcp esp udp udp proto This field is a union of tcp and udp meaning that only one of them should ever be used for an instance of this data structure If the data structure is used for TCP then the tcp property should be used while for UDP the udp property should be used void reverse In the comments this is flagged as a field reserved for user code It is possible the name chosen reverse is actually a typo in the header file e Other fields there are other fields in the structure but they are not meant to be read or written to by user applications Ignore them Using their values is undefined and may have unexpected effects See also TCP esp_tcp esp_udp esp_tcp
184. t information before continuing Please read the following License Agreement You must accept the terms of this agreement before continuing with the installation GNU GCC G License GNU GENERAL PUBLIC LICENSE Version 3 29 June 2007 Copyright C 2007 Free Software Foundation Inc lt http fsf org gt Everyone is permitted to copy and distribute verbatim copies of this license document but changing it is not allowed Preamble 5 1 do not accept the agreement Now the selection of which components to install Page 104 Select Components Which components should be installed Select the components you want to install clear the components you do not want to install Click Next when you are ready to continue V GCC Xtensa LX106 529 1 MB v Espressif SDK 12 2 MB Y Documentation 12 4 MB Y Utilites 8 5 MB Y Examples 19 5 MB Current selection requires at least 583 1 MB of disk space Finally a confirmation dialog to review what you have selected Setup is now ready to begin installing Unofficial Development Kit for Espressif ESP8266 on your computer Click Install to continue with the installation or click Back if you want to review or change any settings Destination location MEM E C Espressif Setup type Full installation Compiler SDK utils docs and examples Selected components GCC Xtensa L
185. t opmode current STATION MODE struct station config stationConfig strncpy stationConfig ssid myssid 32 strncpy stationConfig password password 64 wifi station set config amp stationConfig wifi station connect End of initDone LOCAL void setupUDP Page 130 connl type ESPCONN UDP connl state ESPCONN NONE udpl local port 25867 connl proto udp amp udpl M espconn create amp connl espconn regist recvcb amp connl recvCB os printf Listening for data n End of setupUDP LOCAL void eventCB System Event t event switch event event case EVENT STAMODE GOT IP os printf IP d d d sd n IP2STR amp event event info got ip ip SetupUDP break End of eventCB void user rf pre init void void user init void uart init BIT RATE 115200 BIT RATE 115200 Set GPIO15 as a GPIO pin PIN FUNC SELECT PERIPHS IO MUX MTDO U FUNC GPIO15 Call initDone when the ESP8266 has initialized system init done cb initDone wifi set event handler cb eventCB End of user init Control starts in the user init function where we setup the UART baud In this example we have chosen GPIO15 as our output pin so we map the function of the physical pin called MTDO_U to the logical function of GPIO15 We register a function called initDone to be called when initialization of the device
186. t policy bool set Includes user interface h wifi station get rssi Get the received signal strength indication rssi sint8 wifi station get rssi Includes user interface h wifi station set hostname bool wifi station set hostname char name Includes user interface h wifi station get hostname char wifi station get hostname Includes user interface h wifi softap get config Retrieve the current softAP configuration details bool wifi softap get config struct softap config pConfig When called the struct softap config pointed to be pconfig will be filled in with the details of the current softAP configuration The details returned are those actually in use and may differ from the ones saved for default Page 166 A value of 1 will be returned on success and O otherwise Includes user interface h See also struct softap_config wifi_softap_get_config_default wifi_softap_set_config wifi_softap_set_config_current wifi_softap_get_config_default Retrieve the default softAP configuration details bool wifi softap get config default struct softap config config When called the struct softap config pointed to be pconfig will be filled in with the details of the default softAP configuration The details returned are those used at boot and may be different from the ones currently in use A value of 1 will be returned on success and O otherwise Includes user interface h
187. tartup uint32 system get time This timer will roll over after 71 minutes Includes e lt Include missing for this function See also Timers and time Page 144 system_get_rtc_time Get the real time clock time system_rtc_clock_cali_proc Clock calibration system_rtc_mem_write Storage space for saving data during a deep sleep in RTC storage system_rtc_mem_read Read data from RTC available storage system_uart_swap Swap serial UARTs system_uart_de_swap Go back to original UART system_get_boot_version The version of the boot loader uint8 system get boot version The current value returned through testing of my devices is 5 system_get_userbin_addr Get the address of user bin uint32 system get userbin addr The current value returned on my devices is 0x0 system get boot mode Get the current boot mode uint8 system get boot mode The return value indicates the current boot mode and will be one of Page 145 e SYS BOOT ENHANCE MODE 0 e SYS BOOT NORMAL MODE 1 On my devices the value being returned is 0 system_restart_enhance Restarts the system in enhanced boot mode system_update_cpu_freq Set the CPU frequency system_get_cpu_freq Get the current CPU frequency int system get cpu freq Returns the CPU frequency in MHz For example 80 system get flash size map Get current flash size and map enum flash size map system get flash size
188. ter to a struct ip info that contains the values we wish to set Includes user interface h See also Current IP Address netmask and gateway struct ip_info wifi_set_macaddr Set the MAC address bool wifi set macaddr uint8 if index uint8 macaddr A MAC address is 6 bytes Includes user interface h wifi get macaddr Get the MAC address bool wifi get macaddr uint8 if index uint8 macaddr A MAC address is 6 bytes Includes user interface h wifi set sleep type Includes user interface h wifi get sleep type Includes user interface h wifi status led install Associate a GPIO pin with the WiFi status LED Page 158 void wifi status led install uint8 gpio id uint32 mux name uint8 gpio func When WiFi traffic flows we may wish a status LED to flicker or blink indicating flowing traffic This function allows us to specify a GPIO that should be pulsed to indicate WiFi traffic The gpio id parameter is the numeric pin number The mux_name is the name of the multiplexer logical name The gpio func is the function to be enabled for that multiplexer Includes user interface h See also wifi_status_led_uninstall wifi_status_led_uninstall Disassociate a status LED from a GPIO pin void wifi status led uninstall Disassociates a previous association setup with a call to wifi status led install Includes user interface h See also wifi_status_led_install wifi_
189. that if it appears again we will once more list it to the user To illustrate our design we will break the solution into a number of parts The first part will be to register a callback function that is called every 30 seconds This callback will be responsible for requesting a WiFi scan using wifi station scan This takes a callback function which itself will be invoked when the scan is complete When the scan completes we will have a new list of detected networks We will walk this list and for each network detected determine if we have seen it before If we have we will update the last seen time If not we will add it to the list of previously seen networks and log it to the user A second timer callback will run once a minute and will walk the list of previously seen networks If any of them are older than a minute we will remove them See also Scanning for access points Sample Libraries There are times when commonly used functions can be captured and reused over and over This section describes just such a set of functions which have been collected The source for these functions has been placed in Github at location to be provided The functions when compiled are placed in a library called 1ibcommon a This can then be linked within your Makefile so that unresolved references to these functions can be satisfied A header file called common n is all that one needs to add into your own applications Function list
190. that it ends up in your hands as opposed to someone else who may live with you In TCP IP terms the address is the IP address and the name is the port number With a telephone conversation we can exchange as much or as little information as we like Sometimes I talk sometimes you talk but there is no maximum limit on how much information we can exchange in one conversation With a letter however there are only so many pages of paper that will fit in the envelopes I have at my disposal The notion of the mail analogy is how we might choose to think about UDP The acronym stands for User Datagram Protocol and it is the notion of the datagram that is akin to the letter A datagram is an array of bytes that are transmitted from the sender to the receiver as a unit The maximum size of a datagram using UDP is 64K Bytes No connection need be setup between the two parties before data starts to flow However there is a down side The sender of the data will not be made aware of a receiver s failure to retrieve the data With TCP we have handshaking between the two parties that lets the sender know that the data was received and if not can automatically retransmit until it has been received or we decide to give up With UDP and just like a letter when we send a datagram we lose sight of whether or not it actually arrives safely at the destination If we wish to receive incoming datagrams we must register what port number we are interested in r
191. that we have a valid IP address system_init_done_cb initDoneCB eventCB wifi set event handle cb wifi set opmode current wifi_station_set_config wifi station connect MAA D event EVENT STAMODE CONNECTED T event EVENT STAMODE GOT IP T Page 70 Being an access point So far we have only considered the ESP8266 as a WiFi station to an existing access point but it also has the ability to be an access point to other WiFi devices stations including other ESP8266s In order to be an access point we need to define the SSID that that allows other devices to distinguish our network This SSID can be flagged as hidden if we don t wish it to be scanned In addition we will also have to supply the authentication mode that will be used when a station wishes to connects with us This is used to allow authorized stations and disallow non authorized ones Only stations that know our password will be allowed to connect If we are using authentication then we will also have to choose a password that the connecting stations will have to know and supply to successfully connect The first task in being an access point is to flag the ESP8266 as such using the wifi set opmode Of wifi_set_opmode current functions and pass in the flag that requests we be either a dedicate access point or an access point and a station Here is a snippet of code that can be used to setup and ESP8266 as an access point
192. the Arduino IDE This is potentially a game changing story and it too been given its own important chapter See also Programming using Eclipse Programming using the Arduino IDE Compilation tools There are a number of tools that are essential when building C based ESP8266 applications make Make is a compilation engine used to track what has to be compiled in order to build your target application Make is driven by a Makefile Although powerful and simple enough for simple C projects it can get complex pretty quickly If you find yourself studying Makefiles written by others grab the excellent GNU make documentation and study it deeply gcc The open source GNU Compiler Collection includes compilers for C and C If we look carefully at the flags that are supplied for compiling and linking code for the ESP8266 we find the following Compiling e Os Optimize code generation for size e 02 Optimize even more e ggdb Generate debug code that can be used by GDB e std gnu90 Dialect of C supported e Werror Make all warnings errors e Wno address Do not warn about suspicious use of memory addresses e Wpointer arith Warn when pointer arithmetic is attempted that depends on sizeof Wundef Warn when an identifier is found in a if directive that is not a macro e fno inline functions Do not allow functions to be replaced with in line code e mlongcalls Translate direct assembly
193. the connection WiFiClient remotePort Return the remote port being used in an existing connection uintl6 t remotePort Return the remote port being used in an existing connection WiFiClient setLocalPortStart Set the initial port for allocating local ports for connections void setLocalPortStart uintl6 t port Set the initial port for allocating local ports for connections WiFiClient setNoDelay void setNoDelay bool nodelay WiFiClient status uint8 t status WiFiClient stop void stop WiFiClient stopALL Stop all the connections formed by this WiFi client void stopA11 Page 128 WiFiClient write Write data to the partner size t write uint8 t b size t write const uint8 t buf size t size Write data to the partner The first function writes one byte while the second function writes an array of characters WiFiServer WiFiServer Create an instance of a Server listening on the supplied port WiFiServer uintl6 t port Create an instance of a Server listening on the supplied port WiFiServer available Retrieve a WiFiClient object that can be used for communications WiFiClient available byte status WiFiServer begin Start listening for incoming connections void begin Start listening for incoming connections WiFiServer getNoDelay WiFiServer hasClient Return true if we have a client connected bool hasClient WiFiServer setNoDelay WiFiServer status WiFiServer w
194. the device will attempt to auto connect to the last access point on restart A value of 0 means it will not while a non 0 value means it will If called in user_init the setting will be effective immediately If called elsewhere the setting will take effect on next restart Page 164 Includes user interface h See also wifi_station_connect wifi_station_disconnect wifi_station_get_auto_connect wifi_station_dhcpc_start Start the DHCP client bool wifi station dhcpc start If DHCP is enabled then the IP netmask and gateway will be retrieved from the DHCP server while if disabled we will be using static values Includes user interface h See also Current IP Address netmask and gateway wifi_set_ip_info wifi_station_dhcpc_stop wifi_station_dhcpc_stop Stop the DHCP client bool wifi station dhcpc stop If DHCP is enabled then the IP netmask and gateway will be retrieved from the DHCP server while if disabled we will be using static values Includes user interface h See also Current IP Address netmask and gateway wifi_set_ip_info wifi_station_dhcpc_start wifi_station_dhcpc_status Get the DHCP client status enum dhcp status wifi station dhcpc status One of DHCP STOPPED Page 165 DHCP STARTED Includes user interface h wifi station set reconnect policy What should happen when the ESP gets disconnected from the AP bool wifi station set reconnec
195. the timer fires void os timer setfn os timer t pTimer os timer func t pFunction void pArg Define the callback function that will be called when the timer reaches zero The pTimer parameters is a pointer to the timer control structure The pFunction parameters is a pointer to the callback function The pArg parameter is a value that will be passed into the called back function The callback function should have the signature void functionName void pArg The pArg parameter is the value registered with the callback function Includes e Oosapi h See also Timers and time os_timer_arm os_timer_disarm system_timer_reinit Used to set a uSecond timer Page 140 os_timer_arm_us Enable a microsecond timer hw_timer_init Initialize a hardware timer hw_timer_arm Set the trigger delay hw_timer_set_func Set the timer callback System Functions system_restore Reset some system settings to defaults system_restart Restart the system system_init_done_cb Register a function to be called when system initialization is complete void system init done cb init done cb t callbackFunction This function is designed only be called in user init It will register a function to be called one time after the ESP8266 has been initialized The init done cb t defines a function void functionName void See also Custom programs system get chip id Get the id of the chip long system get chip id For e
196. tion_info wifi_softap_get_station_info Return the details of all connected stations struct station info wifi softap get station info The return data is a linked list of struct station info data structures Includes user interface h See also Being an access point wifi_softap_get_station_num wifi_softap_free_station_info Page 168 wifi_softap_free_station_info Release the data associated with a struct station info void wifi softap free station info Following a call to wifi softap get station info we may have data returned to us The data was allocated by the OS and we must return it with this function call Note that this function does not take in the data that was returned Includes user interface h See also Being an access point wifi_softap_get_station_info wifi_softap_dhcps_start Start the DHCP server service bool wifi softap dhcps start Start the DHCP server service inside the device Includes user interface h See also The DHCP server wifi_softap_dhcps_stop wifi_softap_set_dhcps_lease wifi_softap_dhcps_status wifi_softap_dhcps_offer_option wifi_softap_dhcps_stop Stop the DHCP server service bool wifi softap dhcps stop Stop the DHCP server service inside the device Includes user interface h See also The DHCP server wifi_softap_dhcps_start wifi_softap_set_dhcps_lease wifi_softap_dhcps_status wifi_softap_dh
197. together char os strcat char strl char str2 Concatenate the null terminated sting pointed to by str1 with the string pointed to by str2 and store the result at str1 Includes e Oosapi h os strchr Includes e Oosapi h os strcmp Compare two strings int os strcmp char strl char str2 Page 151 Compare the null terminated string pointed to by str1 with the null terminated string pointed to by str2 If str1 str2 then the return is lt 0 If str1 gt str2 then the return is gt 0 otherwise they are equal and the return is 0 Includes e Oosapi h OS strcpy Copy one string to another char os strcpy char dest char src Copy the null terminated string pointed to by src to the memory located at dest Includes e Oosapi h os strncmp Includes e Oosapi h os strncpy Copy one string to another but be sensitive to the amount of memory available in the target buffer char os strncpy char dest char source size t sizeOfDest Understand that the resulting string in dest may not be null terminated Includes e Oosapi h os sprintf sprintf char buffer char format The format is not as rich as normal sprintf ina C library For example no float or double support Includes e Oosapi h Page 152 os_ strstr Includes e osapi h SPI Flash spi_flash_get_id Ge the ID info of SPI flash uint32 spi_flash_get_id void Includes e spi flash h See also spi_fl
198. truct softap config Configuration control structure for softAP uint8 ssid 32 uint8 password 64 uint8 ssid len The length of the SSID If 0 then the ssid is null terminated uint8 channel The channel to be used for communication Values are 1 to 13 uint8 authmode The authentication mode required AUTH_WEP is not supported uint8 ssid hidden Whether or not this SSID is hidden A value of 1 makes it hidden uint8 max connection The maximum number of station connections The maximum and default is 4 uint16 beacon interval The beacon interval in milliseconds Values are 100 60000 See also wifi_softap_get_config wifi_softap_get_config_default wifi_softap_set_config wifi_softap_set_config_current Page 201 struct station_info This structure provides information on the stations connected to an ESP8266 while it is an access point It is a linked list with properties e uint8 bssid 6 The e struct ipaddr ip The IP address of the connected station To get the next entry we can use STAILO NEXT pStationInfo next See also Being an access point wifi_softap_get_station_info wifi_softap_free_station_info struct dhcps_lease This structure is used by the wifi softap dhcps lease function to define the start and end range of available IP addresses The fields contained within are e struct ip_addr start ip e struct ip_addr end ip Includes user interface h See also
199. ts for some of the more common languages Java Sockets The sockets API is the defacto standard API for programming against TCP IP My programming language of choice is Java and it has full support for sockets What this means is that I can write a Java based application that leverages sockets to communication with the ESP8266 I can send and receive data through quite easily In Java there are two primary classes that represents sockets those are java net Socket which represents a client application which will form a connection and the second class is java net ServerSocket which represents a server that is listening on a socket awaiting a client connection Since the ESP8266 can be either a client or a server both of these Java classes will come into play To connect to an ESP8266 running as a server we need to know the IP address of the device and the port number on which it is listening Once we know those we can create an instance of the Java client with Socket clientSocket new Socket ipAddress port This will form a connection to the ESP8266 Now we can ask for both an InputStream from which to receive partner data and an OutputStream to which we can write data InputStream is clientSocket getInputStream OutputStream os clientSocket getOutputStream When we are finished with the connection we should call close to close the Java side of the connection clientSocket close Page 100 It re
200. ully in folder firmware eagle flash bin gt 0x00000 eagle irom0text bin gt 0x40000 Done 17 57 19 Build Finished took 3s 141ms We can build solutions using the pre supplied Makefiles but personally I don t like mystery so here is a recipe for building a solution from scratch 1 Create a new project from File gt New gt C Project 2 Select a Makefile project Page 46 C Project Create C project of selected type Project name Sample Y Use default location Location CAUsers IBM_ADMIN Documents RaspberryPi ESP8266 EclipseDevi l Browse Choose file system default v Project type Toolchains b GNU Autotools Other Toolchain b Executable Cross GCC b Shared Library GNU Autotools Toolchain gt Static Library Microsoft Visual C 4 Makefile project MinGW GCC Empty Project Show project types and toolchains only if they are supported on the platform Co rm n m 7m 3 Add the ESP8266 include directory Page 47 type filter text Paths and Symbols gt Resource Builders gt C C Build Configuration Default Active 4 C C General gt Code Analysis ES B Includes Symbols amp Libraries Library Paths amp Source Location 2 Out File Types Formatter Indexer Languages Include directories Assembly 9 CAEspressiflESP8266 SDKNinclude GNU C Language Mappings Paths and Symbols Pr
201. ur pPereugus sa receipe Page 214 Variables are defined in the form name value We can use the value of a variable with either name or name Another form of definition is name value Here the value is locked to its value at the time of definition and will not be recursively expanded Some variables have well defined meanings Variable Meaning CC C compiler command AR Archiver command LD Linker command OBJCOPY Object copy command OBJDUMP Object dump command We can use the value of a previously defined variable in other variable definitions For example XTENSA TOOLS ROOT c Espressif xtensa 1x106 elf bin Gc S XTENSA TOOLS ROOT xtensa 1x106 elf gcc defines the C compiler as an absolute path based on the value of a previous variable Special expansions are se The name of the target e 5 lt The first prereq Comments are lines that start with an character Wildcards are e x All characters e 2 Onecharacter Aset of characters Make can be invoked recursively using make C lt directoryName gt Imagine we wanted to build a list of source files by naming directories and the list of source files then becomes all the c files in those directories How can we achieve that Page 215 SRC_DIR dirl dir2 SRC foreach sdir SRC_DIR wildcard sdir c OBJ patsubst c BUILD BASE 0 SRC The puzzl
202. ust then include driver uart h To transmit data using UARTO we have the function called uart0 tx buffer which accepts a pointer to data and a length and transmits it See also Connecting to the ESP8266 USB to UART converters uart init uartO tx buffer uartO rx intr handler os printf Task handling Imagine we wish to have a task performed for us asynchronously What we might want to do is post that we wish this to happen and then go on with our business When we are done and have relinquished control back to the OS we assume that the task will eventually start executing This is the function provided by the task functions of the ESP8266 There are two functions of interest to us The first is called system os task sets up a task processor When we wish to post that a task is eligible to start we can use the second function called system os post Which posts a message The task function that we registered will then be invoked at some point after the post request and will be given the parameters supplied in the post The priority identifies the relative priority of two posts that have been issued The one with the highest priority will execute first It is important to note that only three priorities are allowed which are 0 1 and 2 with 0 having the lowest priority It is also important to note that there can only be one handler for each task registrations So if we execute system os task twice using the same priority in
203. ut e elf2image Create an application image from ELF file output OUTPUT o OUTPUT Output filename prefix o flash freq 40m 26m 20m 80m ff 40m 26m 20m 80m SPI Flash frequency flash mode qio qout dio dout fm qio qout dio dout SPI Flash mode O flash size 4m 2m 8m 16m 32m 16m c1 32m c1 32m c2 fs 4m 2m 8m 16m 32m 16m c1 32m c1 32m c2 SPI Flash size in Mbit O entry symbol ENTRY SYMBOL es ENTRY SYMBOL Entry point symbol name default call user start read mac Read MAC address from OTP ROM Here is an example output MAC AP 1 A FE 34 F9 43 22 MAC STA 18 FE 34 F9 43 22 flash id Read SPI flash manufacturer and device ID Here is an example output head 0 total 0 erase size 0 Manufacturer c8 Device 4014 e read flash Read SPI flash content address Start address size Size of region to dump filename Name of binary dump e erase flash Perform Chip Erase on SPI flash See also Flashing the ESP8266 Github themadinventor esptool Page 58 esptool ck Another tool that is also called esptool The naming of these tools being so similar is starting to become uncomfortable e eo filename e es lt section gt filename e ec bo lt filename gt e bm lt qio qout dio dout gt e bz lt 512K 256K 1M 2M 4M 8M 16M 32M gt e bf lt 40 26 20 80 gt e bs section e bc y q
204. ut fortunately we can make adapters for it extremely easily The pin out of the device is as follows Page 19 Function Color Description TX Transmit RX Receive Always used a level converter for incoming data This device is not 5V tolerant CH_PD Chip enable Should be high for normal operation e 0 Disabled e Enabled RST External reset e 0 Reset e 1 Normal GPIO 0 Should be high on boot low for flash update GPIO 2 Should be high on boot VCC 3 3V GND Ground A simple circuit is shown below Note that the TX and RX pins are shown not connected Remember to always use a level converter for the RX pin into the device as it is not 5V tolerant f A here is an alternate circuit Page 20 3 3V U1 ESP8266 FTDI Basic aon P ESP8266 rogrammer WiFi Module 10kQ Here is the circuit on a breadboard that was demonstrated to work just fine Page 21 TX Blue RX Black CH_PD Green RST Yellow GPIOO White GPIO2 Grey VCC Orange GND Purple ee s CES E di e db de VF Page 22 U1 ESP8266 FTDI Basic X Programmer ESP8266 WiFi When we press the reset button it makes sense for that just to be a momentary press Here is a circuit for that Page 23 3 3V 3 3V FTDI Basic X Programmer ESP8266 WiFi Module R2 10kQ
205. uter information Includes user interface h See also wifi softap dhcps start wifi softap dhcps stop wifi softap set dhcps lease wifi softap dhcps status wifi set phy mode Set the physical level WiFi mode bool wifi set phy mode enum phy mode mode This is used to set the IEEE 802 11 network type such a b g n Includes user interface h See also enum phy_mode wifi_get_phy_mode Get the physical level WiFi mode enum phy mode wifi get phys mode This is used to retrieve the IEEE 802 11 network type such a b g n Includes user interface h See also enum phy_mode wifi_wps_enable bool wifi wps enable WPS TYPE t wps type The type parameter can be one of the following WPS TYPE DISABLE Unsupported Page 171 wPS TYPE PBC Push Button Configuration Supported e WPS TYPE PIN Unsupported WPS TYPE DISPLAY Unsupported e WPS TYPE MAX Unsupported See also WiFi Protected Setup WPS wifi wps disable bool wifi wps disable See also WiFi Protected Setup WPS wifi wps start bool wifi wps start See also WiFi Protected Setup WPS wifi set wps cb bool wifi set wps cb wps st cb t callback The signature of the callback function is void functionName int status The status parameter will be one of e WPS CB ST SUCCESS WPS CB ST FAILED e WPS CB ST TIMEOUT See also WiFi Protected Setup WPS
206. we may find that they don t always run as expected Performing debugging on an SOC can be difficult since we have no readily available source level debuggers Page 60 Logging to UART1 We can insert diagnostic statements using os printf This causes the text and data associated with these functions to be written to UARTI If we attach a USB UART device in the circuit we can then look at the data logged In my development environment I always have two USB UART devices in play One to flash new applications and one to use for diagnostic output The OS is also able to write debugging information By default this is on but can be switched off with a call to system set os print See also USB to UART converters Working with serial System set os print Run a Blinky Physically looking at an ESP8266 there isn t much to see that tells you all is working well within it There is a power light and a network transmission active light but that s about it A technique that I recommend is to always have your device perform execute a blinking led which is commonly known as a Blinky This can be achieved by connecting a GPIO pin to a current limiting resistor and then to an LED When the GPIO signal goes high the LED lights When the GPIO signal goes low the LED becomes dark If we define a timer callback that is called for example once a second and toggles the GPIO pin signal value each invocation we will have a simple blinking LE
207. xample 0xf94322 Page 141 system_get_vdd33 Measure voltage Unknown but related to analog to digital conversion See also Analog to digital conversion system_adc_read system_adc_read Read the A D converter value uintl6 system adc read Read the value of the analog to digital converter The granularity is 1024 discrete steps See also Analog to digital conversion system deep sleep Puts the device to sleep for a period of time void system deep sleep uint32 microseconds system deep sleep set option Define what the chip will do when it next wakes up bool system deep sleep set option uint8 option system phys set rfoption Enable the RF after waking up from a sleep or not system phys set max tpw Set the maximum transmission power system phys set tpw via vdd33 Set the transmission power as a function of voltage Page 142 system_set_os_print Turn on or off logging void system set os print unint8 onOff A value of 0 switches it off while a value of 1 switches it on It was initially thought that this controlled OS level logging however it seems to control all logging via os printf Includes user interface h See also Logging to UART1 system_print_meminfo Print memory information void system print meminfo Memory information for diagnostics is written to the output stream which is commonly UARTI The format of the data looks as follows data Ox3ffe8000 Ox3f

Download Pdf Manuals

image

Related Search

Related Contents

MANUAL BMP Layout.cdr  ADUNION - Quimivisa  Klipsch IC-5T IC-6T User's Manual  Haier AE092FCAJA, AE182FCAJA Air Conditioner User Manual  Black Box GigaTrue CAT6, 2-ft.  Zotac ZBOX nano AD10 Plus  LGW 523 MPI - lombardini service  Samsung ATIV NP905S3G  Panas。ni閤 。、 、 取扱説明書  ダウンロード(PDF 2.21MB)  

Copyright © All rights reserved.
Failed to retrieve file