From 27a0377992bfc536f0e69c3c5ee32cb65936b402 Mon Sep 17 00:00:00 2001 From: feg2hi Date: Mon, 5 Apr 2021 12:35:36 +0200 Subject: [PATCH] Move WiFi credetials and MQTT IP to seperate file WiFiConfig.h --- .gitignore | 2 ++ README.md | 15 +++++++++++++-- sonoffSocket.ino | 10 +--------- 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c8315d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/WifiConfig.h + diff --git a/README.md b/README.md index 41dd1a9..9eded69 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,18 @@ 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 @@ -12,4 +23,4 @@ The socket can be controlled by opening /on (to activate) and /state and toggle with /toggle ## More information -This repository is part of article ["Bastelfreundlich"](https://ct.de/yxgs) from German computer magazine "c't". \ No newline at end of file +This repository is part of article ["Bastelfreundlich"](https://ct.de/yxgs) from German computer magazine "c't". diff --git a/sonoffSocket.ino b/sonoffSocket.ino index 2cc032c..f83c025 100644 --- a/sonoffSocket.ino +++ b/sonoffSocket.ino @@ -4,6 +4,7 @@ #include #include #include +#include "WiFiConfig.h" //To use MQTT, install Library "PubSubClient" and switch next line to 1 #define USE_MQTT 0 @@ -18,20 +19,11 @@ #if USE_MQTT == 1 #include - //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;