Skip to content

Instantly share code, notes, and snippets.

@nakov
Last active January 19, 2020 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nakov/3204535a917b44c3f11294f08b72dc76 to your computer and use it in GitHub Desktop.
Save nakov/3204535a917b44c3f11294f08b72dc76 to your computer and use it in GitHub Desktop.
ESP8266 with Thinger.io for Bulb control
using System;
using System.Net.Http;
using System.Windows.Forms;
namespace ESP8266BulbControl
{
public partial class FormBulbController : Form
{
HttpClient http = new HttpClient();
public FormBulbController()
{
InitializeComponent();
}
private void buttonSwitchOn_Click(object sender, EventArgs e)
{
http.GetAsync("https://api.thinger.io/v2/users/nakov/devices/esp8266bulb/bulbSwitchOn");
}
private void FormBulbController_Load(object sender, EventArgs e)
{
http.DefaultRequestHeaders.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1Nzk0NTQ5MjMsImlhdCI6MTU3OTQ0NzcyMywidXNyIjoibmFrb3YifQ.ywbCx8ckmm_Bzi0hfVFRJRDNUXjvMLgssfcDtyIvVtc");
}
private void buttonSwitchOff_Click(object sender, EventArgs e)
{
http.GetAsync("https://api.thinger.io/v2/users/nakov/devices/esp8266bulb/bulbSwitchOff");
}
}
}
#include <ThingerESP8266.h>
#define USERNAME "nakov"
#define DEVICE_ID "esp8266bulb"
#define DEVICE_CREDENTIAL "FDYmZop8Zu#2"
#define SSID "Softuni"
#define SSID_PASSWORD ""
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
void blink3times(pson& in, pson& out) {
for (int i = 0; i < 3; i++)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
}
void blinkManyTimes(pson& in, pson& out) {
int count = (int)in["count"];
for (int i = 0; i < count; i++)
{
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
out["result"] = "OK";
}
void bulbSwitchOn() {
digitalWrite(LED_BUILTIN, LOW);
}
void bulbSwitchOff() {
digitalWrite(LED_BUILTIN, HIGH);
}
void setup() {
// configure wifi network
thing.add_wifi(SSID, SSID_PASSWORD);
pinMode(LED_BUILTIN, OUTPUT);
// pin control example (i.e. turning on/off a light, a relay, etc)
thing["led"] << digitalPin(LED_BUILTIN);
// resource output example (i.e. reading a sensor value, a variable, etc)
thing["millis"] >> outputValue(millis());
thing["blink3times"] = blink3times;
thing["blinkManyTimes"] = blinkManyTimes;
thing["bulbSwitchOn"] = bulbSwitchOn;
thing["bulbSwitchOff"] = bulbSwitchOff;
}
void loop() {
thing.handle();
}
https://prnt.sc/qpuuiy
https://prnt.sc/qpuv80
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
upload_speed = 921600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment