Monday, December 14, 2015

OpenHab and the Adam 60xx module

Now that I have built a pretty good camera security system using the Milestone XProtect software and various IP cameras, I want to take things to the next level.

I have now successfully integrated an Adam 6052 module (Adam 6050 would work as well) with both the XProtect system and a new OpenHab system using the Modbus plugin for the later.  I have looked over multiple smart house technologies and at the moment the OpenHab software seems to be the most flexible and open for integration with multiple vendors.

With this integration I am now able to track when and for how long my doors are opened for using standard cheap NC wired sensors connected to the Adam module.

Tuesday, August 25, 2015

Open Cart upgrade

During a site upgrade of Open Cart from version 4 to version 6 I ran into some problems.  There were of course the normal issues going between two major versions, but I was finally able to overcome those by upgrading first to version 1.4, then to 2.0.

However, I ran into two unexpected issues after successfully reaching version 6.  The first: I was trying to install the pavilion theme and kept running into odd errors.  I was able to resolve these by upgrading to the latest version of the pavilion theme, apparently pavilion does not have its supported version numbers quite up-to-date yet.

The second issue was an unexplained javascript error "Unexpected end of input OK".  I scoured the web, and tried every known fix out there, but none of them worked.  Finally a post here gave me the needed suggestion to turn on error displaying, which is a setting found in the store settings.  Once that was turned on I got an error written to the screen that made a lot more sense and told me I had forgotten to include a new constant variable in the config file.  I fixed that and everything was working good again.

Note: in the settings table is a new category type column called code I believe.  This new column needs to be updated with the values from the old column, none of the upgrade scripts do this.

Wednesday, June 3, 2015

.NET Rounding Error

A recent project of mine was creating a custom reporting engine in .NET since all of the commercial ones were either too expensive or not flexible enough for the projects requirements.  After creating the engine the natural next step was writing reports to run on it; it was during this process that I found a very interesting error in .net 4.

.NET apparently handles calculations differently depending on whether or not they are implicit or explicit.  For example if you were to run this statement:

If( 3 < (0.6F / 0.2F ))

you would expect .net to do the float calculation, then either cast the integer to a float, or round the float to an integer and perform the calculation.  Apparently it does not as the statement above always evaluates to true, when in reality it is false since the integer 3 is the same value as the float 3.0.  My guess is when performing the division there is some sort of math error in the .net engine which results in something like 3.0000000000000000000001 for 0.6F / 0.2F

The solution to this issue is to explicitly force trimming like this:

Int f = (int)(0.6F / 0.2F)
If( 3 < f )


The above statement casts the float calculation to an integer effectively truncating the extra floating data and allowing a correct comparison.  A better solution would probably be to use Math.Round just in case .net decides to evaluate the calculation to just under 3 rather than just over it.

Friday, March 6, 2015

ELEC new wireless talk camera

ELEC has recently come out with a new wireless camera that allows you to talk out of it.  Considering it is only $40 it is far cheaper than any other competition with that feature so I thought I would try it out.  Unfortunately I was in for a big disappointment.

I was initially pretty disappointed that it lacks an RJ45 port to configure it with, i'm guessing it uses bluetooth or it's own wifi hotspot for initial configuration, either way it requires you to download their app onto your phone for initial configuration.  This is the first camera I have seen that does not have an ethernet port, a big shortcoming in many ways in my opinion.

The web interface for it is viewing only, no configuration changes, which means I need to use my phone for any administrative changes which I do not like.

Their software has a spot for a static IP address, but when I tried to put one in it would not save.  After contacting their support I was told it only supports DHCP.  Another huge shortcoming.  Granted you could put a static reservation in your router for it, so I could live with this if I had to.

Support for elec on the web does not exist yet, so if you get one you will be relying on blog posts like this one, your own whit, or on their support support@eleccctv.com which sometimes responds and sometimes does not.  If they do respond you have to ask only one simple little question at a time, they don't seem to be able to actually read emails.

