Sending and Receiving data to pubnub website - javascript

How to send database data to pubnub and how to receive data from pubnub website for live data streaming
Its not clearly.

Not sure what the actual question is here but I'll attempt to address it.
PubNub is not really a website, it's a realtime network service with serverless Functions that can process the messages that are published through that network.
You send data to the PubNub using the publish or fire API. You receive data using the subscribe API. You just need to pick a PubNub SDK (there's over 70 to choose from) to implement your app using these APIs. Here's the JavaScript SDK for example. Put Functions aside for now and concentrate on the publish/subscribe part first.
Also, you might want to review How PubNub Works docs to understand what PubNub is (and is not) and what it can do for your applications you use it in.

Related

Connecting AWS MQTT via websocket

I am trying to connect a sensor to an AWS MQTT Broker to a database that will send it to a webserver so that it can be easily accessible. Right now the only way people in our lab can have access to our sensor data is through contacting me directly and having me connect to the Node Red dashboard. Would there be any way for everyone to have access to the data via WebSocket, or at least a couple of people?
I've searched for hours on end and have had no success regarding the ease of accessibility.
From what I've researched there is this a java based client called MQTT.Cool that can connect multiple brokers and have data published via WebSocket using JavaScript. However there is literally no data available except the ones provided by the company. So combining it it with my project has not been an easy task.
Also, I've thought about allowing my node red dashboard to be accessed out of my local
ip-address, but due to security reasons it has been recommended not to be done.
AWS IoT provides an SDK that you can use in your browser:
https://github.com/aws/aws-iot-device-sdk-js#browser
You can write a web application and view the contents returned by the database after logging in
If you need to browse in real-time, you can use mqtt.js to subscribe to some topics:
https://www.emqx.com/en/blog/connect-to-mqtt-broker-with-websocket
Or use MQTTX, a client tool, to connect directly to the MQTT broker and subscribe to topic

How push notification works on every browsers when the website is closed?

I want to show the latest news of website in a notification on every browser when the website is opened or closed.
May I know how to implement the process? Which push api I need to use ? What is the procedure ?
In order to add push notifications to your site, you'll need to understand which technology/API is used for communicating between the client and server even the browser is closed. The Service Worker API allows this and you'll need to add a service worker to your site for push notifications to work.
Service workers essentially act as proxy servers that sit between web applications, the browser, and the network (when available). They are intended, among other things, to enable the creation of effective offline experiences, intercept network requests and take appropriate action based on whether the network is available, and update assets residing on the server. They will also allow access to push notifications and background sync APIs.
Source: MDN - Service Worker API
NOTE: In order for a Service Worker to work, your website needs to be secure and run on https:// For local development, this is not a requirement.
Once you have the Service Worker running, you'll need to register the user for accepting push notification. This allows the server to send messages to the client. Have a look at Push Notifications: What are they and how do I send them? to gain a better understanding of this process.
As this topic is quite brought and there are a lot of moving parts that you need to understand, I'd suggest to get familiar with Service Workers and Push Notifications through tutorials and articles. Here are a few free resources that I found helpful.
Service Workers - an Introduction
Offline Web applications
Service Workers: Push Notifications
Set Up a JavaScript Firebase Cloud Messaging Client App

Azure service hub automatically receive message in javascript

I'm very new in Azure. Is there any way to receive messages from queue/topic automatically instead of making some kind of cron mechanism which will be making requests for new messages? This kind of functionality is available in RabbitMQ client.
The question is a bit vague... In C# SDK there is OnMessage callback that you can sign up to, see docs and a full example in C#.
For a fully automated serverless way of handling messages, have a look at Azure Functions Service Bus Trigger. It's based on WebJobs SDK which you could use directly in self-hosted apps.

Send data from web to a local server

I am working on a home automation hub -- a Raspberry Pi running locally that displays weather info, controls my lights, etc. It is "networked" (and I use that term loosely) to a website via a shared MongoDB. Both the site and the hub are running Node.js/Express servers.
Essentially, I am looking to be able to enter text into a field on my website and then display it on my hub.
I'm struggling to figure out how to pass data between them. I can think of a couple ways that might get it done, but the only way I know I could get working is to implement some sort of Mongo watcher/listener to watch for changes on a specific collection. Essentially, you enter the text into the site, that updates the document in Mongo, the watcher informs the locally-running hub, which then fetches and displays the new content.
This seems hacky. Is there a better way? Is this something socket.io could manage? Maybe I'm overthinking it? Help!
You can use Socket.io, WebSocket or TCP socket to connect the two servers together and communicate that way. Or you can use a queue system like ZeroMQ or RabbitMQ and communicate that way. Or you can even make an HTTP request from one server to the other one every time you want it to grab new data - or you could even sent that data right in the request.
It would be much easier if you used Redis that supports pub/sub, see:
https://redis.io/topics/pubsub
or CouchDB that supports the changes feed:
http://docs.couchdb.org/en/2.0.0/api/database/changes.html
or RethinkDB that supports changefeeds:
https://rethinkdb.com/docs/changefeeds/javascript/
I don't think Mongo supports anything like that.

Hide 3rd party API-key with firebase

Im building a website in firebase. It's a simple look-up service which only has an input element that fires a request to a 3rd party api.
www.3rdparty.com/api/[myapikey]/method
The problem is that I'm limited to x requests per second and I can't expose my api-key to the users.
My mission eventually is to store the responses in firebase so that I can limit the number of requests that reach the 3rd party (a cache function)
Putting such an API key into the client-side code of your application introduces the risk of malicious users taking your key and using it to their own purposes. There is nothing you can do about that, except for simply not including the API key into the client-side code. This applies equally to Android and iOS code btw.
Since you can't put the API key in client-side code, you'll have to run it on a server. This is a quite common scenario for using server-side code within a Firebase architecture: the code needs access to some information that common clients cannot be trusted with. It is covered by pattern 2 in our blog post on common Firebase application architectures.
From that blog post:
An example of such an architecture in action would be clients placing tasks for the server to process in a queue. You can have one or more servers picking off items from the queue whenever they have resources available, and then place the result back into your Firebase database so the clients can read them.

Categories

Resources