SlideShare une entreprise Scribd logo
1  sur  17
Télécharger pour lire hors ligne
아두이노(Arduino)는 오픈소스를 기반으로 한 단일 보드
마이크로 컨트롤러이다.
AVR을 기반으로 한 보드로 이루어져 있고 최근에는
Cortex-M3를 이용한 제품(Arduino Due)도 있다.
소프트웨어 개발을 위한 통합 환경(IDE)이 있다.
아두이노는 다수의 스위치나 센서로부터 값을 받아들
여, LED나 모터와 같은 외부 전자 장치들을 통제함으로써
환경과 상호작용이 가능한 물건을 만들어낼 수 있다. 또
한 플래시, 프로세싱, Max/MSP와 같은 소프트웨어를 연
동할 수 있다.[3]
아두이노의 가장 큰 장점은 마이크로컨트롤러를 쉽게 동
작시킬 수 있다는 것이다. 일반적으로 AVR 프로그래밍이
WinAVR로 컴파일하여, ISP장치를 통해 업로드를 해야하
는 등 번거로운 과정을 거쳐야하는데 비해, 아두이노는 컴
파일된 펌웨어를 USB를 통해 업로드를 쉽게 할 수 있다.
또한 아두이노는 다른 모듈에 비해 비교적 저렴하고, 윈도
를 비롯해 맥 OS X, 리눅스와 같은 여러 OS를 모두 지원
한다. 아두이노 보드의 회로도가 CCL에 따라 공개되어 있
으므로, 누구나 직접 보드를 직접 만들고 수정할 수 있다.
• 통신 방식 : RS-232 Serial via USB
• 패킷 : [전체][빨강][노랑][초록]nr
• 0 : 그대로
• 1 : 끄기
• 2 : 켜기
https://github.com/theRichu/node_arduinio_example/blob/master/arduino/device.ino
$ npm update
$ npm install –g express
$ npm install -g express-generator
$ express server
$ cd server
$ npm install
$ npm start• http://localhost:3000
app.get('/', function (request, response) {
fs.readFile('index.html', function (error, data) {
response.send(data.toString());
});
});
https://github.com/theRichu/node_arduinio_example/blob/master/node_arduino_example/public/index.html
$ npm install serialport
var serialport = require("serialport");
var SerialPort = serialport.SerialPort;
var sp = new SerialPort("/dev/ttyACM1", {
baudrate: 9600,
parser: serialport.parsers.readline("n")
});
var onoff = 0;
var state_r = 0;
var state_y = 0;
var state_g = 0;
sp.on("data", function (data) {
onoff = data[0];
state_r = data[1];
state_y = data[2];
state_g = data[3];
io.sockets.emit('status', { "onoff": onoff, "red": state_r,"yellow": state_y,"green": state_g });
});
$ npm install socket.io
var server = http.createServer(app);
var io = require('socket.io').listen(server);
io.sockets.on('connection', function (socket) {
socket.on('status', function (data) {
sp.write("0000nr");
});
socket.on('on', function (data) {
sp.write("2000nr");
});
socket.on('off', function (data) {
sp.write("1000nr");
});
socket.on('red', function (data) {
if(data['status']=="toggle"){
if(state_r=='1') sp.write("0100nr");
else sp.write("0200nr");
}else if(data['status']=="on"){
sp.write("0200nr");
}else if(data['status']=="off"){
sp.write("0100nr");
}
});
socket.emit('status', { "red": state_r,"yellow": state_y,"green": state_g });
});
https://github.com/theRichu/node_arduinio_example/blob/master/node_arduino_example/public/index.html
<div data-role="page">
<div data-role="header">
<h1>
OctoberSky Week1
</h1>
</div>
<ul data-role="content">
<div class="containing-element">
<select name="flip-min" id="flip-min" data-role="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<div data-role="controlgroup" data-type="horizontal">
<a href="#" id="red_toggle" data-role="button"> red </a>
<a href="#" id="yellow_toggle" data-role="button"> yellow </a>
<a href="#" id="green_toggle" data-role="button"> green </a>
</div>
</ul>
</div>
https://github.com/theRichu/node_arduinio_example/blob/master/node_arduino_example/public/index.html
var socket = io.connect('http://localhost:52273');
socket.emit('status');
socket.on('status', function (data) {
if(data['onoff']=="1"){$('#flip-min').val("on");}
else{$('#flip-min').val("off");}
$('#flip-min').slider('refresh');
if(data['red']=="1"){$('#red_toggle').attr("style", "background: red;");}
else{$('#red_toggle').attr("style", "background: gray;");}
$( "#flip-min" ).on( "change", function(event, ui) {
if($("#flip-min").val()=="on"){socket.emit('on');}
else{socket.emit('off');}
});
$("#red_toggle").click(function(){
socket.emit('red', {status: 'toggle'});
});
});
NodeJs로 디바이스 통신하기
NodeJs로 디바이스 통신하기
NodeJs로 디바이스 통신하기

Contenu connexe

Tendances

IoT with Raspberry Pi + Node JS - Chapter 3
IoT with Raspberry Pi + Node JS - Chapter 3IoT with Raspberry Pi + Node JS - Chapter 3
IoT with Raspberry Pi + Node JS - Chapter 3
Park Jonggun
 

Tendances (20)

Start io t_with_raspberrypi
Start io t_with_raspberrypiStart io t_with_raspberrypi
Start io t_with_raspberrypi
 
라즈베리파이입문 - 연세대 특강
라즈베리파이입문 - 연세대 특강라즈베리파이입문 - 연세대 특강
라즈베리파이입문 - 연세대 특강
 
[IoT] MAKE with Open H/W + Node.JS - 4th
[IoT] MAKE with Open H/W + Node.JS - 4th[IoT] MAKE with Open H/W + Node.JS - 4th
[IoT] MAKE with Open H/W + Node.JS - 4th
 
04강 라즈베리-개발환경구축-실습
04강 라즈베리-개발환경구축-실습04강 라즈베리-개발환경구축-실습
04강 라즈베리-개발환경구축-실습
 
웨어러블 디바이스를 활용한 개인용 지능형 로봇
웨어러블 디바이스를 활용한 개인용 지능형 로봇웨어러블 디바이스를 활용한 개인용 지능형 로봇
웨어러블 디바이스를 활용한 개인용 지능형 로봇
 
라즈베리파이로 보일러 제어하기
라즈베리파이로 보일러 제어하기라즈베리파이로 보일러 제어하기
라즈베리파이로 보일러 제어하기
 
[IoT] MAKE with Open H/W + Node.JS - 5th
[IoT] MAKE with Open H/W + Node.JS - 5th[IoT] MAKE with Open H/W + Node.JS - 5th
[IoT] MAKE with Open H/W + Node.JS - 5th
 
라즈베리파이 Circulus API 가이드
라즈베리파이 Circulus API 가이드라즈베리파이 Circulus API 가이드
라즈베리파이 Circulus API 가이드
 
About raspberrypi
About raspberrypiAbout raspberrypi
About raspberrypi
 
Meteor로 공공 IoT한 썰.slides
Meteor로 공공 IoT한 썰.slidesMeteor로 공공 IoT한 썰.slides
Meteor로 공공 IoT한 썰.slides
 
Meteor IoT
Meteor IoTMeteor IoT
Meteor IoT
 
넌프로그래머를 위한 서버/네트워크
넌프로그래머를 위한 서버/네트워크 넌프로그래머를 위한 서버/네트워크
넌프로그래머를 위한 서버/네트워크
 
1장 사물인터넷과 라즈베리 파이
1장 사물인터넷과 라즈베리 파이1장 사물인터넷과 라즈베리 파이
1장 사물인터넷과 라즈베리 파이
 
Rhea_MMO_SNG_Convergence_Server_Architecture
Rhea_MMO_SNG_Convergence_Server_ArchitectureRhea_MMO_SNG_Convergence_Server_Architecture
Rhea_MMO_SNG_Convergence_Server_Architecture
 
Rhea mmo node_for_share
Rhea mmo node_for_shareRhea mmo node_for_share
Rhea mmo node_for_share
 
[IoT] MAKE with Open H/W + Node.JS - 2nd
[IoT] MAKE with Open H/W + Node.JS - 2nd[IoT] MAKE with Open H/W + Node.JS - 2nd
[IoT] MAKE with Open H/W + Node.JS - 2nd
 
Raspberry pi 개발환경 구축
Raspberry pi 개발환경 구축Raspberry pi 개발환경 구축
Raspberry pi 개발환경 구축
 
IoT with Raspberry Pi + Node JS - Chapter 3
IoT with Raspberry Pi + Node JS - Chapter 3IoT with Raspberry Pi + Node JS - Chapter 3
IoT with Raspberry Pi + Node JS - Chapter 3
 
Ipython server(Jupyter Server) 만들기
Ipython server(Jupyter Server) 만들기Ipython server(Jupyter Server) 만들기
Ipython server(Jupyter Server) 만들기
 
