• No results found

Wireless Control of Lights

N/A
N/A
Protected

Academic year: 2022

Share "Wireless Control of Lights"

Copied!
23
0
0

Loading.... (view fulltext now)

Full text

(1)

TVE-E 17 004 juni

Examensarbete 15 hp Juni 2017

Wireless Control of Lights

Independent Project in Electrical Engineering

Andreas Eckerblad

Sebastian From

(2)

Teknisk- naturvetenskaplig fakultet UTH-enheten

Besöksadress:

Ångströmlaboratoriet Lägerhyddsvägen 1 Hus 4, Plan 0

Postadress:

Box 536 751 21 Uppsala

Telefon:

018 – 471 30 03

Telefax:

018 – 471 30 00

Hemsida:

http://www.teknat.uu.se/student

Abstract

Wireless Control of Lights

Andreas Eckerblad, Sebastian From

Wireless control of lights is a 15HP project carried out at Uppsala University. Wireless control is used everywhere nowadays and the goal of this project is to create a prototype that can control the light intensity of an single phase lamp using wireless communication. Using this prototype, a solution of wireless control that can be applied for larger scale applications will be presented. By larger scale in this cases means more than the single lamp used for the prototype.

The project uses WiFi and a server solution to communicate between the control unit and the light appliance. A small circuit was made to make it possible to control the grid voltage of 230 volt AC without damaging the microcontroller. The solution presented by this project works as intended. This solution can be modified to suit many different appliances, and not only control of lamps.

Handledare: Tomas Olofsson

(3)

Glossary

Abbreviation Meaning

DC = Direct Current

GUI = Graphical User Interface

IDE = Integrated Development Environment IOS = iPhone Operating System

IP = Internet Protocol IR = Infrared Radiation LED = Light Emitting Diode VAC = Volts of Alternating Current

MOSFET = Metal Oxide Semiconductor Field Effect Transistor PWM = Pulse Width Modulation

SSID = Service Set Identifier

TV = Television

WiFi = Wireless Fidelity

(4)

Contents

1 Introduction 1

1.1 Background . . . 1

1.2 Purpose . . . 1

1.3 Goal . . . 1

1.4 Boundaries . . . 1

1.5 Design . . . 1

2 Theory 3 2.1 Microcontroller . . . 3

2.2 PWM signals . . . 3

2.3 Dimmer circuit . . . 4

2.4 Wireless communication . . . 4

2.4.1 Radio Waves . . . 4

2.4.2 Bluetooth . . . 5

2.4.3 Wireless Fidelity . . . 6

2.4.4 Infrared . . . 6

3 Method and design 7 3.1 Components . . . 7

3.2 Implementation . . . 7

3.2.1 Setting up a server . . . 7

3.2.2 Server communication . . . 7

3.3 Workspace and system setup . . . 8

4 Results and discussion 9 4.1 Wireless communication . . . 9

4.1.1 Bluetooth solution . . . 11

4.1.2 Infrared solution . . . 11

4.1.3 Radio wave solution . . . 11

4.2 Implementation for other appliances . . . 11

4.3 User interface . . . 12

4.3.1 Android app . . . 12

4.3.2 Blynk . . . 12

5 Conclusion 13

6 References 14

Appendices 15

A Arduino code 15

(5)

1 Introduction

1.1 Background

This 15HP project is carried out at Uppsala University in Uppsala, Sweden, for the course Independent Project in Electrical Engineering. The course will prepare students for working in projects within an area of electrical engineering. This project is about wireless control of electrical systems, specifically wireless control of lights connected to a single phase in a wall outlet.

1.2 Purpose

Today wireless control is becoming more and more popular. Controlling everything at home wirelessly is constantly being pushed by companies. The purpose of this project is to design a system to wireless communicate with and control lighting appliances.

1.3 Goal

The goal of this project is to create a prototype consisting of a small lighting appliance, in the form of a light bulb with corresponding circuit, which is wirelessly controlled using a smartphone. This means that single phase 230 VAC from the wall outlet has to be controlled wirelessly. Using this design, a solution for future wireless control of appliances will be suggested.

1.4 Boundaries

This project only contains work on single phase lighting appliances. This means three phase appliances can not be included in the conclusions and results of this project.

Due to the lack of knowledge of smartphone programming, the wireless control will be limited to what can be done with the limited time frame.

1.5 Design

The circuit design (figure 1) was chosen due to stability and well tested proof of con- cept. The circuit can be said to consist of three parts. The Arduino (section 2.1) which controls when the bigger circuit leads using PWM signals (section 2.2), the rectifier which output is controlled by the Arduino and itself controls the MOSFET which in turn is what will actually dim the 230 VAC signal (section 2.3).

