質問編集履歴
1
arduino側のプログラムの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -105,3 +105,109 @@
|
|
105
105
|
End Try
|
106
106
|
|
107
107
|
End Sub
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
arduino側
|
114
|
+
|
115
|
+
void loop() {
|
116
|
+
|
117
|
+
boolean gRes=false;
|
118
|
+
|
119
|
+
digitalRead(EARTHQUAKE_INPUT);
|
120
|
+
|
121
|
+
digitalRead(WATER_INPUT);
|
122
|
+
|
123
|
+
//// 送信////
|
124
|
+
|
125
|
+
if (digitalRead(EARTHQUAKE_INPUT)== HIGH && digitalRead(WATER_INPUT)== HIGH)
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
EARTHQUAKE_count = 0;
|
130
|
+
|
131
|
+
WATER_count = 0;
|
132
|
+
|
133
|
+
digitalWrite(RELAY_OUTPUT,HIGH); //Relay ON
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}else if(digitalRead(EARTHQUAKE_INPUT)== LOW){
|
138
|
+
|
139
|
+
EARTHQUAKE_count = 0;
|
140
|
+
|
141
|
+
EARTHQUAKE_count=EARTHQUAKE_count+1;
|
142
|
+
|
143
|
+
digitalWrite(RELAY_OUTPUT,HIGH); //Relay ON
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
}else if(digitalRead(WATER_INPUT)== LOW){
|
148
|
+
|
149
|
+
WATER_count = 0;
|
150
|
+
|
151
|
+
WATER_count=WATER_count+1;
|
152
|
+
|
153
|
+
digitalWrite(RELAY_OUTPUT,HIGH); //Relay ON
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
}else{
|
158
|
+
|
159
|
+
EARTHQUAKE_count = 0;
|
160
|
+
|
161
|
+
WATER_count = 0;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
/////受信///
|
168
|
+
|
169
|
+
if(gRes)//TCPサーバとの接続判定
|
170
|
+
|
171
|
+
{//TCPサーバと接続済みの場合
|
172
|
+
|
173
|
+
while(client.available())
|
174
|
+
|
175
|
+
{
|
176
|
+
|
177
|
+
String line = client.readStringUntil('\n');
|
178
|
+
|
179
|
+
Serial.println(line);
|
180
|
+
|
181
|
+
client.print(line + "OK\r\n");
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
int ii=line.indexOf('E');
|
186
|
+
|
187
|
+
if(line[ii]=='E' && line[ii+1]=='N' && line[ii+2]=='D' )
|
188
|
+
|
189
|
+
{gRes=false;delay(5000);}//ENDコマンド受信の場合
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
else
|
196
|
+
|
197
|
+
{//TCPサーバと接続していない場合
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
送受信するときに0 or 1を送って
|
208
|
+
|
209
|
+
1ならarduino側のリレーをOFFにしたいです。
|
210
|
+
|
211
|
+
まだ、arduino側が想像つかない状態なので
|
212
|
+
|
213
|
+
教えていただきたいです。
|