Owncloud-Kalenderkonvertierung in ics

 

Da MagicMirror Owncloud-Kalender nicht unterstützt müssen wir den Kalender ins Format .ics bringen. Dafür legen wir eine Script an das für uns die Konvertierung übernimmt. Dieses Script lassen wir als Cronjob regelmäßig (hier halbstündig) als cronjob laufen

 

Wechsel nach /home/pi

 

1
cd /home/pi

 

  • Datei anlegen:

 

1
sudo nano icalsync.sh

 

  • und folgendes Script einfügen

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
 
 
 
url="https://owncloud-raspberry.ddns.net/owncloud/remote.php/dav/calendars/dho/dho-owncloud9?export"
 
dest="/home/pi/MagicMirror/modules/calendars/owncloud-cal.ics"
 
user=owncloud-user
 
pwd="user-password"
 
 
 
wget \
 
--quiet --output-document="$dest" \
 
--auth-no-challenge --no-check-certificate \
 
--http-user=$user --http-password="$pwd" \
 
"$url"

 

  • owncloud-cal-ics anlegen (natürlich kann es auch ein anderer Name sein)

 

1
sudo nano MagicMirror/modules/calendars/owncloud-cal.ics

 

  • speichern mit Strg + o und schließen mit Strg + x

 

Owncloud-Kalender automatisch konvertieren

 

  • Script ausführbar machen

 

1
sudo chmod /home/pi/icalsync.sh

 

  • cronjob anlegen

 

1
sudo crontab -e

 

  • folgende Zeile ganz unen einfügen (halbstündliche Ausführung)

 

1
*/30 * * * * /home/pi/icalsync.sh

 

  • mit Strg + o speichern und mit Strg + x schließen

Owncloud-Kalender in config.js aufnehmen

 

  • config.js öffnen

 

1
sudo nano /home/pi/MagicMirror/config/config.js

 

  • Kalendermodul folgendermaßen anpassen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
 
          module: "calendar",
 
          header: "owncloud-cal",
 
          position: "top_left",
 
         config: {
 
                       calendars: [
 
                                          {
 
                                            symbol: "calendar-check-o ",
 
                                           url: "webcal://127.0.0.1:8080/modules/calendars/owncloud-cal.ics"
 
                                         }
 
                                       ],
 
                     }    
 
},

 

 

 

 

NodeMCU mit OLED, DHT22 und MQTT

 

verwendete libs:

 

https://github.com/squix78/esp8266-oled-ssd1306

 

verwendete Sites:

 

https://mjrobot.org/iot-made-simple-home-weather-station-with-nodemcu-and-oled/

 

https://github.com/Mjrovai/MJRoBot-Home-Weather-Station/blob/master/Home_Weather_Station_Indoor/Home_Weather_Station_Indoor.ino

 

https://gist.github.com/balloob/1176b6d87c2816bd07919ce6e29a19e9

 

 

// Get ESP8266 going with Arduino IDE
// - https://github.com/esp8266/Arduino#installing-with-boards-manager
// Required libraries (sketch -> include library -> manage libraries)
// - PubSubClient by Nick ‘O Leary
// - DHT sensor library by Adafruit

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


#include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"

SSD1306 display(0x3c, 5, 4); // Initialize the OLED display using Wire library

                /*    SDA ==> D1 (5)

                      SCL ==> D2 (4)  */

// wlan SSID, password, hostname
#define wifi_ssid "wlan-ssid"
#define wifi_password "wlanpassword"
#define myHostname "NodeMCU-indoor"

// mqtt server, user, password
#define mqtt_server "mqtt-server-ip"
#define mqtt_user "mqtt-user"
#define mqtt_password "mqtt-password"

// mqtt topics sensor/humidity; sensor/temperature
#define humidity_topic "sensor/humidity"
#define temperature_topic "sensor/temperature"

// DHT22
#define DHTTYPE DHT22
#define DHTPIN  14

DHT dht(DHTPIN, DHTTYPE, 11);

int localHum = 0;
int localTemp = 0;


/***************************************************
* Get indoor Temp/Hum data
****************************************************/
void getDHT()
{
  float tempIni = localTemp;
  float humIni = localHum;
  localTemp = dht.readTemperature();
  localHum = dht.readHumidity();
  if (isnan(localHum) || isnan(localTemp))   // Check if any reads failed and exit early (to try again).
  {
    Serial.println("Failed to read from DHT sensor!");
    localTemp = tempIni;
    localHum = humIni;
    return;
  }
}

/***************************************************
* Draw Indoor Page
****************************************************/
void drawDHT() 
{
  int x=0;
  int y=0;
  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(0 + x, 5 + y, "Hum");
  
  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(43 + x, y, "INDOOR");

  display.setFont(ArialMT_Plain_24);
  String hum = String(localHum) + "%";
  display.drawString(0 + x, 15 + y, hum);
  int humWidth = display.getStringWidth(hum);

  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.drawString(95 + x, 5 + y, "Temp");

  display.setFont(ArialMT_Plain_24);
  String temp = String(localTemp) + "°C";
  display.drawString(70 + x, 15 + y, temp);
  int tempWidth = display.getStringWidth(temp);
}