The wireless communication for an Arduino device can be made using several tech- nologies. One of the challenges of this project is to choose a fitting technology for the wireless communication, where allowances for each of the technologies pros and cons.

(6)

Figure 1: Ton Giesberts AC dimmer circuit configured to work with Arduino[2]

(7)

2 Theory

2.1 Microcontroller

A microcontroller is a system in a single integrated circuit that can be used as an embedded system to perform a specific task. It contains memory, programmable pe- ripherals and a processor. Today, most microcontrollers are used in wide range of applications, such as machinery, consumer products and office products.

Microcontrollers are designed to be low cost, low power consumption and have a wide range of use. This makes microcontrollers very economical for control of electronic devices.[1]

An example of a programmable environment using micorcontrollers is Arduino. Ar- duino is an open source electronics platform that focuses on easy-to-use hardware and software. They develop single-board microcontrollers and microcontroller kits used for electronic devices. Arduino boards are able to read inputs and turn it into out- puts. The boards are programmable using the Arduino programming language and the Arduino Software (IDE).[5]

2.2 PWM signals

PWM is a technique to control analog circuits using a digital signal from a processor.

An analog signal has a varying signal and infinite resolution, while a digital signal has a fixed value and resolution. Many microcontrollers include PWM controllers, mak- ing the use of digital signals to control analog signals possible without extra equipment.

PWM uses high resolution counters to modulate the duty cycle, the ratio of the on- time and period, of square waves out of the digital outputs of a processor. This means at any given time the digital output gives the voltage from the DC supply either fully turned on or off. Different duty cycles of a digital signal can be seen in figure 2.

One of the advantages of PWM is that the signals is digital, meaning that noise can only affect the signal if it is big enough to change the logic from a 1 to a 0, or vice versa. A use of PWM to control an analog signal is to control the duty cycle of an analog sine wave, creating a dimming effect. [3]

The duty cycle is given in % and is calculated using D =P W

T · 100% (1)

where PW is the pulse width active time, T the total period time and D is the duty cycle.[4]

(8)

Figure 2: Three different duty cycles of a digital output [3]

2.3 Dimmer circuit

The circuit as seen in figure 1 is a dimmer circuit that uses PWM to control the duty cycle of the single phase AC from the wall socket. The operation relies on two transistors that modulates the AC signal from the socket. An optocoupler is used to isolate the microcontroller from the higher voltage of the analog AC signal. The optocoupler is used to control a MOSFET which is determining the duty cycle of the sine wave signal that goes though the lamp. The voltages and currents are limited by Ohm’s law,

U = R · I (2)

where U is the voltage, R, the resistance and I the current, to keep the voltages and currents at specified levels.[6]

As a safety procedure, the microcontroller is protected by the optocoupler, which insulates the microcontroller from the higher voltages of the analog signals in the dimmer circuit. This has to do with the optocouplers class II insulation class. Class II appliances means that the user is protected by at least two layers of insulation and do not require a ground connection.[7]

2.4 Wireless communication

2.4.1 Radio Waves

Radio waves is, as microwaves, infrared radiation, X-rays and Gamma-rays a sort of electromagnetic radiation, also known as EM-radiation. The main purpose of radio waves is to send communication signals like TV, cellphones and radio, where you con- vert the radio waves to mechanical vibrations to produce sound or light. The radio

(9)

wave has the largest bandwidth of all EM-waves. They can vary between 3kHz all the way up to 300GHz depending on its purpose. See table 1 below. [9]

Band Frequency range Wavelength range Extremely Low

Frequency (ELF) <3 kHz >100 km Very Low

Frequency (VLF) 3 to 30 kHz 10 to 100 km Low

Frequency (LF) 30 to 300 kHz 1 m to 10 km Medium

Frequency (MF) 300 kHz to 3 MHz 100 m to 1 km High

Frequency (HF) 3 to 30 MHz 10 to 100 m Very High

Frequency (VHF) 30 to 300 MHz 1 to 10 m Ultra High

Frequency (UHF) 300 MHz to 3 GHz 10 cm to 1 m Super High

Frequency (SHF) 3 to 30 GHz 1 to 1 cm Extremely High

Frequency (EHF) 30 to 300 GHz 1 mm to 1 cm Table 1: How the Frequency changes with wavelength

A radio wave transmitter does not need to be in direct view of the transceiver. They can go through hills and radio waves in the lowest frequency can be reflected on the Earths upper atmosphere called the ionosphere which makes the waves even go over hills. [8]

The main problem with radio waves is interference if two sources sends on the same frequency the receiver will get both signals. The problem can be solved by slightly adjusting the signal frequency sending and receiving.

2.4.2 Bluetooth

