Skip to content

Instantly share code, notes, and snippets.

@azureru
Last active May 27, 2017 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azureru/5d23bf3662f903754c53196ff220bfc3 to your computer and use it in GitHub Desktop.
Save azureru/5d23bf3662f903754c53196ff220bfc3 to your computer and use it in GitHub Desktop.
Node-red Dyndns using digitalocean
// the node-script
var request = global.get('request');
var accessToken = "YOURACCESSTOKEN";
var domain = "YOURDOMAIN";
var record = "YOURDNSRECORD";
var ip = msg.payload;
var options = {
method: 'PUT',
url: 'https://api.digitalocean.com/v2/domains/'+ domain +'/records/' + record,
headers: {
'User-Agent' : 'request',
'Content-Type' : 'application/json',
'Authorization' : 'Bearer ' + accessToken
},
body : '{"data" : "'+ip+'"}'
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
// no error - update successfull
node.status({fill:"green",shape:"dot",text: ip});
node.send({payload : body});
} else {
node.status({fill:"red",shape:"dot",text: 'Error'});
}
});
return;
{
// add this to your config/setting. don't forget to npm install these modules first
functionGlobalContext: {
os:require('os'),
request:require('request'),
cheerio:require('cheerio'),
async:require('async')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment