Skip to content

Instantly share code, notes, and snippets.

@igrr
igrr / mh-z14.ino
Created December 25, 2015 11:42
MH-Z14 ESP8266 Arduino example
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <time.h>
const char* ssid = "co2_sensor";
const char* password = "1qazxsw2";
ESP8266WebServer server(80);
@igrr
igrr / ESP8266_K30_DHT.ino
Created December 25, 2015 12:56
ESP8266 + K-30 CO2 Sensor over UART + DHT22 temperature/humidity sensor + MQTT
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
DHT dht(D5, DHT22);
const char* ssid = "........";
const char* password = "........";
IPAddress mqttServer(192, 168, 1, 10);
#include <functional>
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("");
Serial.println("start");
}
uint32_t measure_time(std::function<void(void)> fn)
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
uint8_t buff[128] = { 0 };
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin("#!/bin/test", "test_bin");
Serial.begin(115200);
#include <ESP8266WiFi.h>
#include <FS.h>
#include <ESP8266WebServer.h>
void startSoftAP() {
Serial.println("startSoftAP");
WiFi.mode(WIFI_AP);
WiFi.softAP("ESPAP");
ESP8266WebServer server;
@igrr
igrr / SMTP_ESP8266.ino
Created June 23, 2016 03:27
ESP8266 Arduino SMTPClient test
// Download SMTPClient library from https://github.com/gregington/SMTPClient
#include <ESP8266WiFi.h>
#include <Client.h>
#include <Mail.h>
#include <SMTPClient.h>
WiFiClient wifiClient;
SmtpClient client(&wifiClient, "smtp.163.com");
@igrr
igrr / newlib-esp32-configure.sh
Last active July 3, 2023 17:19
These are the steps to build newlib used in ESP32 ROM and ESP-IDF
git clone https://github.com/espressif/newlib-esp32.git &&
cd newlib-esp32 && \
./configure \
--with-newlib \
--enable-multilib \
--disable-newlib-io-c99-formats \
--disable-newlib-supplied-syscalls \
--enable-newlib-nano-formatted-io \
--enable-newlib-reent-small \
--enable-target-optspace \
@igrr
igrr / format.sh
Created November 3, 2016 15:32
(temporary) ESP-IDF style guide
#!/bin/bash
# Runs astyle with the full set of formatting options
astyle \
--style=otbs \
--indent=spaces=4 \
--convert-tabs \
--align-pointer=name \
--align-reference=name \
--keep-one-line-statements \
--pad-header \
@igrr
igrr / Makefile
Created January 25, 2017 03:47
DCMI signal generator for Lattice ICEStick
SRC := dcmi_source.v
CONSTRAINTS := dcmi_source.pcf
NAME := dcmi_source
TOP := DCMISource
all: $(NAME).bin
$(NAME).blif: $(SRC)
yosys -p 'synth_ice40 -top $(TOP) -blif $@' $<
@igrr
igrr / sleep_from_wake_stub_example.c
Last active November 25, 2023 21:27
ESP32 ESP-IDF example illustrating how to go back to sleep from deep sleep wake stub
/*
* This sample illustrates how to go back to deep sleep from the
* deep sleep wake stub.
*
* Consider the use case of counting pulses from an external sensor,
* where the pulses arrive at a relatively slow rate.
*
* ESP32 is configured to go into deep sleep mode, and wake up from
* a GPIO pin connected to the external pulse source.
* Once the pulse arrives, ESP32 wakes up from deep sleep and runs