Bluetooth also uses radio waves. The main difference between normal radio waves and Bluetooth is that Bluetooth devices need to pair with each other before they can be used, this solves the previous problem with interference between sources with the same frequency mentioned in section 2.4.1. Bluetooth can transfer data between two devices with a distance of up to 60 meters between them.[10]

The main problem with Bluetooth is also part of its strength. One can at the moment only connect to one device at once. This makes Bluetooth a inferior choice if multiple

(10)

devices needs to communicate .

2.4.3 Wireless Fidelity

Like Bluetooth, (section 2.4.2) Wireless Fidelity, or WiFi for short, is using radio waves (section 2.4.1). Like Bluetooth, some way is needed to connect the source of the signal to the receiver. The WiFi solution is an antenna, which is more commonly known as the router. The router creates a hotspot which is the area where you, with a WiFi module, can connect to the network created by the router. Multiple modules can be connected to the same network at the same time which makes WiFi a good solution if you want to send signals to multiple devices at the same time.

WiFi work on frequency levels of either 2.4GHz or 5GHz depending on the amount of data you want to send. The network using the 802.11 networking standards will vary depending on the users needs, going from 802.11a to the faster 802.11n with 5GHz frequency, and 802.11b to the faster 802.11g with 2.4GHz frequency. [11]

2.4.4 Infrared

Infrared radiation or IR-radiation is as radio waves (section 2.4.1) a sort of EM- radiation with an frequency below radio waves but higher then visible light. IR- radiation is simply light that you can not see but can still use to transfer data IR-radiation are commonly used in remote controllers for the TV. It often operate in the 38kHz area where there are very few natural sources of that frequency. IR- communicating uses an IR-LED on the transmitter and an IR-receiver will pick up the signal and decode it. The LED will blink in a different pattern depending on what you want the reciever to do. [12]

(11)

3 Method and design

3.1 Components

The microcontroller chosen for this project is called Adafruit Feather Huzzah ESP8266 which features Arduino compatible hardware as well as a WiFi module called ESP8266.

The ESP8266 module is a WiFi module compatible with Arduino which can connect to a network and send and transmit data wirelessly over said network. Since the cho- sen Arduino board features a built-in WiFi module, there is no need to add extra modules to the project. The ESP8266 has its own Arduino library which can be used to program it.

This microcontroller is connected to the circuit shown in figure 1 where the Adafruit Feather Huzzah ESP8266 replaces the generic Arduino board in the figure. Because the Adafruit Feather Huzzah ESP8266 uses 3.3 V logic instead of the standard 5 V logic featured on common Arduino boards, the current-limiting resistor has to be changed.

Using equation 2, a new resistor value of 180 Ω is used to have the same voltage across the optocoupler.

3.2 Implementation

3.2.1 Setting up a server

Programming the Huzzah to connect to a network means any device connected to the network can communicate with it. This is essential for the wireless communication between the smartphone and the Arduino. To be able to send and transmit data be- tween the devices, a server is set up. The server is web-based and is accessible by the Arduinos IP adress. This is done using any web browser by a device connected to the same network. The IP adress is accumulated by a computer physically connected to the Arduino, and is displayed when the Arduino is connected to the desired network.

The Arduino is programmed to connect to a specific network chosen in the code, where the SSID and password of the network to connect to is programmed into the Arduino.

When the server is set up, it needs to have a GUI for the user to interact with. This interface is implemented to the server using JavaScrip. This allows for an interactive interface that can be used by any device with internet browser support.

3.2.2 Server communication

To send and transmit data to and from the server, the interactions used by the user on the web server will be detected and recorded on the Arduino. The Arduino will not read the JavaScrip directly, but will instead put the data in a string and split it in to smaller parts to be able to react to actions made on the server, this is made with the server code directly implemented in to the Arduino code. The interface consists of

(12)

sliders, which are called PWM Outputs, which goes from values 0 to 1023. The slider values determines the duty cycle of which the Arduino controls the lamp, meaning a duty cycle of 0 means the lamp is completely off and a value of 1023 means the lamp is completely on.

The server is programmed to support more than one slider, even though the prototype only requires one slider as only one of the digital outputs is used to control a lamp.

Each slider would represent a digital output from the Arduino and can therefore be controlled by adding more sliders and implementing those into the code.

3.3 Workspace and system setup

The system is built on a breadboard instead of on a through hole PCB for easy assem- ble, disassemble and components replacement. The breadboard can have the Arduino connected directly to it, instead of using extra wiring. This makes testing easy, as the Arduino can be easily removed. A computer is used to program the Arduino in the Arduino IDE, this makes transferring the code over to the Arduino easy. To test the Arduino, a generic smartphone with a web browser is used.

Figure 3: System setup. 1) Computer, 2) Circuit, 3) Smartphone, 4) Lamp

(13)

4 Results and discussion