ARTIK 710 IoT class 02
ARTIK 710 IoT class 02ARTIK 710 IoT class 02
ARTIK 710 IoT class 02
 

En vedette

라즈베리파이 홈 오토메이션
라즈베리파이 홈 오토메이션라즈베리파이 홈 오토메이션
라즈베리파이 홈 오토메이션
JuHyeon Yeom
 
1º Primeira Guerra Mundia:l A Europa Antes da Guerra
1º Primeira Guerra Mundia:l A Europa Antes da Guerra1º Primeira Guerra Mundia:l A Europa Antes da Guerra
1º Primeira Guerra Mundia:l A Europa Antes da Guerra
Básicas ou Secundárias
 

En vedette (20)

[1C6]오픈소스 하드웨어 플랫폼과 Node.js로 구현하는 IoT 플랫폼
[1C6]오픈소스 하드웨어 플랫폼과 Node.js로 구현하는 IoT 플랫폼[1C6]오픈소스 하드웨어 플랫폼과 Node.js로 구현하는 IoT 플랫폼
[1C6]오픈소스 하드웨어 플랫폼과 Node.js로 구현하는 IoT 플랫폼
 
라즈베리파이 홈 오토메이션
라즈베리파이 홈 오토메이션라즈베리파이 홈 오토메이션
라즈베리파이 홈 오토메이션
 
엔지니어의 삶 - Raspberry Pi 와 Python을 활용한 에어컨 제어
엔지니어의 삶 - Raspberry Pi 와 Python을 활용한 에어컨 제어엔지니어의 삶 - Raspberry Pi 와 Python을 활용한 에어컨 제어
엔지니어의 삶 - Raspberry Pi 와 Python을 활용한 에어컨 제어
 
IoT & 오픈소스
IoT & 오픈소스IoT & 오픈소스
IoT & 오픈소스
 
IoT 제품 리뷰 - 약 20개의 IoT 제품 리뷰
IoT 제품 리뷰 - 약 20개의 IoT 제품 리뷰IoT 제품 리뷰 - 약 20개의 IoT 제품 리뷰
IoT 제품 리뷰 - 약 20개의 IoT 제품 리뷰
 
졸업작품 최종 발표
졸업작품 최종 발표졸업작품 최종 발표
졸업작품 최종 발표
 
IoT 기반 융합 서비스 기술 (응용사례)
IoT 기반 융합 서비스 기술 (응용사례)IoT 기반 융합 서비스 기술 (응용사례)
IoT 기반 융합 서비스 기술 (응용사례)
 
Do IoT Yourself! - 사물 간의 연결을 위한 Open API
Do IoT Yourself! - 사물 간의 연결을 위한 Open APIDo IoT Yourself! - 사물 간의 연결을 위한 Open API
Do IoT Yourself! - 사물 간의 연결을 위한 Open API
 
IoT 서비스 아키텍처 분석 및 Case Study-Innovation Seminar
IoT 서비스 아키텍처 분석 및 Case Study-Innovation SeminarIoT 서비스 아키텍처 분석 및 Case Study-Innovation Seminar
IoT 서비스 아키텍처 분석 및 Case Study-Innovation Seminar
 
1º Primeira Guerra Mundia:l A Europa Antes da Guerra
1º Primeira Guerra Mundia:l A Europa Antes da Guerra1º Primeira Guerra Mundia:l A Europa Antes da Guerra
1º Primeira Guerra Mundia:l A Europa Antes da Guerra
 
An introduction to hadoop
An introduction to hadoopAn introduction to hadoop
An introduction to hadoop
 
[16.01.05] node.js & mqtt
[16.01.05] node.js & mqtt[16.01.05] node.js & mqtt
[16.01.05] node.js & mqtt
 
201210 그루터 빅데이터_플랫폼_아키텍쳐_및_솔루션_소개
201210 그루터 빅데이터_플랫폼_아키텍쳐_및_솔루션_소개201210 그루터 빅데이터_플랫폼_아키텍쳐_및_솔루션_소개
201210 그루터 빅데이터_플랫폼_아키텍쳐_및_솔루션_소개
 
Intoduction to Android Development
Intoduction to Android DevelopmentIntoduction to Android Development
Intoduction to Android Development
 
Distributed messaging with Apache Kafka
Distributed messaging with Apache KafkaDistributed messaging with Apache Kafka
Distributed messaging with Apache Kafka
 
DB 설계 과제
DB 설계 과제DB 설계 과제
DB 설계 과제
 
