Custom Plex DVR setup with Dreambox DM500HD

Ok, I love my Plex server. I’ve been using it almost daily since 2012. But there’s been one feature missing since I turned off my Windows Media Center server many years ago and that has been to subscribe and record shows that I follow. And when the Plex team announced DVR support in Plex I’ve been meaning to look into it.
As I’m using a satellite dish to get my channels I looked for an alternative way from the official supported devices and stumbled upon a Dreambox thread in one of the forums. Here is what I’ve done if it happens to be of interest to someone else.

Screen Shot 2017-10-25 at 22.03.03-min

  1. I bought a Dreambox 500HD S2 (satellite tuner) on eBay
  2. As it had the original firmware on it, I first needed to flash it with the “second stage loader” in order to be able to add a custom image on it. It is described at the bottom of this page: http://sources.dreamboxupdate.com/
  3. I needed to find a firmware that supported softcams as well as it supported the PlexDVR API and after a lot of Googling I found out that OpenATV should work great
  4. I downloaded and flashed OpenATV v6.1 from this site: http://images.mynonpublic.com/openatv/6.1/index.php?open=dm500hd
  5. Next step was to enable softcams and after many tries and reflashes, I managed to fine a way for it
    1. Download softcam-feed-universal_2.0_all.ipk
    2. Use FTP to upload it to /tmp (see note below – I’ve been using DCC)
    3. Do NOT use the automated install through the Plugin Manager – Open a Terminal window (DCC)
    4. Run the command: “opkg install /tmp/softcam-feed-universal_2.0_all.ipk”
    5. Now, press the blue remote button and navigate to install plugins and softcams should be listed as an option
  6. I installed CCcam 2.3 and started the softcam under the Softcam Panel
  7. Goto /etc/keys to find a template to be used for the softcam. Modify it according to your specs and save it as CCcam.cfg in the same directory. I also updated the attributes to 755 (I don’t know if that is required)
  8. NOW – it is time to install the PlexDVR API plugin.
  9. Post installation follow the guide as described here: http://www.world-of-satellite.com/showthread.php?56936-PlexDVR-Setup
  10. It works great for recording shows or movies and the new content will be stored into my existing libraries. LiveTV is not working perfectly – sometimes it works and some times not – but recording of shows has not failed once.

Other information:

  • I’ve been using Dreambox Control Center for Enigma2 (DCC) to upload and run commands on my Dreambox device: https://www.bernyr.de/dcce2/
  • Post setup I had issues with teletext flashing when watching LiveTV through Plex. This was easily resolved by changing the Plex server default subtitles settings from “Always on” to “Manual”

Issues:

  • I’m still struggling with getting the correct DVB substream with the correct subtitles saved in the file when doing a recording. Really annoying.
Advertisements

Simple esp8266 433MHz MQTT bridge

I’ve played around with ESP8266 on a couple of occasions before but I’ve found it too unstable due to me simply not knowing enough. But as I have struggled to find a good solution for capturing signals from the sensors of my burglar alarm I decided to have another go at it.

There are tons of guides “out there” but I have been missing a good overview so I will try to explain my steps a bit more and the challenges with the esp8266.

Background

I have a cheap home burglar system with a set of PIRs and magnet sensors throughout my house. These are all sending messages to the central unit using PT2262 encryption.

As I am steering the lights etc. using norelite on Node-RED I want to capture these messages and simply put them onto an MQTT bus from where my norelite flows can subscribe to the topics and use the information.

I have tested the rc-switch library using an Arduino so I know that the interception and decoding works as required. I’ve previously used a 433 receiver with an Arduino Mini Pro and an nrf24l01 to send the data to a server that later puts the message on the MQTT bus – but there are too many components involved and it simply is not a good solution.

ESP8266-12E

Basics: Booting ESP8266 for flash

I’ve found the following setup to be stable in setting up the esp8266 for flashing.

 VCC  3.3V (Power supply)
 GND GND Power supply and
GND Serial adapter
 TX RX Serial adapter
 RX TX Serial adapter
 CH_PD  Pull high using 10kΩ resistor. Note that if you are using the module adapter it already includes the resistor
 RST  Pull high using 10kΩ resistor
 GPIO15  Pull low using 10kΩ resistor. Note that if you are using the module adapter it already includes the resistor
 GPIO0  Pull low using 10kΩ resistor

Basics: Booting ESP8266 for run

The only difference from the boot-for-flash setup is that you move GPIO0 to pull to high as shown below and removing the serial adapter (keep it if you want to get the output in the console)

 VCC  3.3V
 GND GND
 CH_PD  Pull high using 10kΩ resistor. Note that if you are using the module adapter it already includes the resistor
 RST  Pull high using 10kΩ resistor. (Move to GND in order to reset the device)
 GPIO15  Pull low using 10kΩ resistor. Note that if you are using the module adapter it already includes the resistor
 GPIO0  Pull high using 10kΩ resistor

