質問編集履歴

3

Wifi情報の書き換え

2020/11/10 13:34

投稿

Letemon
Letemon

スコア4

test CHANGED
File without changes
test CHANGED
@@ -90,7 +90,7 @@
90
90
 
91
91
  WiFiUDP wifiUdp;
92
92
 
93
- const char *pc_addr = "??????????????"; //"???????";//相手のipアドレス(com4:192.168.11.22)
93
+ const char *pc_addr = "??????????????"; //"???????";//相手のipアドレス(com4:??????)
94
94
 
95
95
  const int pc_port = 50008; //送信先のポート
96
96
 

2

受信側コードの追加

2020/11/10 13:34

投稿

Letemon
Letemon

スコア4

test CHANGED
File without changes
test CHANGED
@@ -400,12 +400,254 @@
400
400
 
401
401
  }
402
402
 
403
+
404
+
403
405
  ```
404
406
 
405
-
407
+ ```ここに言語を入力
408
+
409
+ 受信側
410
+
411
+
412
+
413
+ #include <M5StickC.h>
414
+
415
+ #include <driver/i2s.h>
416
+
417
+ #include <WiFi.h>
418
+
419
+ #include <WiFiUDP.h>
420
+
421
+
422
+
423
+ #define htonl(x) ( ((x)<<24 & 0xFF000000UL) | \
424
+
425
+ ((x)<< 8 & 0x00FF0000UL) | \
426
+
427
+ ((x)>> 8 & 0x0000FF00UL) | \
428
+
429
+ ((x)>>24 & 0x000000FFUL) )
430
+
431
+
432
+
433
+ #define PIN_CLK (0) // I2S Clock PIN
434
+
435
+ #define PIN_DATA (34) // I2S Data PIN
436
+
437
+ #define SAMPLING_RATE (16384) // サンプリングレート(44100, 22050, 16384, more...)
438
+
439
+ #define BUFFER_LEN (1024) // バッファサイズ
440
+
441
+ //#define STORAGE_LEN (102400) // 本体保存容量(MAX 100K前後)
442
+
443
+ #define STORAGE_LEN (52400)
444
+
445
+
446
+
447
+ const char* ssid = "???????????";
448
+
449
+ const char* password = "?????????";
450
+
451
+ WiFiUDP wifiUdp;
452
+
453
+ const char *pc_addr = "??????????"; //"????????";//相手のipアドレス
454
+
455
+ const int pc_port = 50007; //送信先のポート
456
+
457
+ const int my_port = 50008; //自身のポート
458
+
459
+
460
+
461
+ uint8_t receive_soundBuffer[BUFFER_LEN]; // DMA転送バッファ
462
+
463
+ uint8_t receive_soundStorage[STORAGE_LEN]; // サウンドデータ保存領域
464
+
465
+ uint8_t receive_soundStorage_tmp[185]; // サウンドデータ保存領域
466
+
467
+
468
+
469
+ bool recFlag = false; // 録音状態
470
+
471
+ int recPos = 0; // 録音の長さ
472
+
473
+
474
+
475
+ // 再生をする
476
+
477
+ void i2sPlay(){
478
+
479
+ //省略
480
+
481
+ }
482
+
483
+
484
+
485
+ void wifi_receive() {
486
+
487
+ int num_packet = wifiUdp.parsePacket();
488
+
489
+ if (num_packet){
490
+
491
+ Serial.print("num_packet : ");
492
+
493
+ Serial.println(num_packet);
494
+
495
+ int recPos_tmp,recPos_a,recPos_b;
496
+
497
+ int j = 0;
498
+
499
+ int send_num;//何回目のsendか
500
+
501
+ int send_num_tmp = 2;//次に受け取りたいsend_numの番号
502
+
503
+ send_num = wifiUdp.read();
504
+
505
+ recPos_a = wifiUdp.read();
506
+
507
+ recPos_b = wifiUdp.read();
508
+
509
+ recPos_tmp = recPos_a*256 + recPos_b;//1回で送られた録音の長さ
510
+
511
+ recPos += recPos_tmp;//最終的な録音の長さ
512
+
513
+ Serial.print("recPos_tmp : ");
514
+
515
+ Serial.println(recPos_tmp);
516
+
517
+ delay(5);
518
+
519
+ while(1){
520
+
521
+ num_packet = wifiUdp.parsePacket();
522
+
523
+ if (num_packet){
524
+
525
+ send_num = wifiUdp.read();
526
+
527
+ Serial.print("send_num : ");
528
+
529
+ Serial.println(send_num);
530
+
531
+ if(send_num == send_num_tmp){
532
+
533
+ Serial.println("Receive middle");
534
+
535
+ int len = wifiUdp.read(receive_soundStorage_tmp,num_packet-1);
536
+
537
+ for(int i=0;i<len;i++){
538
+
539
+ receive_soundStorage[i] = receive_soundStorage_tmp[i];
540
+
541
+ }
542
+
543
+ send_num_tmp++;
544
+
545
+ if(j<recPos_tmp){
546
+
547
+ j += len;
548
+
549
+ }else{break;}
550
+
551
+ }
552
+
553
+ }else{
554
+
555
+ Serial.println("num_packet = 0");
556
+
557
+ delay(5);
558
+
559
+ }
560
+
561
+ }
562
+
563
+ Serial.println("Receive End");
564
+
565
+ }
566
+
567
+ }
568
+
569
+
570
+
571
+ void setup() {
572
+
573
+ M5.begin();
574
+
575
+ M5.Lcd.setRotation(3);
576
+
577
+ M5.Lcd.fillScreen(WHITE);
578
+
579
+ M5.Lcd.setTextColor(BLACK, WHITE);
580
+
581
+ M5.Lcd.println("Sound Recorder");
582
+
583
+ M5.Lcd.println("BtnA Record");
584
+
585
+ M5.Lcd.println("BtnB Play");
586
+
587
+
588
+
589
+ WiFi.begin(ssid, password);
590
+
591
+ while( WiFi.status() != WL_CONNECTED) {
592
+
593
+ M5.Lcd.print(".");
594
+
595
+ delay(500);
596
+
597
+ }
598
+
599
+ M5.Lcd.print("\r\nWiFi connected\r\nIP address: ");
600
+
601
+ M5.Lcd.println(WiFi.localIP());
602
+
603
+
604
+
605
+ wifiUdp.begin(my_port);
606
+
607
+ delay(500);//wifiUdp.begin()の処理を待つ時間
608
+
609
+ M5.update();
610
+
611
+ }
612
+
613
+
614
+
615
+ void loop() {
616
+
617
+ wifi_receive();
618
+
619
+
620
+
621
+ if ( M5.BtnB.wasReleased() ) {
622
+
623
+ Serial.println("sizeof : ");
624
+
625
+ Serial.println(sizeof(receive_soundStorage));
626
+
627
+ // 再生スタート
628
+
629
+ M5.Lcd.setCursor(0, 24);
630
+
631
+ M5.Lcd.println("Play...");
632
+
633
+ Serial.println("Play Start");
634
+
635
+ i2sPlay();
636
+
637
+ M5.Lcd.println("Play Stop");
638
+
639
+ Serial.println("Play Stop");
640
+
641
+ recPos = 0;
642
+
643
+ M5.update();
644
+
645
+ }
646
+
647
+
648
+
649
+ }
406
650
 
407
651
  ```
408
652
 
409
-
410
-
411
653
  ```

1

Wifi情報の書き換え

2020/11/10 13:29

投稿

Letemon
Letemon

スコア4

test CHANGED
File without changes
test CHANGED
@@ -84,13 +84,13 @@
84
84
 
85
85
 
86
86
 
87
- const char* ssid = "Buffalo-G-1A18";
87
+ const char* ssid = "????????";
88
-
88
+
89
- const char* password = "tah75fft4hhsc";
89
+ const char* password = "?????????";
90
90
 
91
91
  WiFiUDP wifiUdp;
92
92
 
93
- const char *pc_addr = "192.168.11.22"; //"10.0.1.29";//相手のipアドレス(com4:192.168.11.22)
93
+ const char *pc_addr = "??????????????"; //"???????";//相手のipアドレス(com4:192.168.11.22)
94
94
 
95
95
  const int pc_port = 50008; //送信先のポート
96
96