I had a momentary spark of hope when I attempted adding it to my XProtect system as a generic OnVif device and it was actually recognised.  Unfortunately, XProtect completely loses connection with it if the microphone is enabled (I have covered that issue in my post about dlink products), and still loses connection for a couple of seconds every 30 seconds or so even with the microphone disabled.  I'm not sure who's fault that is just yet. (see below for fix)

Unless I get some more of these issues figured out I will not be buying another Model: EL -Wini001 720P wifi security camera.

----------
Edit: Using wireshark I was able to get the url for the video feed as rtsp://xxx.xxx.xxx.xxx/live0.264?user=admin&passwd=Password

Using that I setup a Universal driver in XProtect with:
Codec: H264
Streaming Mode: RTP (UDP)
Keep alive: Default
Connection URI: live0.264
RTSP port: 554

So far I have not lost connection to the camera, as long as the microphone is disabled in XProtect.  Wireshark indicates that the audio is G.711 PCMU, however I have not gotten that to work yet.  At least this camera is not a total loss anymore, if I could get the audio to work I think I would even call it a decent camera.  At 1280 x 720 the video quality is definitely far superior to what the dlinks offer.

The connection URI seems to be live0.264 or live1.264 depending on which of the two feeds the camera offers you want to tap into.

UPDATE:
It looks like I was able to get the OnVif to work for this camera.  For some reason changing some things in the config resets the cameras protocol from RTP/UDP to RTP/RTSP/HTTP/TCP.  Simply changing that setting back again to RTP/UDP fixes the issue and the camera works great.

Tuesday, February 24, 2015

Overlapping Columns in Microsoft ASP.NET Chart controls

I was recently tasked with creating a reporting solution that generated column style graphs.  However, there was a twist, the various series in the graphs had to be partially overlapping.

There are lots of solutions available for fully overlapping, stacked, or side-by-side.  But partially overlapping seemed to be missing from all of the posts I found.  Very few people were even asking the question of how to do it, although I did find one post that never got answered.

After much searching, and hours of trying different solutions, I finally found a post that gave me some added information regarding Chart Areas that I was missing.  However, this post cautioned that if one chart area had tick marks and labels while another did not then there was no way to get the axis lines to match up.  Considering I ended up being successful in my endeavours I am not entirely sure what that comment was referring to.

Using this code:
    Chart chrt = new Chart();
    chrt.ChartAreas.Add("ChartAreaRed");
    chrt.ChartAreas["ChartAreaRed"].BackColor = System.Drawing.Color.Transparent;
    chrt.ChartAreas["ChartAreaRed"].Position.Height = 100;
    chrt.ChartAreas["ChartAreaRed"].Position.Width = 100;
    chrt.ChartAreas["ChartAreaRed"].InnerPlotPosition.Height = 90;
    chrt.ChartAreas["ChartAreaRed"].InnerPlotPosition.Width = 80;
    chrt.ChartAreas["ChartAreaRed"].InnerPlotPosition.X = 10;
    chrt.ChartAreas["ChartAreaRed"].AxisY.Maximum = 6;
    chrt.ChartAreas["ChartAreaRed"].AxisX.Maximum = 5;
    chrt.ChartAreas["ChartAreaRed"].AxisX.Interval = 1;
    chrt.ChartAreas["ChartAreaRed"].Position.X = 0;
    chrt.ChartAreas.Add("ChartAreaGreen");
    chrt.ChartAreas["ChartAreaGreen"].BackColor = System.Drawing.Color.Transparent;
    chrt.ChartAreas["ChartAreaGreen"].Position.Height = 100;
    chrt.ChartAreas["ChartAreaGreen"].Position.Width = 100;
    chrt.ChartAreas["ChartAreaGreen"].InnerPlotPosition.Height = 90;
    chrt.ChartAreas["ChartAreaGreen"].InnerPlotPosition.Width = 80;
    chrt.ChartAreas["ChartAreaGreen"].InnerPlotPosition.X = 10;
    chrt.ChartAreas["ChartAreaGreen"].AxisY.Maximum = 6;
    chrt.ChartAreas["ChartAreaGreen"].AxisX.Maximum = 5;
    chrt.ChartAreas["ChartAreaGreen"].AxisX.Interval = 1;
    chrt.ChartAreas["ChartAreaGreen"].Position.X = 0;
    chrt.ChartAreas["ChartAreaGreen"].Axes[0].Enabled = AxisEnabled.False;
    chrt.ChartAreas["ChartAreaGreen"].Axes[1].Enabled = AxisEnabled.False;
    chrt.ChartAreas.Add("ChartAreaBlue");
    chrt.ChartAreas["ChartAreaBlue"].BackColor = System.Drawing.Color.Transparent;
    chrt.ChartAreas["ChartAreaBlue"].Position.Height = 100;
    chrt.ChartAreas["ChartAreaBlue"].Position.Width = 100;
    chrt.ChartAreas["ChartAreaBlue"].InnerPlotPosition.Height = 90;
    chrt.ChartAreas["ChartAreaBlue"].InnerPlotPosition.Width = 80;
    chrt.ChartAreas["ChartAreaBlue"].InnerPlotPosition.X = 15;
    chrt.ChartAreas["ChartAreaBlue"].AxisY.Maximum = 6;
    chrt.ChartAreas["ChartAreaBlue"].AxisX.Maximum = 5;
    chrt.ChartAreas["ChartAreaBlue"].AxisX.Interval = 1;
    chrt.ChartAreas["ChartAreaBlue"].Axes[0].Enabled = AxisEnabled.False;
    chrt.ChartAreas["ChartAreaBlue"].Axes[1].Enabled = AxisEnabled.False;

    chrt.ChartAreas["ChartAreaBlue"].AxisX.MajorGrid.Enabled = false;

    Series chrtS_Red = new Series();
    chrtS_Red.Points.Add(new DataPoint(2, 1));
    chrtS_Red.Points.Add(new DataPoint(3, 0));
    chrtS_Red.Points.Add(new DataPoint(4, 2));
    chrtS_Red.ChartType = SeriesChartType.Column;
    chrtS_Red.Color = System.Drawing.ColorTranslator.FromHtml("#aa220d"); // massini red
    chrtS_Red.IsValueShownAsLabel = true;
    chrtS_Red.EmptyPointStyle.IsValueShownAsLabel = false;
    chrtS_Red["PointWidth"] = ".5";
    chrtS_Red["LabelStyle"] = "TopLeft"; // Auto, Top, Bottom, Right, Left, TopLeft, TopRight, BottomLeft, BottomRight, Center
    chrtS_Red.ChartArea = "ChartAreaRed";
    chrt.Series.Add(chrtS_Red);

    Series chrtS_Green = new Series();
    chrtS_Green.Points.Add(new DataPoint(2, 0));
    chrtS_Green.Points[0].IsEmpty = true;
    chrtS_Green.Points.Add(new DataPoint(3, 5));
    chrtS_Green.Points.Add(new DataPoint(4, 0));
    chrtS_Green.Points[2].IsEmpty = true;
    chrtS_Green.ChartType = SeriesChartType.Column;
    chrtS_Green.Color = System.Drawing.ColorTranslator.FromHtml("#94952d"); // massini green
    chrtS_Green.IsValueShownAsLabel = true;
    chrtS_Green.EmptyPointStyle.IsValueShownAsLabel = false;
    chrtS_Green["LabelStyle"] = "TopLeft"; // Auto, Top, Bottom, Right, Left, TopLeft, TopRight, BottomLeft, BottomRight, Center
    chrtS_Green["PointWidth"] = ".5";
    chrtS_Green.ChartArea = "ChartAreaGreen";
    chrt.Series.Add(chrtS_Green);

I was able to produce this graph:

Overlap with Chart Areas



While it is definitely complex and difficult to understand, once you do understand it it allows for a great deal of control. The key is setting all the Chart Areas width and heights to the same values, then doing the same with the InnerPlotPosition attributes.

The InnerPlotPosition allows you to control the area inside the plot area that is dedicated to plotting the values rather than having the grid lines and values included in the width and height calculations.

You have to set a value for both the width and the height for InnerPlotPosition or else a default of 0 will be used and you will see nothing.

