Thursday, September 28, 2017

ASP.NET Web Api, Twilio Web Hook and Error - 12300 Invalid Content Type

When using Twilio web hook implemented in ASP.NET Web Api, you may get this error

12300 Invalid Content Type

The following page TWIML MESSAGE: YOUR RESPONSE, lead me to the right way to implement the web hook.

public HttpResponseMessage SmsAnswerCallBack(string id)
    var res     = Request.CreateResponse(HttpStatusCode.OK);
    res.Content = new StringContent("<Response/>", Encoding.UTF8, "text/xml");
    return res;

Thursday, May 18, 2017


  • $99 the first month, $39 per month after that. If you cancel and re subscribe you still have to pay $99.
  • Only 100 videos play per month. Each video is about 15 minutes. If you watch a video twice, it is counted twice (Yes).
  • The course "USB Forensics and Pentesting" which is the reason I signed for is good but from 2014. The hardware presented is old, does not work on Windows 64 bit. And there is no update with the new FTDI MCU now released (2017) and mentioned in the video.
  • You also pay for Dr. Philip Polstra sarcasms about Windows versus Linux. I paying for the course, I do not need to hear that.
  • Too much Linux not enough Windows. 
I downloaded up 70 videos about different courses, still have to watch them. So Jury is still out.

But generally speaking too expensive.

Wednesday, April 27, 2016

Friday, April 15, 2016

How to block the windows 10 upgrade

Difficult to believe, but the Microsoft Windows team seems it is ok to trick you to upgrade your Windows 7 machine to Windows 10 without you giving your consent.

 This article from PCWorld and utility from should let you configure your machine to avoid the upgrade.

How to block the windows 10 upgrade

Wednesday, April 13, 2016

Azure Function (JavaScript)

What Is An Azure Function? 

It is the equivalent of the Amazon Lambda. Azure can be written in JavaScript/NodeJs or in C# (Using dynamic C# or ScriptCS syntax). There are different ways to trigger a function
  • On demand via an http (HttpTrigger)
  • Periodically (TimerTrigger)
  • Trigger by blob storage, queue or event hub creation

Learn more : Create Your First Azure Function.
This is the default source code for a Http triggered function.

module.exports = function(context, req) {

    context.log('Node.js HTTP trigger function processed a request. RequestUri=%s', 

    if ( || (req.body && {

        context.res = { 
            status: 200, 
            body: "Hello " + ( || };
    else {

        context.res = { 
            status: 400, 
            body: "Please pass a name on the query string or in the request body" };

Code Structure

Here is my attempt to write a Azure Function and build some re-usable code.
function AzureFunctionBaseClass(context, req) {

    this._context = context;
    this._req     = req;

    this.__terminate = function(m, status) { 

        this._context.res = { status: status, body: m };
    this.succeed        = function(m) {  this.__terminate(m , 200); }           = function(m) {  this.__terminate(m , 400); }
    this.getQueryString = function()  { return this._req.query;           }
    this.getBody        = function()  { return this._req.body;            }
    this.log            = function(s) { this._context.log('[log]%s', s);  }
    this.getParameter   = function(n) { return this.getQueryString()[n];  } = function() {

        var s = "Inherited run "+(new Date());
    this.__init__ = function() {
        this.log("__init__ running");

AzureFunctionBaseClass.create = function(functionType, context, req) {

    var l = new AzureFunctionBaseClass(context, req);, context, req);
    return l;

function MyAzureFunction(context, req) { = function() {

        var s = "Hello " + this.getParameter("name");

module.exports = function(context, req) {

    AzureFunctionBaseClass.create(MyAzureFunction, context, req).run();

How to call the Lambda Function from CURL.exe

C:\Tools\PortableGit\bin>curl.exe -i -X GET "
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 12
Content-Type: text/plain; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Set-Cookie: ARRAffinity=1d89995dbeffc7cc6215c40b5a2e03653fa822c763f464b0126bbb6bc29cc2d8;Path=/;Doma
Date: Wed, 13 Apr 2016 12:54:59 GMT

Hello Freddy

MQTT in Python, C# and JavaScript

MQTT in Python, C# and JavaScript

MQTT is on my horizon for a lot of communication projects, I am going to experiment.
So I am gathering basic samples how to use it in different languages.
  • Python, usefull for Linux and Raspberry PI
  • C#, because I am a PC
  • JavaScrip + Node, usefull if used with Azure Function or Amazon Lambda
  • JavaScript in a Browser


Roughly, what to install on Windows.

  • Download Python 2.7
  • Pip package manager. Download and run pip
    • C:\Python27\python.exe # to install pip
    • Use pip to download the package paho-mqtt
      • C:\Python27\Scripts\pip install paho-mqtt
For more setup info, see page


import paho.mqtt.client as paho
def on_subscribe(client, userdata, mid, granted_qos):
    print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_message(client, userdata, msg):
    print("topic:"+msg.topic+" qos:"+str(msg.qos)+" payload:"+str(msg.payload))
client     = paho.Client()
client.on_subscribe = on_subscribe
client.on_message   = on_message
client.connect("", 1883)
client.subscribe("encyclopedia/temperature", qos=1)


import paho.mqtt.client as paho
import time
def on_publish(client, userdata, mid):
    print("mid: "+str(mid))

client = paho.Client()
client.on_publish = on_publish
client.connect("", 1883)
temperature = 90

while True:
    print("temperature:%d " % temperature)
    (rc, mid)   = client.publish("encyclopedia/temperature", str(temperature), qos=1)
    temperature = temperature + 1


For C# I am using the library M2Mqtt, that can be downloaded from NuGet.
Complere Source Code MQTT CSharp.cs


static void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
    Console.WriteLine("Received = " + Encoding.UTF8.GetString(e.Message) + " on topic " + e.Topic);

const string mqttServer = "";
const string pusblishedVar = "encyclopedia/temperature";

private static void SubscribeAndListen(string CLIENT_ID_SUB)
    MqttClient client;
    Console.WriteLine("Setting up subscribe mode:{0}, clientID:{1}", mqttServer, CLIENT_ID_SUB);
    client = new MqttClient(mqttServer);
    client.MqttMsgPublishReceived += client_MqttMsgPublishReceived;
    client.MqttMsgSubscribed += Client_MqttMsgSubscribed;
    client.Subscribe(new string[] { pusblishedVar }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE });

    var displayMenu = new Action(delegate()
        Console.WriteLine("Q)uit C)lear - Waiting...");
    var quit = false;
    while (!quit)
        if (Console.KeyAvailable)
            switch (Console.ReadKey().Key)
                case ConsoleKey.Q: quit = true; break;
                case ConsoleKey.C: ; displayMenu(); break;


const string mqttServer = "";
const string pusblishedVar = "encyclopedia/temperature";
private static void Publish(string CLIENT_ID_PUB)
    Console.WriteLine("Setting up publish mode ClientID:{0}", CLIENT_ID_PUB);
    var client = new MqttClient(mqttServer);
    var varValue = 70;
    client.MqttMsgPublished += Client_MqttMsgPublished;

    Console.WriteLine("Publishing {0}:{1}", pusblishedVar, varValue);
    client.Publish(pusblishedVar, Encoding.UTF8.GetBytes(varValue.ToString()), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);

JavaScript + Node.js

To install MQTT package
nmp install mqtt


// contoller.js and garage.js
var mqtt = require('mqtt')  
var client = mqtt.connect("mqtt://");//, 1883)

client.on('connect', function() {  

 console.log("Connected, Publishing.");
   // Inform controllers that garage is connected
 client.publish('encyclopedia/temperature', '66')

 * Want to notify controller that garage is disconnected before shutting down
function handleAppExit (options, err) {  
 if (err) {
 if (options.cleanup) {
 if (options.exit) {

 * Handle the different ways an application can shutdown
process.on('exit', handleAppExit.bind(null, {  
  cleanup: true
process.on('SIGINT', handleAppExit.bind(null, {  
  exit: true
process.on('uncaughtException', handleAppExit.bind(null, {  
  exit: true

JavaScript in a browser

MQTT publisher or subscriber can also be hosted in a browser using Websockets. See link

Wednesday, March 16, 2016

Azure VM inbound port to allow SQL server from the internet

To expose a SQL Server instance running in an Azure VM to the internet here how to configure the port.

Also for Reporting Services you need to output port 80 for http.
Turn down the firewall to start

Also follow this link for other steps Provision a SQL Server virtual machine in Azure

SQL Server Management Studio - Script Generation - IF EXISTS

Tools -> Options -> SQL Server Object Explorer -> Scripting -> Check for object existence -> True