@@ -29,10 +29,12 @@ BootMode
29
29
30
30
Adafruit_NeoPixel _NefryLEDNeo;
31
31
Adafruit_DotStar _NefryLEDStar;
32
+ bool connectAnFlg = false ;
32
33
// main
33
34
34
35
void Nefry_lib::nefry_init () {
35
36
/* Display設定 */
37
+ connectAnFlg = false ;
36
38
delay (10 );
37
39
NefryDisplay.begin ();// logo表示
38
40
if (boardId == 3 ) {
@@ -96,6 +98,9 @@ void Nefry_lib::nefry_loop() {
96
98
if (_nefryWifiWait > 1000 ) {// WiFiに接続する間隔を10秒ごとに修正
97
99
_nefryWifiWait = 0 ;
98
100
NefryWiFi.run ();
101
+ if (connectAnFlg != true ) {
102
+ connectAnFlg = setAnalyticsData (" connect" );
103
+ }
99
104
}
100
105
}
101
106
}
@@ -459,4 +464,81 @@ bool Nefry_lib::getDisplayStatusEnabled() {
459
464
return _displayStatusFlg;
460
465
}
461
466
467
+ bool Nefry_lib::setAnalyticsData (String action) {
468
+ bool state = false ;
469
+ if (WiFi.status () == WL_CONNECTED) {
470
+ WiFiClient client;
471
+ const int httpPort = 80 ;
472
+ if (!client.connect (" google-analytics.com" , httpPort)) {
473
+ // Serial.println("connection failed");
474
+ return state;
475
+ }
476
+
477
+ // We now create a URI for the request
478
+ String url = " /collect?v=1&t=event&tid=UA-78080011-2&cid=NefryBT&ec=" ;
479
+ url += " NefryBT" ;
480
+ switch (boardId) {
481
+ case 1 :
482
+ url += " r1" ;
483
+ break ;
484
+ case 2 :
485
+ url += " r2" ;
486
+ break ;
487
+ case 3 :
488
+ url += " r3" ;
489
+ break ;
490
+ default :
491
+ url += " error" ;
492
+ break ;
493
+ }
494
+ url += " &el=v" ;
495
+ url += getVersion ();
496
+ url += " &ea=" ;
497
+ url += action;
498
+
499
+
500
+ // Serial.print("Requesting URL: ");
501
+ // Serial.println(url);
502
+
503
+ // This will send the request to the server
504
+ client.print (String (" GET " ) + url + " HTTP/1.1\r\n " +
505
+ " Host: google-analytics.com\r\n " +
506
+ " Connection: close\r\n\r\n " );
507
+ unsigned long timeout = millis ();
508
+ while (client.available () == 0 ) {
509
+ if (millis () - timeout > 5000 ) {
510
+ // Serial.println(">>> Client Timeout !");
511
+ client.stop ();
512
+ return state;
513
+ }
514
+ }
515
+
516
+ // Read all the lines of the reply from server and print them to Serial
517
+ while (client.available ()) {
518
+ size_t len = client.available ();
519
+ if (len > 0 ) {
520
+ String headerLine = client.readStringUntil (' \n ' );
521
+ headerLine.trim (); // remove \r
522
+ // Serial.print(headerLine);
523
+ log_d (" [HTTP-Client][handleHeaderResponse] RX: '%s'" , headerLine.c_str ());
524
+
525
+ if (headerLine.startsWith (" HTTP/1." )) {
526
+ int _returnCode = headerLine.substring (9 , headerLine.indexOf (' ' , 9 )).toInt ();
527
+ // Serial.printf("[HTTP] GET... code: %d\n", _returnCode);
528
+ if (_returnCode == 200 ) {
529
+ state = true ;
530
+ break ;
531
+ }
532
+ else {
533
+ state = false ;
534
+ break ;
535
+ }
536
+ }
537
+ }
538
+ }
539
+ client.stop ();
540
+ }
541
+ return state;
542
+ }
543
+
462
544
Nefry_lib Nefry;
0 commit comments