Connecting and testing your service with IOT Originating messages


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

    Goal:

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

    Peparation:

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

    Steps:

    • 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

    #!/usr/bin/perl
    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 '160.44.192.209';
    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";
    end:
            print $ret;
    1;
    

    Notifications from the OC platform will look like this:

    {"notifyType":"deviceDataChanged","deviceId":"xxxxx","gatewayId":"xxxxx","requestId":null,"service":{"serviceId":"RawData","serviceType":"RawData","data":{"rawData":"aG9p"},"eventTime":"20171205T050505Z"}}'
    

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

    Next:

    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
    part-vi-using-data-reporting


Log in to reply
 

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