SmartGreed Security Hakathon 참가 후기
SmartGreed Security Hakathon 참가 후기SmartGreed Security Hakathon 참가 후기
SmartGreed Security Hakathon 참가 후기
 
Linkbox 사업계획서20150918
Linkbox 사업계획서20150918Linkbox 사업계획서20150918
Linkbox 사업계획서20150918
 
졸업프로젝트 일정
졸업프로젝트 일정졸업프로젝트 일정
졸업프로젝트 일정
 
Perl Programming 101 - the practical way
Perl Programming 101 - the practical wayPerl Programming 101 - the practical way
Perl Programming 101 - the practical way
 

Similaire à NodeJs로 디바이스 통신하기

KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
흥배 최
 
망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324
종인 전
 

Similaire à NodeJs로 디바이스 통신하기 (20)

KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
KGC 2016 오픈소스 네트워크 엔진 Super socket 사용하기
 
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
 
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoLinux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
 
망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324망고100 메뉴얼 환경부터포팅까지-2011-0324
망고100 메뉴얼 환경부터포팅까지-2011-0324
 
안드로이드 플랫폼 설명
안드로이드 플랫폼 설명안드로이드 플랫폼 설명
안드로이드 플랫폼 설명
 
Relationship between firmware and module(drvier)
Relationship between firmware and module(drvier)Relationship between firmware and module(drvier)
Relationship between firmware and module(drvier)
 
이기종 멀티코어 프로세서를 위한 프로그래밍 언어 및 영상처리 오픈소스
이기종 멀티코어 프로세서를 위한 프로그래밍 언어 및 영상처리 오픈소스이기종 멀티코어 프로세서를 위한 프로그래밍 언어 및 영상처리 오픈소스
이기종 멀티코어 프로세서를 위한 프로그래밍 언어 및 영상처리 오픈소스
 
20141229 dklee docker
20141229 dklee docker20141229 dklee docker
20141229 dklee docker
 
[드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23][드론] 펌웨어 분석 [2015.5.23]
[드론] 펌웨어 분석 [2015.5.23]
 
Nodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjsNodejs, PhantomJS, casperJs, YSlow, expressjs
Nodejs, PhantomJS, casperJs, YSlow, expressjs
 
Maker 오해와 진실
Maker 오해와 진실Maker 오해와 진실
Maker 오해와 진실
 
웹기반원격감시제어 2010 CPD
웹기반원격감시제어 2010 CPD웹기반원격감시제어 2010 CPD
웹기반원격감시제어 2010 CPD
 
Device driver
Device driverDevice driver
Device driver
 
KAFKA 3.1.0.pdf
KAFKA 3.1.0.pdfKAFKA 3.1.0.pdf
KAFKA 3.1.0.pdf
 
Infra as Code with Packer, Ansible and Terraform
Infra as Code with Packer, Ansible and TerraformInfra as Code with Packer, Ansible and Terraform
Infra as Code with Packer, Ansible and Terraform
 
Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발Mean 스택을 사용한 IoT 개발
Mean 스택을 사용한 IoT 개발
 
(120128) #fitalk android forensics 101
(120128) #fitalk   android forensics 101(120128) #fitalk   android forensics 101
(120128) #fitalk android forensics 101
 
소프트웨어의 계층구조
소프트웨어의 계층구조소프트웨어의 계층구조
소프트웨어의 계층구조
 
한글시계웍샵_ SW
한글시계웍샵_ SW한글시계웍샵_ SW
한글시계웍샵_ SW
 
Internship backend
Internship backendInternship backend
Internship backend
 

Dernier

Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)
Wonjun Hwang
 

Dernier (7)

도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'
도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'
도심 하늘에서 시속 200km로 비행할 수 있는 미래 항공 모빌리티 'S-A2'
 
Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)Grid Layout (Kitworks Team Study 장현정 발표자료)
Grid Layout (Kitworks Team Study 장현정 발표자료)
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차
 
A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
 
[Terra] Terra Money: Stability and Adoption
[Terra] Terra Money: Stability and Adoption[Terra] Terra Money: Stability and Adoption
[Terra] Terra Money: Stability and Adoption
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
 

