Last active
March 20, 2024 22:35
-
-
Save abobija/86d74ecf4f024075862fbdb847a0c6ac to your computer and use it in GitHub Desktop.
Code written in YouTube video https://youtu.be/q5tOByY1ch4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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