App server not receiving mesasges

Hiya, hope you can help me. I’ve got a device that successfully sends messages to the sandbox, and now I’ve created my own app server as per the step by step instructions https://www.thingsconnected.net/support/#step-2_5

I can see messages are getting from the device to the dashboard, but I am seeing nothing on my app. I think the node.js script is as per instructions but maybe there’s something else I need to do that I’ve missed?

Node.js script is:

/* Things Connected - test app */

/* Purpose - to read data from hotspot06 (pi) /
/
next step is to feed it into hotspotdb */

const jayson = require(‘jayson’);
const atob = require(‘atob’);
const cors = require(‘cors’);
const jsonParser = require(‘body-parser’).json;
const btoa = require(‘btoa’);
const fs = require(‘fs’);
const connect = require(‘connect’);
const app = connect();

/* Set up log file */
var date=new Date().toISOString().replace(/T/,’’).replace(/-/g,’’).replace(/:/g,’’).replace(/.+/,’’);
var filepath=’./log_data
’+date;

/* Create the server, implement the up/down link methods /
var server = jayson.server({
uplink: function(args, callback) {
/
Print out the uplink message received from the Everynet Network
* on the console and append it to the log file. /
console.log("Received uplink: " + JSON.stringify(args, null, 4) + “\n”);
fs.appendFile(filepath, "Received uplink: " + JSON.stringify(args, null, 4) + “\n”);
/
Get the payload (base64 encoded), which includes actual data
* sent by the device, convert it to ASCII format, print it out
* on the console and append it to the log file.
* We assume the device is sending a string. /
var buffer = new Buffer(args.payload, ‘base64’);
console.log("Payload: " + buffer.toString(‘ascii’) + “\n”);
fs.appendFile(filepath, "Payload: " + buffer.toString(‘ascii’) + “\n”);
callback(null, “200”);
},
downlink: function(args, callback) {
/
Print out the downlink message received from the Everynet Network
* on the console and send back an ACK, which will then be sent to
* the device. */
console.log("Received downlink: " + JSON.stringify(args, null, 4));
var reply = {
payload: btoa(“ACK”)
};
callback(null, reply);
}
});

app.use(cors({methods: [‘POST’, ‘GET’]}));
app.use(jsonParser());
app.use(server.middleware());
app.listen(9090);

Grateful for any guidance :slight_smile:

Hey Mark,

code looks fine to me.
Where do you host the script? Can you send me the endpoint you use so I can double check whether it can be reached by the server properly?

Thanks,
Ben

Hi Ben, I host it on my server which lives in a datacentre in Reading. http://thingitude.com

Hi Ben, I host it on my server which lives in a datacentre in Reading. http://thingitude.com/ http://thingitude.com

If I run netstat on my server it shows node as listening on 9090

Hey Mark,

while I can reach thingitude.com on port 80 I don’t seem to get anything on port 9090
Can you make sure your firewall (and whatever else is inbetween such as a load balancer if applicable) allows inbound traffic on port 9090?

Alternatively it might be easier to use port 80 (on it’s own subdomain perhaps?)

Hi Ben,

I have started up the node.js script so it should be listening on port 9090 now.

Mark

Ha, that would explain why I couldn’t reach it!
I can indeed reach it now.

I was so free and had a quick look at the setup on thingsconnected.
Make sure to include the port when you create the application, e.g. yours would be http://thingitude.com:9090 now rather than just http://thingitude.com

Let me know whether that solves the issue for you!

  • Ben

That works a treat - thanks Ben!