====== Arduiono IDE for ESP8266 ======
===== Basic Arduino functions and classes =====
===== Standard Libs =====
==== Wire ====
content
==== EEPROM ====
EEPROM functionality is similar to the standard Arduino library with the exception of having to declare memory size and committing writes.
===example===
#include
void setup()
{
//Init EEPROM, note the size requirement. I believe 4096B is the maximum available.
//You could use a smaller amount/size.
EEPROM.begin(4096);
for( int i = 0; i < 4096; i++ )
{
EEPROM.write(i,i);
}
EEPROM.commit(); //note here the commit!
}
NOTE: EEPROMAnything can be used with one simple modification.
Find the EEPROMAnything.h and add EEPROM.commit(); after the EEPROM.write(ee++, *p++);
EEPROMAnything provides nice functionality to save any type of variable including structers.
#include
struct eepromInfoType
{
uint8_t MyUnsigned8BitInt;
char MyCharArray[25]
} myStructOriginal, myStructCopy;
void setup()
{
myStructOriginal.MyUnsigned8BitInt = 0; //assign some value
strcpy( myStructOriginal.MyCharArray, "Less than 25 chars" ); //assign some value
EEPROM_writeAnything( 0, myStructOriginal ); //remember to modify EEPROM_writeAnything by adding .commit().
//Lets read it back
EEPROM_readAnything( 0, myStructCopy );
}
void loop()
{
//nothing here
}
===== ESP Specific Libs =====
==== SDK-API (1.0.0) ====
If you want to use some the the SDK-API functions have a look at this link
http://bbs.espressif.com/viewtopic.php?f=5&t=286
The Documentation can be found here
http://bbs.espressif.com/download/file.php?id=253
To use the API you have to include some header-files in your sketch. Below is a quick example of using the RTC-Memory-Write API to make a counter persistent even after using sleep + the following reset.
#include
// Include API-Headers
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "cont.h"
}
// Counter
uint32_t i = 0;
// Temporary buffer
uint32_t b = 0;
void setup() {
Serial.begin(115200);
// Call API-Function
system_deep_sleep_set_option(4);
// Call API-Function
system_rtc_mem_read(64,&b,4) << endl;
// Check if the value is within expected range
if(b < 100000)
i = b;
}
int lap = 0;
void loop() {
for(int c = 0; c < 50; c++)
{
Serial << i++ << " " << lap << endl;
delay(10);
}
// Call API-Function
system_rtc_mem_write(64,&i,4) << endl;
delay(1000);
// Call API-Function
system_deep_sleep(10000000);
lap++;
}
==== ESP8266WiFi ====
**Connect with static IP**
If you experience problems regarding DNS resolving check out https://github.com/esp8266/Arduino/issues/369
#include
#include
#include
const char* ssid = ".....";
const char* password = ".....";
void setup(void)
{
Serial.begin(115200);
// Connect to WiFi network
WiFi.begin(ssid, password);
//set static ip part
WiFi.config(IPAddress(192,168,1,118), IPAddress(192,168,1,1), IPAddress(255,255,255,0));
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(200);
}
Serial.println(WiFi.localIP());
}
==== ESP8266mDNS ====
content
==== ESP8266WebServer ====
content