My Smart Home

When I had my first and only house (2015) I wanted it to have some state of the art smart home system. The electrician suggested me to implement the Bticino MyHome which was one of the best out there.

However the budget was an issue so I started with a limited implementation by enabling only scenarios and integrated Burglar Alarm. I thought “…in the future I will enable advanced scenarios and integrate with other devices by developing some applications through a connection with the Bticino SCS bus and OpenWebNet protocol…”

It all started in 2016, when I asked the electrician about automating external lighting… and I’ve been told that I needed to spend hundreds of Euros on devices for a fixed/hardware only configuration? No it can’t be possible,… the other option was to install a Bticino Web Server with subscription for about 1200€ of work/hardware… but I wanted to enable any kind of automation integrating advanced scenarios and an integrated mobile application.

In 2020 I started thinking about buying an F454 Web Server to perform all these automations on my own, but it appeared that this device is now obsolete, or at least for “old” MyHome systems… the new one is Bticino specific and very expesive as well… so I asked myself: “Why don’t try to implement a smart home by integrating my existing one but moving away from Bticino specific MyHome implementation?”

The idea is to enable my home with Smart Automation not limited to what current MyHome can do but being able to add additional automations to the system, being able to control everything from the mobile phone, and so on…

So I searched through the net and I found that there was a really cheap Gateway MH201, compatible with my system that would allow me to connect to the automation system through the LAN! So, I bought it, and in a few minutes I was able to install it (see below).

After connecting hte MH201 I was able to reverse-engineer the whole system, name things, and started hacking the system after a proper backup! I was able to program My Home with about 70 Euros!!!

EUREKA!

After connecting the system, I needed to find the best automation software system and I stumbled upon https://homebridge.io/. After some interesting testing I was able to bridge my Bticino system with Applie iOS HomeKit devices. It was NOT enough for me, since I realized that this kind of bridge was somehow limited I wanted a more complete and apple-independent system: I wanted a complete web interface, I wanted being able to connect through a normal browser, connect any device (any technology) and other advanced features.

Talking with my collegue and friend Michele he pointed me to know https://www.home-assistant.io/. Just installed this system I realized immediately the power of this stunning open platform! The community behind Home Assistant is growing continuously, backed by Casa Nabu.

I started playing with this platform, bought a Raspberry PI, connected the whole home with LAN cables and integrated all wired/wireless devices:

System Architecture Overview

AS-IS

The first thing I had to do was to bridge the existing MyHome Automation system with the network. SCS BUS is a proprietary technology of Bticino, the best way to integrate it is through a Gateway.

So, I opened the electrical cabinet to look into it and study the whole system.

This is what I found … a mess… this is what the electrician did… anyway I was able to study the Bticino official MyHome documentation, and I reverse engineered the whole system understanding some key points that allowed me to understand where the MH201 Gateway should be placed.

Basically:

  • Red items: Alarm sub-system
  • Blue items: Automation

Installing the MH201

First off, I needed the gateway, so I bought the MH201 device online for about 60€.

My Idea is to Connect it to the main SCS AI Bus like this:

Since I didn’t have any LAN cable/router in my home I had to set up the physical LAN having fun deploying some Cat5/6 cables around the house 🙂

In the next posts I’ll explain what I did in my spare time in the latest months in building the whole system!

Welcome back! :-)

Finally I am back after a Loooong time away from my blog.

Actually I have been very busy in the latest months/years building new awesome stuff with my team during the day, and with my family during the rest of my spare time… for this reason I had really no time to write posts on my blog.

I am going to discover MS Azure in depth. I think this Cloud Infrastructure will be the best, I think they offer really unique and realitively cheap services compared with other cloud providers.

Yes, it is now the time to start discovering how migrate to build a SAAS solution on this infrastructure.

Keep in touch I’ll be back with some thoughts and I’ll post some updates soon!

Installing Xsd2Code on Visual Studio 2012 RC

These days I’m working mainly on Visual Studio 2012 RC and since we use Xsd2Code, I thought about why can’t I have it running there?

Basically VS 2012 RC is really similar on the Add-Ins model (from what I understand it didn’t change a lot from the 2010 release).

However if you try to find it through NuGet you can’t find it, and if you install the CodePlex package you see that actually it does show up on earlier versions of Visual Studio, but not on Visual Studio 2012.

I tried to hack this stuff and “published” the AddIn manually by changing some files, and it looks like it’s working.

Install from here:

http://xsd2code.codeplex.com/downloads/get/298534

Here you go:

  • Find the folder “AddIns” on your personal Visual Studio 2010 folder. You should have the same file as shown here:

  • Now, move on the “Visual Studio 2012” folder, and copy the same Addin file as shown above (remember to create AddIn subfolder if not found).
  • Edit the AddIn file by adding the section highlighted below.

There you go!

Start Visual Studio 2012, and see that the tool is available on the AddIn manager.