WiFiClient espClient;
PubSubClient client(espClient);


void setup() {
  Serial.begin(115200);
  display.init(); // Initialising the UI will init the display too.
  display.flipScreenVertically();
  dht.begin();
  setup_wifi();
  client.setServer(mqtt_server, 1883);
}

void setup_wifi() {
  WiFi.hostname(myHostname);
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(wifi_ssid);

  WiFi.begin(wifi_ssid, wifi_password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    // If you do not want to use a username and password, change next line to
    // if (client.connect("ESP8266Client")) {
    if (client.connect("ESP8266Client", mqtt_user, mqtt_password)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

bool checkBound(float newValue, float prevValue, float maxDiff) {
  return !isnan(newValue) &&
         (newValue < prevValue - maxDiff || newValue > prevValue + maxDiff);
}

long lastMsg = 0;
float temp = 0.0;
float hum = 0.0;
float diff = 1.0;



void loop() {
  getDHT();
  display.clear();
  drawDHT(); 
  display.display();
  delay (2000);
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  long now = millis();
  if (now - lastMsg > 2000) {
    lastMsg = now;

    float newTemp = dht.readTemperature();
    float newHum = dht.readHumidity();

    if (checkBound(newTemp, temp, diff)) {
      temp = newTemp;
      Serial.print("New temperature:");
      Serial.println(String(temp).c_str());
      client.publish(temperature_topic, String(temp).c_str(), true);
    }

    if (checkBound(newHum, hum, diff)) {
      hum = newHum;
      Serial.print("New humidity:");
      Serial.println(String(hum).c_str());
      client.publish(humidity_topic, String(hum).c_str(), true);
    }
  }
}

 

 

 

 

NodeMCU_DS18B20_MQTT

verwendete libs.

 

http://arduiniana.org/libraries/streaming/

 

verwendete Links:

 

http://www.jerome-bernard.com/blog/2015/10/04/wifi-temperature-sensor-with-nodemcu-esp8266/

 

NodeMCU DS18B20 wiring

/*
 Sketch which publishes temperature data from a DS1820 sensor to a MQTT topic.
 This sketch goes in deep sleep mode once the temperature has been sent to the MQTT
 topic and wakes up periodically (configure SLEEP_DELAY_IN_SECONDS accordingly).
 Hookup guide:
 - connect D0 pin to RST pin in order to enable the ESP8266 to wake up periodically
 - DS18B20:
     + connect VCC (3.3V) to the appropriate DS18B20 pin (VDD)
     + connect GND to the appopriate DS18B20 pin (GND)
     + connect D4 to the DS18B20 data pin (DQ)
     + connect a 4.7K resistor between DQ and VCC.
 - UploadSpeed: 9600Baud
*/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Streaming.h>

#define SLEEP_DELAY_IN_SECONDS  30
#define ONE_WIRE_BUS            D4      // DS18B20 pin
#define myHostname "NodeMCU-Kammer"


const char* ssid = "wlan-ssid";
const char* password = "wlan-password";

const char* mqtt_server = "mqtt-server-ip";
const char* mqtt_username = "mqtt-user";
const char* mqtt_password = ",qtt-password";
const char* mqtt_topic = "sensors/test/temperature";

WiFiClient espClient;
PubSubClient client(espClient);

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

char temperatureString[6];

void setup() {
  // setup serial port
  Serial.begin(115200);

  // setup WiFi
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);

  // setup OneWire bus
  DS18B20.begin();
}

void setup_wifi() {
  WiFi.hostname(myHostname);
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  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();
}

void reconnect() {
  // Loop until were reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

float getTemperature() {
  Serial << "Requesting DS18B20 temperature..." << endl;
  float temp;
  do {
    DS18B20.requestTemperatures(); 
    temp = DS18B20.getTempCByIndex(0);
    delay(100);
  } while (temp == 85.0 || temp == (-127.0));
  return temp;
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  float temperature = getTemperature();
  // convert temperature to a string with two digits before the comma and 4 digits for precision
  dtostrf(temperature, 2, 4, temperatureString);
  // send temperature to the serial console
  Serial << "Sending temperature: " << temperatureString << endl;
  // send temperature to the MQTT topic
  client.publish(mqtt_topic, temperatureString);

  Serial << "Closing MQTT connection..." << endl;
  client.disconnect();

  Serial << "Closing WiFi connection..." << endl;
  WiFi.disconnect();

  delay(100);

  Serial << "Entering deep sleep mode for " << SLEEP_DELAY_IN_SECONDS << " seconds..." << endl;
  ESP.deepSleep(SLEEP_DELAY_IN_SECONDS * 1000000, WAKE_RF_DEFAULT);
  //ESP.deepSleep(10 * 1000, WAKE_NO_RFCAL);
  delay(500);   // wait for deep sleep to happen
}