PubNub to transfer data to the server

I am creating an IoT application. I use PubNub for communication between harware and the user. Now I need to save all messages and data coming from the hardware and from the user on a central server. We want to learn a little cars.

Is there a way to do this, except that the server subscribes to all output channels (there will be many of them)?

I was hoping for some kind of once-a-day data dump using the storage and playback module in PubNub

Thank you in advance

+4
source share
1 answer

PubNub for server data transfer

Yes, you can perform one-time data dumps associated with the storage and playback function.

! , a.* a.b.*, . , , , : root.chan_1 root.chan_2. root.* .

, , . PubNub . , API , , , .

JavaScript, .

get_all_history({
    limit    : 1000,
    channel  : "my_channel_here",
    error    : function(e) { },
    callback : function(messages) {
        console.log(messages);
    }
});

function get_all_history(args) {
    var channel  = args['channel']
    ,   callback = args['callback']
    ,   limit    = +args['limit'] || 5000
    ,   start    = 0
    ,   count    = 100
    ,   history  = []
    ,   params   = {
            channel  : channel,
            count    : count,
            callback : function(messages) {
                var msgs = messages[0];
                start = messages[1];
                params.start = start;
                PUBNUB.each( msgs.reverse(), function(m) {history.push(m)} );
                callback(history);

                if (history.length >= limit) return;
                if (msgs.length < count)     return;

                count = 100;
                add_messages();
            },
            error : function(e) {
                log(  message_out, [ 'HISTORY ERROR', e ], '#FF2262' );
            }
        };

    add_messages();
    function add_messages() { pubnub.history(params) }
}
+2

Source: https://habr.com/ru/post/1613242/


All Articles