Update: Darin asked me to add the file directly for those that don’t have Visual Studio 2010 installed on their machine, but only 2012,  here you go … from codeplex, for the VS 2010 version, apply the changes above and you’re done

Have fun with this great tool!

Deploying an ASP.NET application on a different timezone

Yesteday I had a very strange behavior. I had to build an installer package to update a web application in a customer site, but got crazy trying to have it installed correctly.

The application installed fine, but as soon as I tried to browse it, a strange error appeared on the EventViewer:

Type : System.ArgumentOutOfRangeException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
       Message : Specified argument was out of the range of valid values.
Parameter name: utcDate
       Source : System.Web
       Help link :
       ActualValue :
       ParamName : utcDate
       Data : System.Collections.ListDictionaryInternal
       TargetSite : Void UtcSetLastModified(System.DateTime)
       Stack Trace :    at System.Web.HttpCachePolicy.UtcSetLastModified(DateTime utcDate)
          at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
          at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
          at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

What was happening?

Well, it appears that there is a problem with assemblies compiled in the “future”. Obviously this means that if you’re deploying an application on another timezone you must the coherency of the date/time of your assemblies with the actual date/time of that server.

In fact, IIS looks for the date/time of your assemblies, and if the date/time of your assemblies is on the future compared with the local date/time then it crashes with the exception above.

Hope this helps someone else having this issue.

Windows 8, HTML5/JS and Silverlight… my opinion

The first demo of Windows 8 produced an indredible reaction of Silverlight developers having the sensation that Silverlight being dropped while promoting HTML5/CSS3 and Javascript as a new “first class” framework for the new OS.

I think that Silverlight and WPF are superior for many reasons compared to HTML5 and JS, as they are TODAY.

The reasons are:

  • XAML is BY FAR more elegant way to define UIs
  • Silverlight can completely re-template UIs easily
  • Building complex LOB applications. KnockOut JS is great, but not enough.
  • Silverlight is FAR more performant compared to ANY JS engine
  • Debugging HTML/JS app is a nightmare
  • JS is a dynamic language. Dynamic languages are powerful… but it’s extremely easy to lose control on your code.

Basically my thought are that HTML5/CSS3/JS is GREAT to build dynamic web sites, BUT when comes to write real/very complex LOB applications, then there are great limitations, at least TODAY. (please look at this great @shanselman blog regarding this stuff: Should I use HTML5 or Silverlight? One man’s opinion).

Talking about HTML5/CSS3, the standard is not yet defined, and many browsers implement it in different ways creating problems…

Before switching to any HTML and JS framework, I guess we really need to wait for adequate tooling – such as Blend for example – and for sure a REAL standard.

So… what’s really happening here? Should I need to learn HTML5/CSS3 tomorrow? I think the answer is NO. And I hope too because really I hate it at least at its current status.

The “future” as I hope it

Actually I think that Windows 8 will support ALL the platforms, including Silverlight, and Silverlight will continue to be supported in the future, however I think for a number of reasons that possibly Microsoft will introduce a sort of “deployment target” to HTML5/CSS3/JS for any application and continue to provide a .NET language such as C# and .NET along with XAML.

Let’s see what’s the current scenario:

  • WP7 runs Silverlight
  • Visual Studio, Blend, and other tools are currently based on XAML/Silverlight
  • Silverlight is a subset of WPF with some limitations

There are a lot of tentatives of “PORTING” features like data binding and .NET from Silverlight/XAML to other “platforms”:

  • Script# attempts to convert C# in JS!
  • Knockout JS implements MVVM pattern on JS
  • Mono touch allows writing C# code and run on IPhone/Android for example.

Do you think that MS will re-invent ALL their tooling to suit HTML and Javascript?

Do you think that tomorrow WP7 will run both Silverlight and HTML5 apps built in completely different ways?

Is Microsoft probably working on a sort of “conversion tool” or runtime that will allow current tools, XAML, .NET to be converted in HTML/JS/CSS3? A new “deployment target”, … something like that.

OK, this sounds very difficult or full of limitations, … however I am quite sure that it isn’t impossible, given the points above.

We’ll see what will happen in the next months…

Keep tuned.

KnockOutJS Library, or MVVM on Javascript!

These days I came across Knockout. This GREAT library really provides necessary help for developers on building the next generation HTML5/CSS3 applications for both client and mobile platforms.

MVVM was firstly introduced on WPF and then on Silverilght to provide an intermediate mean for databinding a user interface to the underlying data model.

Today we can really provide the same experience also on browser applications, by doing databinding on HTML!

I have to say that with this library everything is different. This complementary library can work with JQuery and other frameworks.

Here you can look at how it works:

image

This library is very lightweight since is somewhat ~28Kb minified and 10 Kb compressed javascript.

Great Job Steve!

Don’t trust Visual Studio 2008 Profiler too much…

Today I experienced something that made me really angry against Visual Studio 2008 Profiler! I spent half a day to try find why a certain program was slow at determinate operations, I was focusing to some complex methods because profiler was pointing me there and I was seeing no other sign of issues around.

Well, after losing a lot of hours, Mizokunimito came into rescue and promptly remembered me to avoid trusting this profiler.

I said “You’re joking. If the profiler shows me that this method reports the major number of samples then is the place to look for optimizations… ok, … if the profiler is right, and I really hope so”.

Well, he was completely right on that, Profiler was cheating. Some method calls were COMPLETELY MISSING FROM THE REPORT, thus pointing us to look at the wrong direction.

We saw that by manually adding some StopWatch.Start/Stop calls, and dumping the timings on the method that profiler, the time required to execute that method was only a few ms, compared to the simulation that was saying more than 1500 ms!!

Now, I know and we use Visual Studio 2010 for other projects, but in this case we had to keep the Visual Studio 2008 project for a number of reasons, so we had to use an “old” version of the profiler, … but… I have to admit, …

I learned another time, that

1) We should never trust software too much , and be always as St. Thomas… trust only your eyes, and look also where you think that there are no issues… because sometimes Murphy Law helps making this the actual answer to your performance issues!

2) Working on a real Team is a great thing!

Cheers

SOLID Principles

Great object programming should always employ SOLID object programming principles/patterns, because they allow among other things, better extensibility maintenance. This is especially true if you’re going to create an application or framework that evolves over time.

I would like to post some links where Julian M Bucknall (CTO of DevExpress) that explains the principles on these great videos:

"S" Single Responsibility Principle: http://tv.devexpress.com/#SingleResponsibilityPrinciple;.tag;1

"O" Open Closed Principle
http://tv.devexpress.com/#OinSOLID;.tag;1

"L" Liskov Substitution
http://tv.devexpress.com/#LinSOLID;.tag;1

"I" Interface Segregation
http://tv.devexpress.com/#IinSOLID;CTO+Message.tag;1

"D" Dependency Injection
http://tv.devexpress.com/#DinSOLID

Thank you Julian for providing such valuable videos.

HttpWebRequest packet fragmentation?

Anyone of you experiencing STRANGE issues trying to connect to a Java web service –or- to embedded web servers (for instance sms gateways etc) ?

Well it could sound strange, but it happened 2 times in the same week here at my company and on totally different projects.

Basically it appears that if you send a POST using the HttpWebRequest sometimes the packets get fragmented on the IP protocol. This was NOT happening using the “old” XMLHttpRequest object of MSXML!

The actual point is that some web servers DO NOT LIKE the fragmentation. This TCP packet fragmentation introduce a wrong behavior of the web server that receives ONLY PART of the POST you performed. This leads to misunderstanding the actual request… and finally responding to you with errors or wrong behaviors.

It’s very hard to find this problem. The best tools that help understanding what is going on under the hoods are Network Protocol Analyzers such as Wireshark or Ethereal.

Some interesting lectures about that are:

Nagle’s Algorithm is Not Friendly towards Small Requests

If you want to solve the issue, use the following code:

 

Dim url As String = String.Format("http://{0}/smssend.cgi", txtAddress.Text)
Dim wr As HttpWebRequest = WebRequest.Create(url)
Dim msg As String = ".... .... ...."
Dim buffer As Byte() = System.Text.UTF8Encoding.UTF8.GetBytes(msg)

wr.ProtocolVersion = New System.Version(1, 0)
wr.Method = "POST"

System.Net.ServicePointManager.Expect100Continue = False
System.Net.ServicePointManager.UseNagleAlgorithm = False

 

Hope it helps!!

Adriano

WF4: Versioning Definitions

Many times it could happen that you may want to update your definition while you have many workflows already running.

What happens? Well, if you change the definition and then resuming any workflow created with a previous version of the same, then you have 99% probability to get issues/exceptions (Murphy law again!).

This is normal, and I can explain why and how to work around this.

Why?

WF4 introduces a new persistence model which reduces the amount of data to serialize when persisting. This was a great improvement against the previous version of the framework because allows the framework to scale up better than previously.

However, it introduces the versioning issue, because if you added/removed some activities from your definition the persistence engine is not able to understand where to resume your workflow as well as the values of the variables/arguments at that stage.

There is also a logical issue behind that. You can’t assume that the new workflow definition is compatible with the new one.

Workarounds

You need to track all the versions of definitions that have running workflows into a table, for instance, and then provide your custom hosting for the workflow runtime so that you can deal directly with persistence engine and load the right version by your own. I already talked about that here:

https://adrianot75.wordpress.com/2010/11/04/wf4-persisnce-delay-and-execution-resume/

What is going to come

vNext will include Dynamic Updates on workflow resumption to help on this stuff. So the framework is going to provide a way to automate version redirection or definition “upgrade” automatically for you.

However, I guess “upgrading” can’t be done in any case, depends a lot on the kind of change you made. I think that this new feature will fall back to version redirection when not able to perform upgrade.