Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>MQTT Client</title>
		<script src="https://unpkg.com/[email protected]/dist/mqtt.min.js"></script>
		
	</head>
	<body style="text-align:center;">
    <button onclick="led('on')">Led On</button>
		<button onclick="led('off')">Led Off</button>

		<div style="color:red;font-size:22px;margin-top:20px;">
			<div><strong id="led"></strong></div>
			<div id="new-user" ></div>
			<div id="temp"></div>
		</div>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                //console.log(mqtt);

			//Nodejs de publish gonderiyor, topic havuz

      //Websocket bağlantısı kurma
			//var client = mqtt.connect('ws://localhost:3009');//local
			var client = mqtt.connect('ws://104.248.196.221:3009');//Servera bağlanma

			client.subscribe('new-user');
			client.subscribe('TEMP');//Dinliyoruz
			client.subscribe('led');//led butonların aboneliği dinliyoruz

			client.on('connect', function() {
				console.log('connected!');

				client.publish('new-user', 'From Browser Client');
			});

			// Yeni mesaj geldiğinde bilgilenmemizi sağlıyor
      client.on('message', function(topic, message) {
				console.log(topic, ' : ', message.toString());
				//alert('topic: '+topic+" Mesaj: "+message.toString());

				//Hangi topicten geliyor onu yakalıyoruz
				switch (topic) {
					case "led":
						//console.log(message.toString());
						document.getElementById('led').innerHTML = message.toString();
						break;
					case "TEMP":
						document.getElementById('temp').innerHTML = message.toString();
						break;
					case "new-user":
						document.getElementById('new-user').innerHTML = message.toString();
						break;
					default:
				}

			});

      function led(value) {//Butonlara tıklandiğı içindeki verileri client ve servera gonderdik
        //alert(value);
				client.publish('led', value);
			}
/*
//Serverjs tarafi
var mosca = require('mosca');//Moska modülünü çagıriyoruz

var settings = {//Dinleyecegımiz portu belirliyoruz
  port: 1883,
  http: { port:3000 }
};

var server = new mosca.Server(settings);//Servere kurmak için ayağa kaldırdık

//Kurduğumuz servera clientler girdimi yakalıyoruz
server.on('clientConnected', function(client) {
    console.log('client connected', client.id);
});

//Çıkış yaptığını algılıyoruz
server.on('clientDisconnected', function(client) {
    console.log('client disconnected', client.id);
});

// mesajlaşma veri gonderme alma
server.on('published', function(packet, client) {
  console.log('Published', packet.payload.toString());
});

server.on('ready', setup);

// fired when the mqtt server is ready
function setup() {
  console.log('Mosca server is up and running');
}

//ClientJs tarafı
var mqtt = require('mqtt');
var client = mqtt.connect('mqtt://127.0.0.1:1883');

client.subscribe('new-user');
client.subscribe('led');//led butonların aboneliği

client.on('connect', function() {
	console.log('connected!');

  client.publish('new-user', 'İsmail-' + Math.ceil(Math.random() * 10));
});

//Gelen MEseajları dinleme
client.on('message', function(topic, message) {
	console.log(topic, ' : ', message.toString());
});
*/
              
            
!
999px

Console