質問編集履歴

2

現在の実行結果、理想の実行結果、受信側のプログラムを記載しました

2021/12/20 11:06

投稿

hirokitrain13
hirokitrain13

スコア0

test CHANGED
File without changes
test CHANGED
@@ -12,8 +12,6 @@
12
12
 
13
13
 
14
14
 
15
-
16
-
17
15
  ###値の送信はうまくいっているが、正しい値を送れていないコード
18
16
 
19
17
 
@@ -130,7 +128,39 @@
130
128
 
131
129
  ```
132
130
 
133
-
131
+ **実行結果**
132
+
133
+ ```ここに言語を入力
134
+
135
+ Successfully Received > {"time": "2021-12-20 19:49:55.907691", "ID": 12345, "Data": "0"}
136
+
137
+ Successfully Received > {"time": "2021-12-20 19:49:56.915803", "ID": 12345, "Data": "\r"}
138
+
139
+ Successfully Received > {"time": "2021-12-20 19:49:57.920313", "ID": 12345, "Data": "\n"}
140
+
141
+ Successfully Received > {"time": "2021-12-20 19:49:58.927146", "ID": 12345, "Data": "4"}
142
+
143
+ Successfully Received > {"time": "2021-12-20 19:49:59.933469", "ID": 12345, "Data": "0"}
144
+
145
+ Successfully Received > {"time": "2021-12-20 19:50:00.940842", "ID": 12345, "Data": "0"}
146
+
147
+ Successfully Received > {"time": "2021-12-20 19:50:01.948506", "ID": 12345, "Data": "\r"}
148
+
149
+ Successfully Received > {"time": "2021-12-20 19:50:02.966437", "ID": 12345, "Data": "\n"}
150
+
151
+ Successfully Received > {"time": "2021-12-20 19:50:03.971292", "ID": 12345, "Data": "4"}
152
+
153
+ Successfully Received > {"time": "2021-12-20 19:50:04.978614", "ID": 12345, "Data": "0"}
154
+
155
+ Successfully Received > {"time": "2021-12-20 19:50:05.983044", "ID": 12345, "Data": "0"}
156
+
157
+ Successfully Received > {"time": "2021-12-20 19:50:06.987425", "ID": 12345, "Data": "\r"}
158
+
159
+ Successfully Received > {"time": "2021-12-20 19:50:07.989914", "ID": 12345, "Data": "\n"}
160
+
161
+
162
+
163
+ ```
134
164
 
135
165
 
136
166
 
@@ -252,6 +282,80 @@
252
282
 
253
283
  ```
254
284
 
285
+ **実行結果**
286
+
287
+ ```
288
+
289
+ Successfully Received > {"time": "2021-12-20 19:53:00.254192", "ID": 12345, "Data": "0\r\n"}
290
+
291
+ Successfully Received > {"time": "2021-12-20 19:53:01.258051", "ID": 12345, "Data": "0\r\n0\r\n"}
292
+
293
+ Successfully Received > {"time": "2021-12-20 19:53:02.257321", "ID": 12345, "Data": "0\r\n0\r\n0\r\n"}
294
+
295
+ Successfully Received > {"time": "2021-12-20 19:53:03.256606", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n"}
296
+
297
+ Successfully Received > {"time": "2021-12-20 19:53:04.260266", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n"}
298
+
299
+ Successfully Received > {"time": "2021-12-20 19:53:05.263327", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n400\r\n"}
300
+
301
+ Successfully Received > {"time": "2021-12-20 19:53:06.262898", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n400\r\n402\r\n"}
302
+
303
+ Successfully Received > {"time": "2021-12-20 19:53:07.266468", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n400\r\n402\r\n409\r\n"}
304
+
305
+ Successfully Received > {"time": "2021-12-20 19:53:08.270060", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n400\r\n402\r\n409\r\n402\r\n"}
306
+
307
+ Successfully Received > {"time": "2021-12-20 19:53:09.269093", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n400\r\n402\r\n409\r\n402\r\n402\r\n"}
308
+
309
+ Successfully Received > {"time": "2021-12-20 19:53:10.272321", "ID": 12345, "Data": "0\r\n0\r\n0\r\n0\r\n400\r\n400\r\n402\r\n409\r\n402\r\n402\r\n411\r\n"}
310
+
311
+ ```
312
+
313
+
314
+
315
+ これは配列だからかなと感じています
316
+
317
+
318
+
319
+
320
+
321
+ 下のようになればいいなという風に考えています。
322
+
323
+ (受信側プログラムはHttp.jsというプログラムで受信しています。)
324
+
325
+
326
+
327
+ **理想のプログラム完成の実行例**
328
+
329
+ ```
330
+
331
+ Successfully Received > {"time": "2021-12-20 19:53:00.254192", "ID": 12345, "Data": "0"}
332
+
333
+ Successfully Received > {"time": "2021-12-20 19:53:01.258051", "ID": 12345, "Data": "0"}
334
+
335
+ Successfully Received > {"time": "2021-12-20 19:53:02.257321", "ID": 12345, "Data": "0"}
336
+
337
+ Successfully Received > {"time": "2021-12-20 19:53:03.256606", "ID": 12345, "Data": "0"}
338
+
339
+ Successfully Received > {"time": "2021-12-20 19:53:04.260266", "ID": 12345, "Data": "400"}
340
+
341
+ Successfully Received > {"time": "2021-12-20 19:53:05.263327", "ID": 12345, "Data": "400"}
342
+
343
+ Successfully Received > {"time": "2021-12-20 19:53:06.262898", "ID": 12345, "Data": "402"}
344
+
345
+ Successfully Received > {"time": "2021-12-20 19:53:07.266468", "ID": 12345, "Data": "409"}
346
+
347
+ Successfully Received > {"time": "2021-12-20 19:53:08.270060", "ID": 12345, "Data": "402"}
348
+
349
+ Successfully Received > {"time": "2021-12-20 19:53:09.269093", "ID": 12345, "Data": "402"}
350
+
351
+ Successfully Received > {"time": "2021-12-20 19:53:10.272321", "ID": 12345, "Data": "411"}
352
+
353
+ Successfully Received > {"time": "2021-12-20 19:53:11.271874", "ID": 12345, "Data": "409"}
354
+
355
+ Successfully Received > {"time": "2021-12-20 19:53:12.275307", "ID": 12345, "Data": "409"}
356
+
357
+ ```
358
+
255
359
 