The resulting prototype works. There is a running server that can be accessed by any device on the same wireless network and it responds to commands by clients on the network. These commands can be interpreted by the Arduino to control the lamp.

The dimming is not continuous when the slider value is altered, but instead only reads the value of the slider when it is released. There is a small problem with the bootup of the Arduino. The current limiting resistor on the digital output causes the digital pin to float, which causes the Arduino to not load the program properly. Booting the Arduino separate and then connecting it to the circuit will however make the system load fine and work as intended.

Figure 4: Prototype circuit with connected smartphone

4.1 Wireless communication

The final product uses WiFi (section 2.4.3) to communicate between the smartphone and the Arduino instead of Bluetooth (section 2.4.2), regular radio waves (section 2.4.1) or IR-radiation (section 2.4.4).

The WiFi solution makes the whole system password protected and easy to connect multiple modules to the same network. WiFi lets the user control the system in a larger area depending on your routers range, which makes it easy to control several modules on the same network. The WiFi solution has a GUI designed to be easy to use by any device with web browser support, as seen on a smartphone in figure 5.

(14)

Figure 5: Server GUI as seen from a smartphone

(15)

4.1.1 Bluetooth solution

A Bluetooth solution would have looked similar to the WiFi solution except there would have been a Bluetooth chip on the Arduino for communication instead of the WiFi chip, and a sever solution would not have been an option instead an Android app would have been needed. The reason that Bluetooth was not chosen was because of its limitation to only be able to be connected to one receiver module at once and one of the projects goals was to be able to come up with a solution to implement the solution to a larger scale.

4.1.2 Infrared solution

A IR-radiation solution would have used an IR-module on the Arduino for the wireless communication. Since most smartphones nowadays do not have IR-transmitters, an IR controller would have been needed. IR-radiation is limited to line of sight with the receiver which can be problematic to use when there are many objects nearby the transmitter and reciever. IR-radiation also has a very limited amount of data that can be sent which in itself becomes a limitation if the final product needs to transfer a lot of data.

4.1.3 Radio wave solution

The radio wave solution would have been very similar to the IR-radiation solution except that all the receiver and transmitter modules would have been radio wave ver- sions. A radio wave solution makes the whole system exposed from outside sources which makes it an inferior choice, as it will be easier for other sources to interfere with the signals. Some smartphones have radio wave transmitters, which can be used for this purpose.

4.2 Implementation for other appliances

The Adafruit Feather Huzzah ESP8266 supports nine digital outputs, meaning this microcontroller can control up to nine different appliances at a time. Each output can also control more than one lamp, several lamps connected in serial or parallel can be connected to each output, making the single microcontroller able to control larger lighter systems.

The final product can be used in many different areas. It is not always preferred to be able to dim electrical appliances, but that can easily be modified in the prototype so that instead of controlling a dimmer circuit, relay switches are controlled with an Arduino. This opens up a lot of possible areas of usage. For example are most in- dustrial lighting appliances made up of fluorescent lamps, which can not be dimmed.

These can however be controlled using relay switches, making an implementation of

(16)

our system to industrial appliances and offices not too difficult.

To implement wireless control of electrical appliances in a room, the Arduino needs to be connected to a relay for each phase or number of appliances to control. The Arduino will have to be programmed in a slightly different way for this to work, depending on the appliances. For appliances that can not be dimmed, a simple ON/OFF switch can replace the sliders on the server. This requires the dimming code itself to be changed so that the digital pins instead outputs a HIGH signal when the button is ON, and a LOW signal when the button is OFF, instead of a duty cycle that is used for the dimmer circuit.

4.3 User interface

Mentioned in section 3.2, a server solution is used to control the intensity of the light.

Several solutions were tested during the course of this project where an Android app and a Blynk solution was the biggest contenders, but ultimately the sever solution was chosen.

4.3.1 Android app

A solution using a self-designed Android app is probably the best solution. The GUI will be designed for a smartphone and lets the person making the interface more in control of the design. The Android app solution was not chosen because of lack of knowledge in programming Android software and WiFi communication between An- droid apps and microcontrollers.

4.3.2 Blynk

Blynk is a platform for both Android and IOS which lets you control your microcon- troller easily with minimal coding needed. The only requirement for the Blynk solution is that your unit is connected to the internet. Blynk was not used as a solution for this project for several reasons. Blynk has its own library for Arduino programming, meaning the code is already premade and doesn’t offer too many options for the pro- grammer. To use Blynk, an app is downloaded to the smartphone. When started, the wanted sliders or buttons are chosen depending on the users needs. Then premade code are accessed on the Blynks own severs, and as long internet connection is up everything works. Because Blynk uses their own server for the communciation, the solution strictly depends on the Blynk server runtime.[13]

(17)