NodeJs로 디바이스 통신하기

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. 아두이노(Arduino)는 오픈소스를 기반으로 한 단일 보드 마이크로 컨트롤러이다. AVR을 기반으로 한 보드로 이루어져 있고 최근에는 Cortex-M3를 이용한 제품(Arduino Due)도 있다. 소프트웨어 개발을 위한 통합 환경(IDE)이 있다. 아두이노는 다수의 스위치나 센서로부터 값을 받아들 여, LED나 모터와 같은 외부 전자 장치들을 통제함으로써 환경과 상호작용이 가능한 물건을 만들어낼 수 있다. 또 한 플래시, 프로세싱, Max/MSP와 같은 소프트웨어를 연 동할 수 있다.[3] 아두이노의 가장 큰 장점은 마이크로컨트롤러를 쉽게 동 작시킬 수 있다는 것이다. 일반적으로 AVR 프로그래밍이 WinAVR로 컴파일하여, ISP장치를 통해 업로드를 해야하 는 등 번거로운 과정을 거쳐야하는데 비해, 아두이노는 컴 파일된 펌웨어를 USB를 통해 업로드를 쉽게 할 수 있다. 또한 아두이노는 다른 모듈에 비해 비교적 저렴하고, 윈도 를 비롯해 맥 OS X, 리눅스와 같은 여러 OS를 모두 지원 한다. 아두이노 보드의 회로도가 CCL에 따라 공개되어 있 으므로, 누구나 직접 보드를 직접 만들고 수정할 수 있다.
  • 7. • 통신 방식 : RS-232 Serial via USB • 패킷 : [전체][빨강][노랑][초록]nr • 0 : 그대로 • 1 : 끄기 • 2 : 켜기 https://github.com/theRichu/node_arduinio_example/blob/master/arduino/device.ino
  • 8.
  • 9. $ npm update $ npm install –g express $ npm install -g express-generator $ express server $ cd server $ npm install $ npm start• http://localhost:3000 app.get('/', function (request, response) { fs.readFile('index.html', function (error, data) { response.send(data.toString()); }); }); https://github.com/theRichu/node_arduinio_example/blob/master/node_arduino_example/public/index.html
  • 10. $ npm install serialport var serialport = require("serialport"); var SerialPort = serialport.SerialPort; var sp = new SerialPort("/dev/ttyACM1", { baudrate: 9600, parser: serialport.parsers.readline("n") }); var onoff = 0; var state_r = 0; var state_y = 0; var state_g = 0; sp.on("data", function (data) { onoff = data[0]; state_r = data[1]; state_y = data[2]; state_g = data[3]; io.sockets.emit('status', { "onoff": onoff, "red": state_r,"yellow": state_y,"green": state_g }); });
  • 11. $ npm install socket.io var server = http.createServer(app); var io = require('socket.io').listen(server); io.sockets.on('connection', function (socket) { socket.on('status', function (data) { sp.write("0000nr"); }); socket.on('on', function (data) { sp.write("2000nr"); }); socket.on('off', function (data) { sp.write("1000nr"); }); socket.on('red', function (data) { if(data['status']=="toggle"){ if(state_r=='1') sp.write("0100nr"); else sp.write("0200nr"); }else if(data['status']=="on"){ sp.write("0200nr"); }else if(data['status']=="off"){ sp.write("0100nr"); } }); socket.emit('status', { "red": state_r,"yellow": state_y,"green": state_g }); });
  • 12.
  • 13. https://github.com/theRichu/node_arduinio_example/blob/master/node_arduino_example/public/index.html <div data-role="page"> <div data-role="header"> <h1> OctoberSky Week1 </h1> </div> <ul data-role="content"> <div class="containing-element"> <select name="flip-min" id="flip-min" data-role="slider"> <option value="off">Off</option> <option value="on">On</option> </select> </div> <div data-role="controlgroup" data-type="horizontal"> <a href="#" id="red_toggle" data-role="button"> red </a> <a href="#" id="yellow_toggle" data-role="button"> yellow </a> <a href="#" id="green_toggle" data-role="button"> green </a> </div> </ul> </div>
  • 14. https://github.com/theRichu/node_arduinio_example/blob/master/node_arduino_example/public/index.html var socket = io.connect('http://localhost:52273'); socket.emit('status'); socket.on('status', function (data) { if(data['onoff']=="1"){$('#flip-min').val("on");} else{$('#flip-min').val("off");} $('#flip-min').slider('refresh'); if(data['red']=="1"){$('#red_toggle').attr("style", "background: red;");} else{$('#red_toggle').attr("style", "background: gray;");} $( "#flip-min" ).on( "change", function(event, ui) { if($("#flip-min").val()=="on"){socket.emit('on');} else{socket.emit('off');} }); $("#red_toggle").click(function(){ socket.emit('red', {status: 'toggle'}); }); });