You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					67 lines
				
				1.4 KiB
			
		
		
			
		
	
	
					67 lines
				
				1.4 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								<%@ page language="java" contentType="text/html; charset=UTF-8"
							 | 
						||
| 
								 | 
							
									pageEncoding="UTF-8"%>
							 | 
						||
| 
								 | 
							
								<!DOCTYPE HTML>
							 | 
						||
| 
								 | 
							
								<html> 
							 | 
						||
| 
								 | 
							
									<head>
							 | 
						||
| 
								 | 
							
										<title>测试</title> 
							 | 
						||
| 
								 | 
							
										<%@ include  file="/WEB-INF/oss/base/common/variable.jsp"%>
							 | 
						||
| 
								 | 
							
								    	<%@ include  file="/WEB-INF/oss/base/common/resource_lib.jsp"%>
							 | 
						||
| 
								 | 
							
								    	<%@ include  file="/WEB-INF/oss/base/common/variable_js.jsp"%>
							 | 
						||
| 
								 | 
							
								    	
							 | 
						||
| 
								 | 
							
								    	<script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
									</style>
							 | 
						||
| 
								 | 
							
									</head>
							 | 
						||
| 
								 | 
							
									<body>
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										nihao hello 
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
									</body>
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									<script type="text/javascript">
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
									// 连接选项
							 | 
						||
| 
								 | 
							
									const options = {
							 | 
						||
| 
								 | 
							
									      connectTimeout: 4000, // 超时时间
							 | 
						||
| 
								 | 
							
									      // 认证信息
							 | 
						||
| 
								 | 
							
									      clientId: '426aad8a150a4d85a8fa7221085edca3_21212',
							 | 
						||
| 
								 | 
							
									      username: 'iot2yun',
							 | 
						||
| 
								 | 
							
									      password: 'iot2yun',
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										var client = mqtt.connect('ws://47.107.108.69:8083/mqtt', options)
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
										client.on('reconnect', function(error)  {
							 | 
						||
| 
								 | 
							
										    console.log('正在重连:', error)
							 | 
						||
| 
								 | 
							
										})
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
										client.on('error', function(error) {
							 | 
						||
| 
								 | 
							
										    console.log('连接失败:', error)
							 | 
						||
| 
								 | 
							
										})
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
										client.on('connect', function() {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											client.subscribe('/alarm/iid');
							 | 
						||
| 
								 | 
							
											client.subscribe('/sensor/+');
							 | 
						||
| 
								 | 
							
										})
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										client.on('message', function(topic, message) {
							 | 
						||
| 
								 | 
							
											// message is Buffer
							 | 
						||
| 
								 | 
							
											console.log(topic);
							 | 
						||
| 
								 | 
							
											console.log(message.toString())
							 | 
						||
| 
								 | 
							
								// 			client.end()
							 | 
						||
| 
								 | 
							
										})
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										setInterval( function()  {
							 | 
						||
| 
								 | 
							
											client.publish('/alarm/iid', 'Hello mqtt2 111') ;
							 | 
						||
| 
								 | 
							
										}, 1100);
							 | 
						||
| 
								 | 
							
										
							 | 
						||
| 
								 | 
							
										setTimeout(function() {
							 | 
						||
| 
								 | 
							
											client.publish('/sensor/aa', 'Hello sensor') ;
							 | 
						||
| 
								 | 
							
										}, 1000);
							 | 
						||
| 
								 | 
							
									</script>
							 | 
						||
| 
								 | 
							
									
							 | 
						||
| 
								 | 
							
								</html>
							 |