Also, if you intend to have grid lines or X and Y axis values then you will need the width and height values for InnerPlotPosition to be less than 100 to allow for room inside the Chart Area for those items, or else they will be hidden.

Finally, when using layers, make sure you set all the backgrounds to transparent or you will only see the last layer added. If you want a background then apply it to the first layer.

Tuesday, January 6, 2015

Add DLink DCS-932L cameras to Milestone's XProtect Go software

Problem

I've been trying to get some of my low end DLink cameras to work with XProtect Go. I have been successful getting their feeds in iSpy, BlueIris, VLC, and the D-ViewCam. However, for some reason I could not get them to work with XProtect.

After trying many different settings, and searching the web for hours, I finally decided to try Wireshark. I am no expert with wireshark by any means, but it seemed to me that XProtect was failing to add the correct port to the request URL even though I had specified a port when setting up the camera. So I tried setting the port back to port 80 on the camera itself, but it seemed to have no effect.

In XProtect I have tried many combinations, and during the wireshark test was trying (turns out it does work):

Code: JPEG
Streaming Mode: HTTP
Delivery Mode: Multipart stream
Retrieval mode: Snapshot
Connection URI: mjpeg.cgi

I realise these are two different IPs, I was capturing data using two different cameras to make it easier to filter through the results in Wireshark. However, all the cameras work with BlueIris. (Yes I changed IPs and passwords for this post)

XPROTECT (Doesn't Work):
GET /mjpeg.cgi HTTP/1.1\r\n
User-Agent: HTTP Image Reader\r\n
Connection: Keep-Alive\r\n
User-Agent: HTTP Image Reader\r\n
Authorization: Basic YWRtaW46==\r\n
Credentials: admin:password
Full request URI: http://192.168.1.17/mjpeg.cgi

BLUEIRIS (Works):
GET /mjpeg.cgi HTTP/1.1\r\n
User-Agent: BlueIris\r\n
Connection: Keep-Alive\r\n
Authorization: Basic YWRtaW=\r\n
Credentials: admin:password
Full request URI: http://192.168.1.18:818/mjpeg.cgi

Solution

After doing more research on the web and pouring over other people's posts with the same problem I finally found the solution.

It turns out there are quite a few settings that actually do work with XProtect. However, XProtect does seem to have a flaw in that it cannot correctly pass authentication to the DLink camera.

The biggest change I needed to make was turning off UAC as this post suggested. It is found on the Maintenance tab of the DCS-930L and DCS-932L cameras under Server Settings, it is called User Access Control. By disabling this feature I believe you are turning off the ability to have multiple user accounts on the camera itself, a nice feature being lost, but in my case I can live without it.

Once that change has been made on the camera, specific ports do seem to work just fine. Specific ports are nice if you want direct access to the cameras through your firewall, in my case so the DLink mobile app doesn't time out.

The Settings in XProtect that I have found to work the best are:
Codec: JPEG
Streaming mode: HTTP
Delivery mode: Non multipart stream
keep alive type: Default (greyed out)
Retrieval mode: Snapshot
Connection URI: image/jpeg.cgi

These settings seem to provide a more consistent network stream when viewed in wireshark:
Codec: JPEG
Streaming mode: HTTP
Delivery mode: Non multipart stream
keep alive type: Default (greyed out)
Retrieval mode: Streaming
Connection URI: video.cgi

Other delivery modes, retrieval modes, and URI's do work, however the ones I tried caused a great deal of jerkiness to be introduced into the stream.

Notes

Edit: I am using the Universal 1 channel driver in XProtect.  Also, DCS-932L and 930L cameras are NOT ONVIF compatible , nor do they support RTSP streams.  If you want the technical details on how to use the XProtect universal driver you can find them in their KB article 197.

Edit2: I ran into an issue where the cameras were flashing, or not connecting at all in the smart client.  I had to disable the microphone on the server side to fix this issue.  I have not configured it yet, perhaps when correctly configured it will not be an issue.

Edit3: I have noticed that when the microphone is enabled that the video stream slows up quite a bit, but if I use the jpeg snapshots refresh speed is still quite good.  The downside is that the snapshots take up easily 3 times the space and bandwidth.