Skip to content

1. Receive with HTTPS nodes

MichielJol edited this page Sep 9, 2016 · 11 revisions

KPN LoRa requires a server to receive HTTPS messages. In this exercise you will built a basic HTTPS receiver in Node-Red

Setting up your HTTPS Node

  1. In Node Red you can add a HTTPS node by selecting the node under input (left hand-side) and dragging it to your flow editor.
  2. Double click on the node to edit the parameters:
  • Method We should listen to a POST command
  • URL is the destination where the POST messages should be sent to. For instance “/lorapost”
  • Name is the name of the Node, so whatever you like, here I chose “LoRa Post Catcher”
  1. From the HTTPS Node, the post should go somewhere. Select and drag a debug Node from the output nodes. Select the dot on your HTTP node and drag a line towards your debug node to connect the 2.
  • Note: NodeRed passes around J-SON objects called a 'msg'. Every Node receives a msg and does something with it. Usually the msg.payload attribut contains the important data. In case of the HTTPS node it creates a msg object with the msg.payload containing the payload of the post message. The debug tab should therefore show the payload here. It does so automatically, but you can click on the Node to change the parameter you want to see.
  1. In principle you are ready to do your first postmessage. The link to post to is "https://YourNodeRedServer.com/lorapost". If you're using bluemix you can get your NodeRed server adres by copying your browser adress (e.g. **http://yourname.eu-gb.mybluemix.net**/red/#) and changing it to https://yourname.eu-gb.mybluemix.net/lorapost. Important to at the s to the http, this is necessary for KPN LoRa messages.

Sending your first POST message

If you try your url directly in your browser you should get Cannot GET /lorapost. This is because a browser actually uses a GET method and we are using POST. We need to sent a proper POST message. There are several ways to do this, but the one we are going to use here is Postman (up to you of course :))

  1. Go to https://www.getpostman.com/ and follow the instructions to install a chrome app (or the mac version if you have a mac).
  2. Open the app:
  • Set the method in the dropdown menu to POST (probably says GET when opening for the first time).
  • Fill in your URL https://yourname.eu-gb.mybluemix.net/lorapost
  • LoRa Post depend on query parameters, so try some here. Append ?query=example to your URL at the end. Postman nicely opens other edditing options now, but you can ignore that.
  • You should also pass something in the body of the POST message. So click on the body tab below the URL part and type something.
  1. Click on the Send button. Go back to your NodeRed, click on the debugger on the right panel and see if any data has come in. If so, you are in business :)!

Answering the POST

If you now go back to Postman you will see that Postman is still sending (of if you wait to long say something like 502 Bad Gateway: Registered endpoint failed to handle the request.). This is because NodeRed does not answer. You can cancel the request if you look at the bottom of the Postman screen. We want a clean application of course, so let's create a simple answer:

  1. Select the HTTP Response node. In would be enough to connect it directly to your HTTP node, but I like to be able to change the response a bit so let's add some more.
  2. Select a function node. In a Function you can execute Node-JS or JavaScript code to make changes to your msg. Here we want to change the payload to "I have received something!". Adjust your code to do this and return the adjust msg. '''javascript msg.payload = "I have received something!"; return msg; '''
  3. Now hookup the output of the HTTP node to the input of the Function Node and the output of the Function node to the HTTPS reponse node and hit deploy.
  4. Make a post again in postman. You should receive something back now and your data should still be visible in the NodeRed debugger.

Your done with the first exercise. You can now move on to the next one.

Clone this wiki locally