Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
If you like Sming, give it a star, or fork it and contribute!
Summary
- Highly effective in performance and memory usage (this is native firmware!)
- Simple and powerful hardware API wrappers
- Fast & user friendly development
- Work with GPIO in Arduino style
- Compatible with standard Arduino libraries - use any popular hardware in few lines of code
- Integrated boot loader rBoot with support for 1MB ROMs, OTA firmware updating and ROM switching
- Built-in file system: spiffs
- Built-in powerful wireless modules
- Powerful asynchronous (async) network stack
- Async TCP and UDP stack based on LWIP
- With clients supporting: HTTP, MQTT, WebSockets and SMTP
- And servers for: DNS, FTP, HTTP(+ WebSockets), Telnet
- With SSL support for all network clients and servers based on axTLS 2.1+ with Lwirax.
- Out of the box support for OTA over HTTPS.
- Crash handlers for analyzing/handling system restarts due to fatal errors or WDT resets.
- PWM support based on Stefan Bruens PWM
- Optional custom heap allocation based on Umm Malloc
- Based on Espressif NONOS SDK. Tested with versions 1.5 and 2.0. Experimental support for SDK version >= 3.0.0.
Compatibility
OS/SDK | Linux | Mac OS X | Windows | FreeBSD-current |
---|---|---|---|---|
UDK (v1.5) | n/a | n/a | n/a | |
esp-open-sdk (v1.5, v2.0, v3.0 **) | n/a |
- OS = Operating System.
- SDK = Software Development Kit.
- n/a = The selected SDK is not available on that OS.
- ** = experimental support
Latest Stable Release
Getting started
Optional features
There are multiple custom features that can be enabled by default. For example: SSL support, custom LWIP, open PWM, custom heap allocation, more verbose debugging, etc. Click here to see the details
Compilation and flashing
See the getting started page for your respective operating system.
You can find more information about compilation and flashing process by reading esp8266.com forum discussion thread. Official ESP8266 documentation can be found in the Espressif website.
Examples
Once you are ready with the "Getting started" guide you can get the latest source code.
git clone https://github.com/SmingHub/Sming.git
And check some of the examples.
cd Sming/samples
cd Basic_Blink
make # -- compiles the application
make flash # -- tries to upload the application to your ESP8266 device.
More information at Wiki Examples page.
Simple GPIO input/output
#define LED_PIN 2 // GPIO2
...
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
For a complete example take a look at the Basic_Blink sample.
Start Serial communication
Serial.begin(9600);
Serial.println("Hello Sming! Let's do smart things.");
Connect to WiFi
WifiStation.enable(true);
WifiStation.config("LOCAL-NETWORK", "123456789087"); // Put you SSID and Password here
Read DHT22 sensor
#include <Libraries/DHTesp/DHTesp.h> // This is just a popular Arduino library!
#define DHT_PIN 0 // GPIO0
DHTesp dht;
void init()
{
dht.setup(DHT_PIN, DHTesp::DHT22);
float h = dht.getHumidity();
float t = dht.getTemperature();
}
Take a look at the code of the Humidity_DHT22 sample.
HTTP client
HttpClient thingSpeak;
...
thingSpeak.downloadString("http://api.thingspeak.com/update?key=XXXXXXX&field1=" + String(sensorValue), onDataSent);
void onDataSent(HttpClient& client, bool successful)
{
if (successful) {
Serial.println("Successful!");
}
else {
Serial.println("Failed");
}
}
For more examples take a look at the HttpClient, HttpClient_Instapush and HttpClient_ThingSpeak samples.
OTA application update based on rBoot
void OtaUpdate()
{
uint8 slot;
rboot_config bootconf;
Serial.println("Updating...");
// need a clean object, otherwise if run before and failed will not run again
if (otaUpdater) {
delete otaUpdater;
}
otaUpdater = new rBootHttpUpdate();
// select rom slot to flash
bootconf = rboot_get_config();
slot = bootconf.current_rom;
if (slot == 0) {
slot = 1;
}
else {
slot = 0;
}
// flash rom to position indicated in the rBoot config rom table
otaUpdater->addItem(bootconf.roms[slot], ROM_0_URL);
// and/or set a callback (called on failure or success without switching requested)
otaUpdater->setCallback(OtaUpdate_CallBack);
// start update
otaUpdater->start();
}
For a complete example take a look at the Basic_rBoot sample.
Embedded HTTP Web Server
server.listen(80);
server.addPath("/", onIndex);
server.addPath("/hello", onHello);
server.setDefaultHandler(onFile);
Serial.println("=== WEB SERVER STARTED ===");
Serial.println(WifiStation.getIP());
...
void onIndex(HttpRequest &request, HttpResponse &response)
{
TemplateFileStream *tmpl = new TemplateFileStream("index.html");
auto &vars = tmpl->variables();
vars["counter"] = String(counter);
vars["IP"] = WifiStation.getIP().toString();
vars["MAC"] = WifiStation.getMAC();
response.sendTemplate(tmpl);
}
void onFile(HttpRequest &request, HttpResponse &response)
{
String file = request.getPath();
if (file[0] == '/')
file = file.substring(1);
response.setCache(86400, true);
response.sendFile(file);
}
For more examples take a look at the HttpServer_ConfigNetwork, HttpServer_Bootstrap, HttpServer_WebSockets andHttpServer_AJAX samples.
Sending emails
SmtpClient emailClient;
emailClient.connect(URL("smtp://user:password@domain.com:25"));
MailMessage* mail = new MailMessage();
mail->from = "developers@sming";
mail->to = "iot-developers@world";
mail->subject = "Greetings from Sming";
mail->setBody("Hello");
FileStream* file= new FileStream("image.png");
mail->addAttachment(file);
emailClient.onMessageSent(onMailSent);
emailClient.send(mail);
...
int onMailSent(SmtpClient& client, int code, char* status)
{
MailMessage* mail = client.getCurrentMessage();
...
if(!client.countPending()) {
client.quit();
}
return 0;
}
See the SmtpClient sample for details.
Documentation
We provide generated documentation online.
If you want you can also generate a complete documentation locally by running the commands below. This requires
doxygen
to be installed on your system.cd $SMING_HOME
make docs
The newly generated documentation will be located under Sming/docs/api.
Contribute
You can contribute to Sming by
- Providing Pull Requests with new features, bug fixes, new ideas, etc. Make sure to follow our Coding-Style-Rules. Read ourContributing guide for details.
- Testing our latest source code and reporting issues.
- Supporting us financially to acquire hardware for testing and implementing or out of gratitude
Financial contributions
We welcome financial contributions in full transparency on our open collective page. They help us improve the project and the community around it. If you would like to support us you can become a backer or a sponsor.
In addition to that anyone who is helping this project can file an expense. If the expense makes sense for the development of the community, it will be "merged" in the ledger of our open collective by the core contributors and the person who filed the expense will be reimbursed.
Backers and sponsors
or sponsored it.
Commentaires
Enregistrer un commentaire