The community forums are in BETA and closed to the public.

Interpreting Format of data received via Pubnub Developer Console

Hi, I'm sending data from a mobile app in Corona. I can see it coming in through the PubNub Developer Console. The data looks like this:

Mon Dec 15 2014 06:51:10:944 :<z> [5551212,1161.316,282]
Mon Dec 15 2014 06:51:10:860 :<z> y [5551212,1160.944,283]
Mon Dec 15 2014 06:51:10:708 :<z> [5551212,1160.368,283]
Mon Dec 15 2014 06:51:03:881 :<z> [5551212,1132.772,193]
Mon Dec 15 2014 06:51:03:796 :<z> [5551212,1132.752,193]

I don't know how to interpret this in terms of what is being received. I need to parse this data and print it to screen via javascript node.js. Am I parsing the date, , etc?

If someone could show me in a few lines of code how to print the array data to screen.

I need to insert the above data to a database, probably PostgresSQL. If subscribe to chanel z is what is being received simply the array, no date, no ?

Guy, This more depends on the format of the message you are sending and less on the way dev console displays data. The dev console is dong extra work to present the data after it is received.

That z in the angle brackets is the channel and that is just an argument of the callback. Dev Console is just formatting all the data from the parameters that are passed in to that callback.

I publish {"text":"hey"} on channel cvc from the Dev Console, it will receive it and display it as 'Mon Dec 15 2014 13:31:21:258 : {"text":"hey"}', but the message part is only what was originally sent which is the message parameter (the first parameter) of the callback. The timetoken and channel can be pulled from the other parameters.

But if you include the other two parameters, channel & envelope, then you can extract the channel name and timetoken from there. Here is an example of a subscribe call taking advantage of all the parameter:

    channel: 'cvc',
    message: function(msg, ch, env){
  • The msg will be exactly what you sent in the format that you sent it.
  • The ch will just be the channel name (a string) that the message was received on.
  • The env will be an array that contains the msg (or messages if there were multiple messages bundled do to windowing or message-catch-up) in element 0 and the timetoken will be in element 1 of this array.

I hope that helps a bit to get you started on your node code.

Comments to this discussion are now closed!