#ConnectedChristmas2020
is an art project whose goal is to help people celebrating Christmas connect to each other with the help of IoT technology.
This initiative is free to use and the server will be operated till 15th, January 2021.
The Basics
#ConnectedChristmas2020 leverages MQTT technology and the main component of this initiative is an MQTT Broker in the cloud. MQTT technology enables IoT devices to share messages with each other and while MQTT was not intended to be a synchronization protocol you can synchronize (1-2 sec. jitter) devices with this protocol over the internet.
MQTT Clients are implemented on numerous platforms. In this document we will focus on Python and Arduino (C++) code for ESP8266.
A few example use cases for what you can achieve within #ConnectedChristmas2020. You can build devices that:
- Synchronize Christmas lights across different locations in your family or in your neighborhood.
- Enable you to send lights, sounds, emojis, texts.. to your loved ones via devices you build.
- Message to anyone in a broadcasting style communication channel.
- React on variables like number of connected users or any other data you define.
Parameters
The #ConnectedChristmas2020 MQTT broker (an instance of the popular Mosquitto broker) can be accessed via the following IP address: 104.248.45.72
, the port used for the MQTT communication is the standard 1883
.
Accessing this MQTT broker needs a user name and a password combination. You can use the username : xmas , password : connXm4s
credentials.
It will enable you to read the following MQTT topics:
"welcome"
– information about the project"fiveseconds"
– a “ping” message is published every 5 seconds to help you with synchronization"daystillchristmas"
– countdown to Christmas"$SYS/broker/clients/active"
– number of active users connected to the MQTT broker
You can publish to xmas
and any topic under that.
Python example
The following code is a simple client application written in Python, requires the Paho MQTT Client library.
import paho.mqtt.client as mqtt
#Unfiltered callback for received messages
def on_message(client, userdata, message):
print(str(message.topic)+" : "+ str(message.payload)+" @QoS: " + str(message.qos))
#On Connect callback function
def on_connect(client, userdata, flags, rc):
print("Connected, result code:" + str(rc))
if __name__ == "__main__":
#These are the topics published by the server
topics = ["welcome", "fiveseconds", "daystillchristmas", "$SYS/#"]
mc = mqtt.Client()
#User + Password to access the broker
mc.username_pw_set("xmas", "connXm4s")
mc.on_message = on_message
mc.on_connect = on_connect
mc.connect("104.248.45.72", 1883, 60)
for topic in topics:
mc.subscribe(topic)
print(topic)
#Users can publish and subscribe to xmas and any topic under xmas
mc.publish("xmas/hello", "User has joined")
while (True):
mc.loop()
Arduino (ESP8266) Example
This is a modified example provided with the PubSubClient library.
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
const char* ssid = "........";
const char* password = "........";
const char* mqtt_server = "broker.mqtt-dashboard.com";
WiFiClient espClient;
PubSubClient client(espClient);
unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int value = 0;
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
randomSeed(micros());
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
// Switch on the LED if an 1 was received as first character
if ((char)payload[0] == '1') {
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is active low on the ESP-01)
} else {
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
}
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("arduinoClient", "xmas", "connXm4s")) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("xmas", "hello world");
// ... and resubscribe
client.subscribe("welcome");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup() {
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
}
Security/Legal Notice
To enable less experienced users easily connect the broker does not require TLS certifications. This is justified by the fact that what your are publishing to the MQTT broker will be visible for anyone. That’s the goal of this project!
The information you will publish to the MQTT broker will be visible to anyone connected to the same broker and maybe also to people who are not connected.
Do not publish any information to this MQTT broker where confidentiality is an issue!
Due to the nature of this project any type of information can be published to the broker and the owner of this project is not responsible to any of the content published, not only to, but especially in regards to political and religious views, swear words and such.
This is an “as-is” service and might be interrupted or terminated anytime, especially in regards of maintenance and termination upon attacks.
The owner of this project is not responsible to any direct or indirect damage caused by the normal or irregular operation of this MQTT broker.