Skip to content

Instantly share code, notes, and snippets.

@abobija
Last active March 20, 2024 22:35
Show Gist options
  • Save abobija/86d74ecf4f024075862fbdb847a0c6ac to your computer and use it in GitHub Desktop.
Save abobija/86d74ecf4f024075862fbdb847a0c6ac to your computer and use it in GitHub Desktop.
Code written in YouTube video https://youtu.be/q5tOByY1ch4
var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://io.adafruit.com', {
username: 'ADAFRUIT_IO_USERNAME',
password: 'ADAFRUIT_UI_KEY'
});
var ssd1306topic = `${client.options.username}/f/ssd1306`;
client.on('connect', function() {
console.log('connected');
client.subscribe(ssd1306topic, function(err) {
if(! err) {
console.log('subscribed');
client.publish(ssd1306topic, 'Hello from NodeJS');
}
});
});
client.on('message', function(topic, message) {
console.log(message.toString());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment