Connecting and testing your service with IOT Originating messages

  • Just some pointers to get you started with collecting the subscribe events:


    • Send messages directly to an application server via OceanConnect (OC).


    • assume you already are able to send a hello world
    • assume you are already a bit familiar with the OC API


    • Create a demo CGI script that will collect notifications.
    • Subscribe to events on the OC platform.

    Create a demo CGI script that will collect notifications.

    After you have instructed the OC server to publish "device events" to a callback URL it will try to deliver these messages to the specified server.

    Here is an example of a perl CGI script that will collect these events:
    (Of course you may use your own solutions, this is just example code)

    This script can for example be placed in the cgi-bin directory of your webserver of choiche.

    For our demo purposes this script is located at: http://www.myserver.iot/cgi-bin/nbiot.cgi

    use strict;
    my $ret = "Status: 404 Not Found\r\n\r\n";
    # Only respond if the request is comming from the OC server and is a POST.
    goto end if $ENV{REMOTE_ADDR} ne '';
    goto end if $ENV{REQUEST_METHOD} ne 'POST';
    # Concatenate the json string in a log file.
    my $buffer;
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    # For Get Method   $buffer = $ENV{'QUERY_STRING'};
    open(my $fh, '>>', '/tmp/nbiot.log') or die "open $!";
    print $fh $buffer, "\n";
    close $fh;
    # Send the data over a UNIX socket to some other process for handling. 
    use IO::Socket::UNIX;
    my $client = IO::Socket::UNIX->new(
            Type => SOCK_STREAM(),
            Peer => '/tmp/nbiot.sock',
    $client->print($buffer, "\n") if $client;
    $ret = "Status: 200 OK\r\n\r\n";
            print $ret;

    Notifications from the OC platform will look like this:


    The "rawData":"aG9p" is formated as a base64 string.


    Subscribe to events on the OC platform.

    Next, after jou have made sure your script is reachable from the outside, jou can subscribe to the platfrom:

    Where the notifyType can be one of:
    deviceAdded deviceInfoChanged deviceDataChanged deviceDeleted deviceEvent messageConfirm commandRsp serviceInfoChanged

    And callbackurl in this case would be: 'http://www.myserver.iot:80/cgi-bin/nbiot.cgi'

    See the postman documentation in the link below and select Bind Applicatioon

Log in to reply

Looks like your connection to INTERNET OF THINGS was lost, please wait while we try to reconnect.