5 Conclusion

The final product works. The system connects to a WiFi network and can be controlled by devices, such as a smartphone, connected to the same network. The system has a GUI that can be used by a smartphone, but also by devices with a web browser. The product can be used for many electric appliances that has to be controlled wirelessly.

The system can be altered for none-dimming purposes by using relay switches instead of dimming circuits for easier implementation, as many appliances does not support varying input voltages.

Wireless control of appliances is in line with the future, as many devices aims for wire- less control, such as home automation and wireless communication between devices.

This solution of wireless control can be implemented for many different applications, but will need some improvements to work flawlessly.

(18)

6 References

[1] Techopedia, Microcontroller, https://www.techopedia.com/definition/3641/

microcontroller

[2] Arduino Lamp Dimmer, https://diyhacking.com/arduino-lamp-dimmer/

[3] Barr, 2001, Pulse Width Modulation, http://www.

embedded.com/electronics-blogs/beginner-s-corner/4023833/

Introduction-to-Pulse-Width-Modulation

[4] Cox, Leo, 2001, Fundamentals of Linear Electronics: Integraded and Discrete, second edition, pp 511-584.

[5] Arduino, 2017, Introduction, hhttps://www.arduino.cc/en/guide/

introduction

[6] Nordling, Österman, 2006, Physics Handbook for Science and Engineering, eighth edition, pp där ohms lag hittas.

[7] Excelsys, 2011, Electrical Appliances, http://www.excelsys.com/wp-content/

uploads/2011/09/ApplicationNoteAN1102-ClassIvsClassII.pdf

[8] BBC, Communicating with waves, http://www.bbc.co.uk/schools/

gcsebitesize/science/aqa/waves/soundandlightrev3.shtml

[9] Livescience, What Are Radio Waves ?, http://www.livescience.com/

50399-radio-waves.html

[10] Bluetooth, How It Works?, https://www.bluetooth.com/

what-is-bluetooth-technology/how-it-works

[11] CCM, What is Wifi and How Does it Work?, http://ccm.net/faq/

298-what-is-wifi-and-how-does-it-work

[12] Sparkfun, IR Communication, https://learn.sparkfun.com/tutorials/

ir-communication

[13] Blynk, Blynk solution, http://www.blynk.cc/

(19)

Appendices

A Arduino code

1 #i n c l u d e <ESP8266WiFi . h>

3 c o n s t c h a r ∗ s s i d = " n e t w o r k "; c o n s t c h a r ∗ p a s s w o r d = " p a s s w o r d ";

5

// C r e a t e an i n s t a n c e o f t h e s e r v e r

7 // s p e c i f y t h e p o r t t o l i s t e n on a s an argument W i F i S e r v e r s e r v e r ( 8 0 ) ;

9

i n t pwm = 0 ;

11

i n t PwmPin = 0 ;

13

v o i d s e t u p ( ) {

15 S e r i a l . b e g i n ( 1 1 5 2 0 0 ) ; S e r i a l . s e t T i m e o u t ( 5 0 ) ;

17 d e l a y ( 1 0 ) ;

19 // Connect t o WiFi n e t w o r k S e r i a l . p r i n t l n ( ) ;

21 S e r i a l . p r i n t l n ( ) ;

S e r i a l .p r i n t(" C o n n e c t i n g t o ") ;

23 S e r i a l . p r i n t l n ( s s i d ) ;

25 WiFi . b e g i n ( s s i d , p a s s w o r d ) ;

27 w h i l e ( WiFi . s t a t u s ( ) != WL_CONNECTED) {

d e l a y ( 5 0 0 ) ;

29 S e r i a l .p r i n t(" . ") ; }

31 S e r i a l . p r i n t l n (" ") ;

S e r i a l . p r i n t l n ("WiFi c o n n e c t e d ") ;

33

// S t a r t t h e s e r v e r

35 s e r v e r . b e g i n ( ) ;

S e r i a l . p r i n t l n (" S e r v e r s t a r t e d ") ;

37

// P r i n t t h e IP a d d r e s s

39 S e r i a l . p r i n t l n ( WiFi . l o c a l I P ( ) ) ; }

41

