Added first code for Wifi and MQTT
This commit is contained in:
parent
f41386954d
commit
ecef529a58
2 changed files with 27 additions and 0 deletions
|
@ -1,13 +1,21 @@
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
#include <NeoPixelBus.h>
|
#include <NeoPixelBus.h>
|
||||||
#include <NeoPixelSegmentBus.h>
|
#include <NeoPixelSegmentBus.h>
|
||||||
#include <NeoPixelAnimator.h>
|
#include <NeoPixelAnimator.h>
|
||||||
#include <NeoPixelBrightnessBus.h>
|
#include <NeoPixelBrightnessBus.h>
|
||||||
|
|
||||||
|
#include <MQTTPubSubClient.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
// Only for ESP8266 D1 Mini
|
// Only for ESP8266 D1 Mini
|
||||||
#define ECHO 5 // D1
|
#define ECHO 5 // D1
|
||||||
#define TRIG 16 // D0
|
#define TRIG 16 // D0
|
||||||
#define POTI_IN 17 // A0, analog In
|
#define POTI_IN 17 // A0, analog In
|
||||||
|
|
||||||
|
WiFiClient client;
|
||||||
|
MQTTPubSubClient mqtt;
|
||||||
|
|
||||||
// Set Data pin for LED ring (we use GPIO3, which is also RX of the serial line)
|
// Set Data pin for LED ring (we use GPIO3, which is also RX of the serial line)
|
||||||
#define DATA_PIN 3
|
#define DATA_PIN 3
|
||||||
|
@ -32,6 +40,21 @@ RgbColor black(0);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
// start your network
|
||||||
|
WiFi.begin(wifi_ssid, wifi_password);
|
||||||
|
// connect to host
|
||||||
|
client.connect(mqtt_server, 1883);
|
||||||
|
// initialize mqtt client
|
||||||
|
mqtt.begin(client);
|
||||||
|
// connect to mqtt broker
|
||||||
|
mqtt.connect("arduino", "public", "public");
|
||||||
|
|
||||||
|
// subscribe topic and callback which is called when /hello has come
|
||||||
|
mqtt.subscribe("/hello", [](const String& payload, const size_t size) {
|
||||||
|
Serial.print("/hello ");
|
||||||
|
Serial.println(payload);
|
||||||
|
});
|
||||||
|
|
||||||
// Setup the ultrasonic sensor PIN
|
// Setup the ultrasonic sensor PIN
|
||||||
pinMode(TRIG, OUTPUT); // TRIG-Pin: Output
|
pinMode(TRIG, OUTPUT); // TRIG-Pin: Output
|
||||||
pinMode(ECHO, INPUT); // ECHO-Pin: Input
|
pinMode(ECHO, INPUT); // ECHO-Pin: Input
|
||||||
|
|
4
config.h
Normal file
4
config.h
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
char* wifi_ssid = "your-ssid";
|
||||||
|
char* wifi_password = "your-passwd";
|
||||||
|
const char* mqtt_server = "your.mqtt.broker.org";
|
||||||
|
const char* mqtt_topic = "/your/topic/to/listen/to";
|
Loading…
Reference in a new issue