Lessons learned when programming for the esp8266

  • Don’t forget to use delay() or yield() in your loops to give the opportunity for the device to manage background processes
  • If you are using timers (e.g. using Ticker library), make them short and very simple  – set variables and then do the major processing in the loop(). This is useful if you want to only run a certain task with a timing delay: Below is a simple example where just a variable is set in the called function and then the processing is made in the main loop function.
    #include Ticker timer;
    volatile bool timerRun;
    
    void timerTick(){
     timerRun = true; //Just setting the variable
    }
    
    void setup() {
     pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
    
     //Setup timer
     timer.attach_ms(60000, timerTick);
     timerRun = false;
    }
    
    // the loop function runs over and over again forever
    void loop() {
     if (timerRun){
     digitalWrite(LED_BUILTIN, 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)
     delay(1000); // Wait for a second
     digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making the voltage HIGH
     timerRun = false;
     }
     /*
     * Other processing
     *
     */
    }
  • Don’t run the esp8266 on the power supplied from the serial cable. Use a dedicated power supply and make sure to have a common ground. I.e. connect the serial GND to the power supply GND. Don’t forget limit the supplied voltage to 3.3V…
  • Verify that the baud rate in the console is supported by the OS and is the same as specified in the code
  • I’ve also experienced some issues with the serial adapter where the communication is lost sometimes but that is usually resolved by ejecting and re-inserting the usb cable and sometimes I have to update the port setting in the Arduino IDE.
  • I’ve also heard that it can be good to reset the flash memory when troubleshooting. I’ve never done it myself but one tool that can be used is esptool

The project

Components and schema

The below schema is for run mode. When flashing move GPIO0 to GND, connect TX/RX and GND from the serial adapter.

  • (U2)  LM1117 voltage regulator. Needed as I have a 5V input and I the ESP8266 runs on 3.3V and the 433MHz receiver is powered by 3.3-5V
  • (U1) 433MHz receiver (Superheterodyne 3400 RF).
  • (R1-R4) As explained in the basics above. These are for setting up the ESP.
  • I’m also using an esp module adapter board as these ones
  • Libraries: rc-switch, PubSubClient and ESP8266WiFi

screen-shot-2016-12-06-at-09-36-00

The code

#include <SPI.h>
#include <RCSwitch.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

/*
 * 433MHz to MQTT bridge for burglar alarm
 */

#define RADIOPIN 4
#define wifi_ssid "virus"
#define wifi_password "abc123abc123"
#define mqtt_server "192.168.2.195"
#define mqtt_port 1883

#include "os_type.h"

//WIFI and MQTT
WiFiClient espClient;
PubSubClient client(espClient);

//MQTT topics
String burglar_topic_all;
const char* mqttclientid;

RCSwitch mySwitch = RCSwitch();

/*
 * Common function to get a topic based on the chipid. Useful if flashing
 * more than one device
 */
String getMqttTopic(String type){
  return "/raw/esp8266/"+String(ESP.getChipId())+"/"+type;
}

/*
 * Setup WIFI connection and connect the MQTT client to the
 * MQTT server
 */
void connection_start() {
  setup_wifi();

  //Setup MQTT preferences
  client.setServer(mqtt_server, mqtt_port);
  delay(100);
  while(!client.connected()){
    if (client.connect(mqttclientid)) {
      Serial.println("MQTT connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");

      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
  Serial.println("Connections are setup");
}
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(mqttclientid)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      ESP.wdtFeed();
      delay(5000);
    }
  }
}

/*
 * Setup WIFI communication. I.e. connect to the access point
 * and get an IP address
 */
void setup_wifi() {
  //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());
}

/*
 * Common function to turn on WIFI radio, connect and get an IP address,
 * connect to MQTT server and publish a message on the bus.
 * Finally, close down the connection and radio
 */
void sendmsg(String topic, String payload){
    //Send status to MQTT bus if connected
    if (client.connected()){
      client.publish(topic.c_str(), payload.c_str());
      Serial.println("Published MQTT message");
    }
}

void setup() {
  Serial.begin(9600);
  delay(100);
  Serial.print("Starting\n");

  /* Setup MQTT Client ID
   *  As the id needs to be unique per user the chipid is used to
   *  generate an MQTT client id.
   */
  mqttclientid = ("ESPClient-"+String(ESP.getChipId())).c_str();
  Serial.print("MQTT Client ID: ");
  Serial.println(mqttclientid);

  //Setup connections
  connection_start();

  //Radio
  burglar_topic_all = getMqttTopic("burglar");
  Serial.print("Burglar topic: ");
  Serial.println(burglar_topic_all);
  mySwitch.enableReceive(RADIOPIN);
}

void loop() {
  //Reconnect network if needed
  if (WiFi.status() != WL_CONNECTED){
    connection_start();
  }

  //Reconnect MQTT if needed
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  /*
   * Listen for the input from the receiver
   */
  if (mySwitch.available()){

    int value = mySwitch.getReceivedValue();

    if (value == 0) {
      Serial.print("Unknown encoding");
    } else {
      //Send message
      sendmsg(burglar_topic_all, String(mySwitch.getReceivedValue()));
    }

    mySwitch.resetAvailable();
  }

  yield();
}