Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Farbgeber a MsgFlo participant #9

Closed
wants to merge 11 commits into from
Closed
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
56 changes: 56 additions & 0 deletions color_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/python
# coding=utf-8

import time
import struct
from colour import Color
from Tkinter import *
import threading

def generate_terminal_output(base_color, base_color_variant_1, base_color_variant_2, base_color_variant_3, base_color_variant_4, contrast_color, time_value, canvas=0, width=0, height=0):
w = width / 12.0
x = width / 2 - w / 2
y = int(time_value / 6)

canvas.create_line(x + 0 * width, y, x + w, y, fill=base_color.hex)
canvas.update()

def generate_palette(time_value=0.0, base_saturation=1.0, base_luminance=0.4, hue_modifier=0.03, lum_modifier=0.07, sat_modifier=0.2, program_cycles=0, canvas=0, width=0, height=0):

while(time_value < 3600):
base_hue = time_value / 3600
base_color = Color(hsl=(base_hue, base_saturation, base_luminance))

base_color_variant_1 = Color(
hsl=(base_color.hue + hue_modifier, base_saturation - sat_modifier, base_luminance))
base_color_variant_2 = Color(
hsl=(base_color.hue - hue_modifier, base_saturation - sat_modifier, base_luminance))
base_color_variant_3 = Color(
hsl=(base_color.hue, base_saturation, base_luminance + lum_modifier))
base_color_variant_4 = Color(
hsl=(base_color.hue, base_saturation, base_luminance - lum_modifier))

base_degree = base_hue * 360
if base_degree < 180:
contrast_hue = base_degree + 180
else:
contrast_hue = base_degree - 180
contrast_hue /= 360
contrast_color = Color(hsl=(contrast_hue, base_saturation - sat_modifier, (base_luminance + 0.2)))

generate_terminal_output(base_color, base_color_variant_1, base_color_variant_2, base_color_variant_3,
base_color_variant_4, contrast_color, time_value, canvas, width, height)

time_value += 6

if __name__ == "__main__":
master = Tk()

canvas_width = 800
canvas_height = 600
w = Canvas(master, width=canvas_width, height=canvas_height)
w.pack()

generate_palette(canvas=w, width=canvas_width, height=canvas_height)
mainloop()

104 changes: 75 additions & 29 deletions esp8266/mqtt_client/mqtt_client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,58 @@

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Adafruit_NeoPixel.h>

#define PIN D8
#define NUM_LEDS 6 // 150
#define NUM_GROUPS 6 // base + variant1,2,3,4 + contrast
#define LEDS_PER_GROUP NUM_LEDS / NUM_GROUPS

// Update these with values suitable for your network.

const char* ssid = "c-base-botnet";
const char* password = "<secret>";
const char* ssid = "<enter ssid here>";
const char* password = "<enter password here>";
const char* mqtt_server = "iot.eclipse.org";

WiFiClient espClient;
PubSubClient client(espClient);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
long lastMsg = 0;
char msg[50];
int value = 0;

typedef struct Color {
unsigned char red;
unsigned char green;
unsigned char blue;
} ;

typedef struct ColorElements {
char pBinary[8];
Color base;
Color variant[4];
Color contrast;
};

void setLedGroupColor(int group, Color color) {
int startLed = group * LEDS_PER_GROUP;
int brightnessDivider = 32;

color.red /= brightnessDivider;
color.green /= brightnessDivider;
color.blue /= brightnessDivider;

for(int i = startLed; i < startLed + LEDS_PER_GROUP; i++)
strip.setPixelColor(i, strip.Color(color.red, color.green, color.blue));

strip.show();
delayMicroseconds(100); // avoid glichtes (do not set below 100us)
}

void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'

pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
Serial.begin(115200);
setup_wifi();
Expand Down Expand Up @@ -66,46 +104,56 @@ void setup_wifi() {
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();
void printColor(const char* pDescription, struct Color color) {
char pBuf[128];
snprintf(pBuf, sizeof(pBuf) - 1,
"%s color: #%02X%02X%02X", pDescription,
color.red, color.green, color.blue);

Serial.println(pBuf);
}

// 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 acive low on the ESP-01)
} else {
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
void callback(char* topic, byte* payload, unsigned int length) {
if (length != sizeof(ColorElements)) {
Serial.println("Invalid packet format!");

return;
}

Serial.println(topic);

const ColorElements* pColors = (ColorElements*)payload;
printColor("Base ", pColors->base);
printColor("Variant 1", pColors->variant[0]);
printColor("Variant 2", pColors->variant[1]);
printColor("Variant 3", pColors->variant[2]);
printColor("Variant 4", pColors->variant[3]);
printColor("Contrast ", pColors->contrast);

setLedGroupColor(0, pColors->base);
setLedGroupColor(1, pColors->variant[0]);
setLedGroupColor(2, pColors->variant[1]);
setLedGroupColor(3, pColors->variant[2]);
setLedGroupColor(4, pColors->variant[3]);
setLedGroupColor(5, pColors->contrast);
}

void reconnect() {
// Loop until we're reconnected
void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect

if (client.connect("farbgeber_client")) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic", "hello world");
// ... and resubscribe
client.subscribe("c-base/#");
Serial.println("connected");
client.subscribe("c-base/farbgeber");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void loop() {

if (!client.connected()) {
Expand All @@ -117,9 +165,7 @@ void loop() {
if (now - lastMsg > 2000) {
lastMsg = now;
++value;
snprintf (msg, 75, "hello world #%ld", value);
Serial.print("Publish message: ");
snprintf (msg, 75, "Heartbeat #%ld", value);
Serial.println(msg);
client.publish("outTopic", msg);
}
}
131 changes: 0 additions & 131 deletions experiment1.py

This file was deleted.

Loading