v o i d l o o p ( ) {

43 // Check i f a c l i e n t h a s c o n n e c t e d W i F i C l i e n t c l i e n t = s e r v e r . a v a i l a b l e ( ) ;

45 i f ( ! c l i e n t ) { r e t u r n;

47 }

49 // Wait u n t i l t h e c l i e n t s e n d s some d a t a S e r i a l . p r i n t l n ("new c l i e n t ") ;

(20)

51 w h i l e( ! c l i e n t . a v a i l a b l e ( ) ) { d e l a y ( 1 ) ;

53 }

55 // Read t h e f i r s t l i n e o f t h e r e q u e s t

S t r i n g command1 = c l i e n t . r e a d S t r i n g U n t i l (’ / ’) ;

57 S t r i n g command = c l i e n t . r e a d S t r i n g U n t i l (’ / ’) ; S e r i a l . p r i n t l n ( command1 ) ;

59 S e r i a l . p r i n t l n ( command ) ;

61

i f ( command == "pwm") {

63 i n t pin , v a l u e ;

p i n = c l i e n t . p a r s e I n t ( ) ;

65 i f ( c l i e n t . r e a d ( ) == ’ / ’) { v a l u e = c l i e n t . p a r s e I n t ( ) ;

67 pwm = v a l u e ;

a n a l o g W r i t e ( pin , v a l u e ) ;

69 } e l s e {

71 v a l u e = pwm;

}

73 c l i e n t .p r i n t(F("pwm, ") ) ; c l i e n t .p r i n t( p i n ) ;

75 c l i e n t .p r i n t(F(" , ") ) ; c l i e n t . p r i n t l n ( v a l u e ) ;

77 }

e l s e i f ( command == " s t a t u s ") {

79 i n t pin , v a l u e ;

c l i e n t .p r i n t(F(" s t a t u s ") ) ;

81

c l i e n t . p r i n t l n (" ") ;

83 }

e l s e { // P r e p a r e t h e r e s p o n s e

85 S t r i n g s = "HTTP/ 1 . 1 200 OK\ r \ nContent−Type : t e x t / html \ r \n\ r \n"; s += "<html >\r \n"

87 "<head >\r \n"

"< t i t l e >W i r e l e s s I /O Demo</ t i t l e >\r \n"

89 "< s c r i p t t y p e=\" t e x t/ j a v a s c r i p t \">\ r \n"

" window . o n l o a d=P i n s t a t u s ; \ r \n"

91 " f u n c t i o n P i n s t a t u s ( ) {\ r \n"

" m o r e s t a t u s ( ) ; \ r \n"

93 " }\ r \n"

" f u n c t i o n m o r e s t a t u s ( ) {\ r \n"

95 " s e t T i m e o u t ( m o r e s t a t u s , 4 0 0 0 ) ; \ r \n"

" document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = \ "P r o c e s s i n g S t a t u s

\" ; \ r \n"

97 " s e r v e r = \ "s t a t u s /99\" ; \ r \n"

" r e q u e s t = new XMLHttpRequest ( ) ; \ r \n"

99 " r e q u e s t . o n r e a d y s t a t e c h a n g e = u p d a t e a s y n c s t a t u s ; \ r \n"

" r e q u e s t . open ( \ "GET\" , s e r v e r , t r u e ) ; \ r \n"

101 " r e q u e s t . s e n d ( n u l l ) ; \ r \n"

" }\ r \n"

103 " f u n c t i o n u p d a t e a s y n c s t a t u s ( ) {\ r \n"

" i f ( ( r e q u e s t . r e a d y S t a t e == 4 ) && ( r e q u e s t . s t a t u s == 2 0 0 ) ) \ r \n"

105 " {\ r \n"

(21)

" r e s u l t = r e q u e s t . r e s p o n s e T e x t ; \ r \n"

107 " document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = r e s u l t ; \ r \n"

" f u l l s e t = r e s u l t . s p l i t ( \ "#\ " ) ; \ r \n"

109 " document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = f u l l s e t ; \ r \n"

" f o r ( i = 1 ; i < f u l l s e t . l e n g t h ; i ++){\ r \n"

111 " P i n P a i r = f u l l s e t [ i ] ; \ r \n"

" s i n g l e s e t = P i n P a i r . s p l i t ( \ "=\" ) ; \ r \n"

113 "PN = s i n g l e s e t [ 0 ] ; \ r \n"

" P i n s t a t u s = s i n g l e s e t [ 1 ] ; \ r \n"

115 " i f (PN > 1 1 ) \ r \n"

" {\ r \n"

117 "ActNum = \ "a c t i o n \" + PN; \ r \n"

"TxtNum = \ " t e x t\" + PN; \ r \n"

119 " i f ( P i n s t a t u s == 0 ) \ r \n"

" {\ r \n"

121 " PinAct = \ "1\" ; \ r \n"

" t e x t = \ "O f f \" ; \ r \n"

123 " }\ r \n"

" e l s e \ r \n"

125 " {\ r \n"

" PinAct = \ "0\" ; \ r \n"

127 " t e x t = \ "On\" ; \ r \n"

" }\ r \n"

129 " document . g e t E l e m e n t B y I d ( ActNum ) . v a l u e = PinAct ; \ r \n"

" document . g e t E l e m e n t B y I d (TxtNum) . innerHTML = t e x t ; \ r \n"

131 " }\ r \n"

" i f (PN == 4 ) \ r \n"

133 " {\ r \n"

"TxtNum = \ " t e x t\" + PN; \ r \n"

135 " i f ( P i n s t a t u s == 1 ) \ r \n"

" {\ r \n"

137 " t e x t = \ "On\" ; \ r \n"

" }\ r \n"

139 " e l s e \ r \n"

" {\ r \n"

141 " t e x t = \ "O f f \" ; \ r \n"

" }\ r \n"

143 " document . g e t E l e m e n t B y I d (TxtNum) . innerHTML = t e x t ; \ r \n"

" }\ r \n"

145 " i f (PN == 0 ) \ r \n"

" {\ r \n"

147 " PinVal = p a r s e I n t ( s i n g l e s e t [ 1 ] ) ; \ r \n"

"PwmNum = \ "pwm\" + PN; \ r \n"

149 "ValNum = \ "valuePwm\" + PN; \ r \n"

" document . g e t E l e m e n t B y I d (PwmNum) . v a l u e = PinVal ; \ r \n"

151 " document . g e t E l e m e n t B y I d ( ValNum ) . innerHTML = PinVal ; \ r \n"

" }\ r \n"

153 " i f (PN . s u b s t r ( 0 , 1 ) == \ "A\" ) \ r \n"

" {\ r \n"

155 " PinVal = p a r s e F l o a t ( s i n g l e s e t [ 1 ] ) ; \ r \n"

"AnalogNum = \ "a n a l o g \" + PN . s u b s t r ( 1 , 2 ) ; \ r \n"

157 " document . g e t E l e m e n t B y I d ( AnalogNum ) . v a l u e = PinVal ; \ r \n"

" }\ r \n"

159 " }\ r \n"

" }\ r \n"

161 " }\ r \n"

(22)

" f u n c t i o n u p d a t e a s y n c b u t t o n ( ) {\ r \n"

163 " i f ( ( r e q u e s t . r e a d y S t a t e == 4 ) && ( r e q u e s t . s t a t u s == 2 0 0 ) ) \ r \n"

" {\ r \n"

165 " r e s u l t = r e q u e s t . r e s p o n s e T e x t ; \ r \n"

" document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = r e s u l t ; \ r \n"

167 " s i n g l e s e t = r e s u l t . s p l i t ( \ ", \" ) ; \ r \n"

" document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = r e s u l t ; \ r \n"

169 " }\ r \n"

" }\ r \n"

171 " f u n c t i o n sendPwm ( Pin , v a l u e ) {\ r \n"

"ValNum = \ "valuePwm\" + Pin ; \ r \n"

173 " document . g e t E l e m e n t B y I d ( ValNum ) . innerHTML=v a l u e ; \ r \n"

" document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = \ "P r o c e s s i n g S l i d e r

\" ; \ r \n"

175 " s e r v e r = \ "pwm/\" + Pin + \ "/\" + v a l u e ; \ r \n"

" r e q u e s t = new XMLHttpRequest ( ) ; \ r \n"

177 " r e q u e s t . o n r e a d y s t a t e c h a n g e = updateasyncPwm ; \ r \n"

" r e q u e s t . open ( \ "GET\" , s e r v e r , t r u e ) ; \ r \n"

179 " r e q u e s t . s e n d ( n u l l ) ; \ r \n"

" }\ r \n"

181 " f u n c t i o n updateasyncPwm ( ) {\ r \n"

" i f ( ( r e q u e s t . r e a d y S t a t e == 4 ) && ( r e q u e s t . s t a t u s == 2 0 0 ) ) \ r \n"

183 " {\ r \n"

" r e s u l t = r e q u e s t . r e s p o n s e T e x t ; \ r \n"

185 " s i n g l e s e t = r e s u l t . s p l i t ( \ ", \" ) ; \ r \n"

" PinType = s i n g l e s e t [ 0 ] ; \ r \n"

187 "PinNum = s i n g l e s e t [ 1 ] ; \ r \n"

" PinVal = p a r s e I n t ( s i n g l e s e t [ 2 ] ) ; \ r \n"

189 "PwmNum = \ "pwm\" + PinNum ; \ r \n"

"ValNum = \ "valuePwm\" + PinNum ; \ r \n"

191 " document . g e t E l e m e n t B y I d (PwmNum) . v a l u e = PinVal ; \ r \n"

" document . g e t E l e m e n t B y I d ( ValNum ) . innerHTML = PinVal ; \ r \n"

193 " document . g e t E l e m e n t B y I d ( \ "d e s c r i p t i o n \" ) . innerHTML = r e s u l t ; \ r \n"

" }\ r \n"

195 " }\ r \n"

"</ s c r i p t >\r \n"

197 "</head >\r \n"

"<f o n t f a c e =\"A r i a l \">\ r \n"

199 "<t a b l e name=\"Ta bl e \" b o r d e r =\"1\" c e l l p a d d i n g =\"6\">\ r \n"

"<t r > <t h a l i g n =\"c e n t e r \" c o l s p a n =\"6\" >PWM Output</th></t r >\r \n"

201 "<t r >\r \n"

"<t d a l i g n =\"c e n t e r \">\ r \n"

203 "GPIO 0\ r \n"

" <br >\r \n"

205 "<i n p u t t y p e=\" h i d d e n\" name=\"p i n \" v a l u e =\"0\" i d =\"p i n 0 \" />\ r \n"

"<i n p u t t y p e=\"r a n g e \" s t y l e =\"w id th : 400 px ; h e i g h t : 60 px ; \" i d =\"pwm0\"

min=\"0\" max=\"1 02 3\" v a l u e =\"0\" s t e p =\"1\" onchange=\"sendPwm ( document . g e t E l e m e n t B y I d (’ p i n 0 ’) . v a l u e , \ r \n"

207 " t h i s . v a l u e ) ; \ "/>\ r \n"

"<br >\r \n"

209 "<span i d =\"valuePwm0 \">0</span >\r \n"

"</td >\r \n"

211 "</ t r >\r \n"

"<t r > <t h a l i g n =\"c e n t e r \" c o l s p a n =\"6\" >PWM Output 2</th></t r >\r \n"

213 "<t r >\r \n"

"<t d a l i g n =\"c e n t e r \">\ r \n"

(23)

215 "GPIO 16\ r \n"

" <br >\r \n"

217 "<i n p u t t y p e=\" h i d d e n\" name=\"p i n \" v a l u e =\"16\" i d =\"p i n 1 6 \" />\ r \n"

"<i n p u t t y p e=\"r a n g e \" s t y l e =\"w id th : 400 px ; h e i g h t : 60 px ; \" i d =\"pwm0\"

min=\"0\" max=\"1 02 3\" v a l u e =\"0\" s t e p =\"1\" onchange=\"sendPwm ( document . g e t E l e m e n t B y I d (’ p i n 1 6 ’) . v a l u e , \ r \n"

219 " t h i s . v a l u e ) ; \ "/>\ r \n"

"<br >\r \n"

221 "<span i d =\"valuePwm16 \">0</span >\r \n"

"</td >\r \n"

223 "</ t r >\r \n"

"</ t a b l e >\r \n"

225 "<br><br >\r \n"

"<br><br >\r \n"

227 "<p i d =\"d e s c r i p t i o n \"> − </p>\r \n"

"</ f o n t >\r \n"

229 "</html >\r \n"; c l i e n t . f l u s h ( ) ;

231

// Send t h e r e s p o n s e t o t h e c l i e n t

233 w h i l e( s .l e n g t h( ) >2000) {

235 S t r i n g dummy = s . s u b s t r i n g ( 0 , 2 0 0 0 ) ; c l i e n t .p r i n t(dummy) ;

237 s . r e p l a c e (dummy," ") ; }

239

c l i e n t .p r i n t( s ) ;

241 d e l a y ( 1 ) ;

S e r i a l . p r i n t l n (" C l i e n t d i s c o n n e c t e d ") ;

243

// The c l i e n t w i l l a c t u a l l y be d i s c o n n e c t e d

245 // when t h e f u n c t i o n r e t u r n s and ’ c l i e n t ’ o b j e c t i s d e s t r o y e d }

247 }

References

Related documents

5-12. Vännerna leker kurragömma. Sara har räknat färdigt och hon börjar leta efter sina vänner. Hon springer runt, runt, men ser dem inte. De har gömt sig väl.. Det står

With TRUE, the function block has been started, distance-to-go pending Active BOOL FALSE Display of the command activity in the function block. With TRUE, the command is

K analýze dat byl z obou zařízení vybrán pro každou polohu jeden graf, který bude porovnáván s odpovídajícím grafem z druhého zařízení. Učinilo se tak

Äldre personer som vårdas på sjukhus på grund av akut sjukdom löper ökad risk för försämrad funktionell status.. Studier indikerar att träning under sjukhusvistelsen kan

[r]

Hlavním cílem této části je ověřit přesnost simulace splývavého chování oděvu na virtuální figuríně v počítačovém programu VStitcher za pomoci zařízení

• Statligt hyresstöd till vissa branscher: 10 Mdkr varav fastighetsbranschen står för.. 50 % och staten för

Současní módní tvůrci nachází dnes inspiraci pro vznik svých kolekcí téměř všude. Inspiracemi již nejsou jen konkrétní vizuální věci, ale nahrazují je