Showing posts with label DIY. Show all posts
Showing posts with label DIY. Show all posts

Thursday, 2 February 2017

HOME AUTOMATION: ESP8266, Blynk and OTA Updates

I previously used Blynk to set up remote access to my house via my phone and a electric door strike. Since then I learned of the Arduino Over The Air (OTA) update library that would allow me to remotely update the firmware of my device so naturally I immediately wanted to add this feature.

Arduino OTA Library:

You can read about the library on the Arduino github site here, but basically there are three ways you can implement the OTA update:

  1. Arduino IDE
  2. Web Browser
  3. HTTP Server
I've decided to go for the Arduino IDE scenario that is described here.
The requirements for this process are:
  • Arduino IDE (tested with 1.6.8)
  • Python 2.7


Arduino IDE OTA Update:

Basically all you really is the command "ArduinoOTA.begin();" in the setup routine and the command "ArduinoOTA.handle();" in the loop function. This is the bare minimum you need to get it working, but we'll add some more things like error handling and some basic security.

EDIT: I couldn't get the Arduino IDE security feature working on my windows 10 machine, it seems there are a few bugs still being worked out 


Blynk and OTA Code:


/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * This example runs directly on ESP8266 chip.
 *
 * WARNING! ESP8266 SSL support is still experimental.
 *          More info here: https://github.com/esp8266/Arduino/issues/43
 *
 * Note: This requires ESP8266 support package:
 *   https://github.com/esp8266/Arduino
 *
 * Please be sure to select the right ESP8266 module
 * in the Tools -> Board menu!
 *
 * Change WiFi ssid, pass, and Blynk auth token to run :)
 *
 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define RELAY_PIN D1

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
#include <Ticker.h>
#include <ArduinoOTA.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXX";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXX";
char pass[] = "XXXX";
char hostOTA[] = "DoorLock";
char passOTA[] = "XXXX";

bool vPinState = false;               // Set the default virtual pin state
int maxRelayOnTime = 10;              // Set the max on time of the relay 
int minRelayOnTime = 1;               // Set the minimum on time of the relay
int vDelayTime = minRelayOnTime;      // Set the initial delay time value
Ticker doorLatch;                     // Callback fuction instance

void setPinLow()
{
  digitalWrite(RELAY_PIN, 0);
  doorLatch.detach();
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, 0);

  ArduinoOTA.setHostname(hostOTA);
  //ArduinoOTA.setPassword(passOTA);
  ArduinoOTA.onStart([]() {
    Serial.println("OTA: Start");
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nOTA: End");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) Serial.println("OTA: Auth Failed");
    else if (error == OTA_BEGIN_ERROR) Serial.println("OTA: Begin Failed");
    else if (error == OTA_CONNECT_ERROR) Serial.println("OTA: Connect Failed");
    else if (error == OTA_RECEIVE_ERROR) Serial.println("OTA: Receive Failed");
    else if (error == OTA_END_ERROR) Serial.println("OTA: End Failed");
  });
  ArduinoOTA.begin();
  Serial.println("OTA: Ready");
}

void loop()
{
  ArduinoOTA.handle();
  Blynk.run();
}

BLYNK_WRITE(V0)
{
  // Get the virtual input state
  vPinState = param.asInt();

  // If the virtual input went high
  if(vPinState)
  {
    // Open the relay
    digitalWrite(RELAY_PIN, 1);
    // Turn off the relay after the defined delay time
    doorLatch.attach(vDelayTime, setPinLow);
  }
}

BLYNK_WRITE(V1)
{
  // Get the input from the virtual input slider
  vDelayTime = param.asInt();

  // Constrain the virtual slider input to within the preset bounds
  vDelayTime = constrain(vDelayTime, minRelayOnTime, maxRelayOnTime);
}


How to update your device OTA:

Once you get the code loaded on to your device you should see the unit appear in your list of ports under the 'Tools' heading.
I had to reboot my machine to get this to work for me. Now you can upload code to your device over the network as if it was connected via USB.


Wednesday, 18 January 2017

HOME AUTOMATION: Automated blinds - Teptron Move

Adding automated blinds to my home automation system has always been something I wanted to do. The promise of waking up to natural lighting the morning or coming home to a cool house on a hot day is what I imagine is an essential part of the house of the future.

I did some research and didn't find much in the way of a cheap DIY solution on the market, most of the solutions were at least a couple of hundred dollars per unit and required 240v wiring.
That was until I found the Teptron Move Kickstarter campaign, promising to give me everything I wanted for about $60 per blind including a solar charging panel. It was the cheapest of the DIY solutions I found and didn't require and extra wiring.




The reality:

The Kickstarter campaign took longer than expected (as usual) but I did eventually get my Bluetooth controlled blinds. I'm using the units on block-out roller blinks and opted to install with the double sided adhesive tape to try the system out before drilling any holes.
My experience with the system has been mixed, but here are the main points:
  • Be careful where you place the mechanism. May work on the way up but not down. My blinds catch on the Move unit on their way down so I need to stand by the unit to flick the bottom of the blind over the unit.
  • When I initially ordered the device there was no mention of load rating. I have big blinds and am right on the edge of capability for two out of three blinds and overweight on the third. This is probably not an issue if you are using the device for vertical blinds
  • Being over the load rating I needed to pull some serious tension on the beaded chain to get the device to work properly. As you can imagine this does not work well with the double sided tape over a long period of time in the heat of summer.
  • It's not always convenient to use my phone to open the blind. This point has probably been my single biggest issue with the Move unit
  • In my situation the physical buttons are impossible to get to when the blind is closed


Chain tension and double sided tape over time

Chain cover moved as it was getting in the way

Physical buttons hidden by the blind when closed


App (Android) v1.02

It was immediately obvious that the developers had over promised on this one. It's been a few months now and updates don't seem to be making it out, there is not much functionality at the moment and a few things are clearly missing:
  • I was only able to pair with one phone. I initially did it from a tablet then had to reset the device to connect with my phone, but somehow now both my phone and tablet can connect with the unit and set blind position
  • No automation functionality at the moment
  • No IFTTT support 
  • My blinds are back to front to the pictures shown
  • Blind doesn't always go to the correct position as per the slider bar, but has never gone past the end points
My blind is closed in the state shown


No automation support

Conclusion:

After using the devices for a little over one month the biggest issue I have with my system is not the devices fault, but my blinds catch on the way down and jam up on the unit itself. It's really annoying. I'm waiting on another Kickstarter campaign to send me my 3D printer so I can make a deflector bracket for the blind.

Blind caught in chain on the way down


My second biggest pain point with the device is that it's not as convenient as I thought it would be due to the placement of the manual control buttons. In my configuration the physical buttons are hidden behind the blind and it's really annoying to access.

Move unit hidden behind the blind

In reality without the automation component of the blinds I use the physical buttons 95% of the time, so it's pretty annoying to use at the moment. I'm considering a couple of hacks to expose the buttons for use with a wired remote but I'm not of the possibility of that at the moment, the unit isn't as easy to pull apart as I first though.


Update - 21/01/2017

I've tried to disassemble my move unit with no luck. The unit really doesn't appear to be made to disassemble...





Update - 24/01/2017

I contacted Teptron directly, they tell me the device is glued together and would need to be destroyed to be disassembled. Going to need to think of something else...