Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/WifiConfig.h

15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@ Switching Sonoff Basic and Sonoff S20 (Webserver, local button and MQTT).
## Getting started
This project ist split in two parts: sonoffSimple/sonoffSimple.ino is just a simple demo as described [here](https://ct.de/yxgs).

The more advanced software (sonoffSocket.ino) supports MQTT, toggle, status and is actively developed. Just copy sonoffSocket.ino into your Arduino-IDE folder. To use mqtt you have to install external library "PubSubClient". Change your SSID and WiFi-Key and activate MQTT if needed (choose a topic too).
The more advanced software (sonoffSocket.ino) supports MQTT, toggle, status and is actively developed. Just copy sonoffSocket.ino into your Arduino-IDE folder. To use mqtt you have to install external library "PubSubClient". Activate MQTT if needed (choose a topic too) in sonoffSocket.ino.

Create a WiFiConfig.h with this content:
```
//Your Wifi SSID
const char* ssid = "your_ssid";
//Your Wifi Key
const char* password = "your_key";
//Your MQTT Broker
const char* mqtt_server = "your.mqtt.broker.IP";
```

Connect Sonoff Basic or Sonoff S20 to your FTDI-Adapter and flash it using the Arduino-IDE.

## How it works
The socket can be controlled by opening <ip of socket>/on (to activate) and <ip of socket>/off to deactivate. If MQTT is enabled, send 1 or 0 to your chosen topic (defined at the beginning of your code).
Get the current status with <ip of socket>/state and toggle with <ip of socket>/toggle

## More information
This repository is part of article ["Bastelfreundlich"](https://ct.de/yxgs) from German computer magazine "c't".
This repository is part of article ["Bastelfreundlich"](https://ct.de/yxgs) from German computer magazine "c't".
10 changes: 1 addition & 9 deletions sonoffSocket.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <Ticker.h>
#include "WiFiConfig.h"

//To use MQTT, install Library "PubSubClient" and switch next line to 1
#define USE_MQTT 0
Expand All @@ -18,20 +19,11 @@

#if USE_MQTT == 1
#include <PubSubClient.h>
//Your MQTT Broker
const char* mqtt_server = "your mqtt broker";
const char* mqtt_in_topic = "socket/switch/set";
const char* mqtt_out_topic = "socket/switch/status";

#endif


//Yout Wifi SSID
const char* ssid = "your_ssid";
//Your Wifi Key
const char* password = "your_key";


ESP8266WebServer server(80);
#if USE_WEBUPDATE == 1
ESP8266HTTPUpdateServer httpUpdater;
Expand Down