256
360
 
257
361
 
@@ -381,3 +485,99 @@
381
485
 
382
486
 
383
487
  ご回答いただけると嬉しいです。よろしくお願いします。
488
+
489
+
490
+
491
+
492
+
493
+ **受信側のプログラム(Node.js)**
494
+
495
+ ```recive
496
+
497
+
498
+
499
+ var http = require('http');
500
+
501
+
502
+
503
+
504
+
505
+ var server = http.createServer();
506
+
507
+
508
+
509
+
510
+
511
+ server.on('request', function(req,res){
512
+
513
+
514
+
515
+ if(req.method == 'POST'){
516
+
517
+
518
+
519
+ res.writeHead(200, {'Content-Type' : req.headers['content-type']});
520
+
521
+
522
+
523
+
524
+
525
+ req.on('data', function(data){
526
+
527
+
528
+
529
+ var text = data.toString('utf8');
530
+
531
+
532
+
533
+ res.write('Successfully Received > ' + text);
534
+
535
+
536
+
537
+
538
+
539
+ console.log(req.method + ' "' + req.headers['user-agent'] + '"');
540
+
541
+ console.log('Client Request > ' + data);
542
+
543
+ });
544
+
545
+
546
+
547
+
548
+
549
+ req.on('end', function(){
550
+
551
+ // スマートフォンへのデータの返信を終了
552
+
553
+ res.end();
554
+
555
+ });
556
+
557
+ }
558
+
559
+
560
+
561
+ else {
562
+
563
+ res.writeHead(200, {'Content-Type': 'text/plain'});
564
+
565
+ res.write('Hello World\n');
566
+
567
+ res.end();
568
+
569
+ }
570
+
571
+ });
572
+
573
+
574
+
575
+
576
+
577
+ server.listen(3000);
578
+
579
+
580
+
581
+
582
+
583
+ ```

1

誤字、IPアドレスの編集(プライバシー配慮)

2021/12/20 11:05

投稿

hirokitrain13
hirokitrain13

スコア0

test CHANGED
File without changes
test CHANGED
@@ -50,11 +50,7 @@
50
50
 
51
51
  def upload_data(json_data):
52
52
 
53
- #url="http://192.168.0.18:3000" #home
53
+ #url="http://192.168.0.11:3000" #home
54
-
55
- #url = "http://172.31.145.166:3000" # Lab-Server IP
56
-
57
- url="http://192.168.100.65:3000"
58
54
 
59
55
  method = "POST"
60
56
 
@@ -174,11 +170,7 @@
174
170
 
175
171
  def upload_data(json_data):
176
172
 
177
- #url="http://192.168.0.18:3000" #home
173
+ #url="http://192.168.0.11:3000" #home
178
-
179
- #url = "http://172.31.145.166:3000" # Lab-Server IP
180
-
181
- url="http://192.168.100.65:3000"
182
174
 
183
175
  method = "POST"
184
176
 
@@ -384,7 +376,7 @@
384
376
 
385
377
 
386
378
 
387
- 二酸化炭素センサーを使用しています。
379
+ 二酸化炭素センサーを使用しています。配線は間違えておらず、Arduino付帯のシリアルモニタでは正しく出力されることを確認しています。
388
380
 
389
381
 
390
382