-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMark3.ino
129 lines (119 loc) · 2.81 KB
/
Mark3.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WebSocketsServer.h>
ESP8266WebServer server;//webserrver
WebSocketsServer webSocket = WebSocketsServer(81);//websocket server
uint8_t pin=4;//Pin D2 is selected to operate MOSFET
char* ssid = "301_2.4";
char* password = "Rekulapalli";
String message;
char webpage[] PROGMEM = R"=====(
<html>
<head>
<title>Smart-TENS</title>
<script>
var Socket;
function init() {Socket = new WebSocket('ws://' + window.location.hostname + ':81/');}
function conventional(){
document.getElementById("mode").innerHTML="Conventional Mode Activated";
Socket.send("conventional");
}
function acupuncture(){
document.getElementById("mode").innerHTML="Acupuncture Mode Activated";
Socket.send("acupuncture");
}
function intense(){
document.getElementById("mode").innerHTML="Intense Mode Activated";
Socket.send("intense");
}
function actstop(){
document.getElementById("mode").innerHTML="Stop Command Activated";
Socket.send("actstop");
}
</script>
</head>
<body onload="javascript:init()">
<h1>Smart TENS Device</h1>
</hr>
<h2>Device Mode</h2>
<p id="mode" > </p>
<br>
</hr>
<h2>Select Mode</h2>
</hr>
<br>
<div>
<button id="conventional" onclick="javascript:conventional();">Conventional TENS</button>
</div>
<br>
<div>
<button id="acupuncture" onclick="javascript:acupuncture();">Acupuncture TENS</button>
</div>
<br>
<div>
<button id="Intense" onclick="javascript:intense();">Intense TENS</button>
</div>
<br>
<div>
<h2>Stop Action </h2>
<button id="stop" onclick="javascript:actstop();">Stop</button>
</div>
<br>
</body>
</html>
)=====";
void conventional(){
digitalWrite(pin,HIGH);
delay(35);
digitalWrite(pin,LOW);
delay(35);
}
void acupuncture(){
digitalWrite(pin,HIGH);
delay(330);
digitalWrite(pin,LOW);
delay(330);
}
void intense(){
digitalWrite(pin,HIGH);
delay(17);
digitalWrite(pin,LOW);
delay(17);
}
void actstop(){
digitalWrite(pin,LOW);
delay(100);
}
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length){
if(type == WStype_TEXT){
message = String((char*)( payload));
Serial.println(message);
}
}
void setup()
{
pinMode(pin, OUTPUT);
WiFi.begin(ssid,password);
Serial.begin(115200);
while(WiFi.status()!=WL_CONNECTED)
{
Serial.print(".");
delay(200);
}
Serial.println("");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
server.on("/",[](){server.send_P(200, "text/html", webpage);});
server.begin();
webSocket.begin();
webSocket.onEvent(webSocketEvent);
}
void loop()
{
webSocket.loop();
server.handleClient();
if(message == "conventional"){conventional();}
else if(message == "acupuncture"){acupuncture();}
else if(message == "intense"){intense();}
else{actstop();}
}