Components and supplies
CAM WiFi
Arduino Oplà IoT Kit
Project description
Code
Arduino Audience Measurement
arduino
It's used to monitor Live TV audience. This is part of the #cloudgames2022 #arduinocloudgames and #acg2022
1/*************************************************************************************************** 2 Arduino Audience Measurement 3 Sketch created by Carlo Stramaglia for the Arduino Cloud Games. My pitch has been selected on 4 Jan 26th 2022. 5 This sketch aims to measure the behaviur of users while watching Television. 6 7 Please check on my youtube channel https://www.youtube.com/c/CarloStramaglia for latest projects 8 Project start date: Jan 30th 2022 9 Project end date: March 11th 2022 10 Location: Monza (Italy) 11 Board: Arduino MKR WiFi 1010 (Opl Kit) 12 Device: CAM WiFi see www.camwifi.it for more info 13 Thanks to mDNS library (Georg Kaindl) for the IP discovery section 14****************************************************************************************************/ 15 16#include "thingProperties.h" 17#include <ArduinoHttpClient.h> 18#include "defines.h" 19#include <ArduinoJson.h> 20#include <Arduino_MKRIoTCarrier.h> //Inserted 19-1 21 22MKRIoTCarrier carrier; //Inserted 19-1 23String hostname = BOARD_TYPE; 24WiFiUDP udp; 25#include <MDNS_Generic.h> 26int status = WL_IDLE_STATUS; // the Wifi radio's status 27MDNS mdns(udp); 28IPAddress foundIP; 29int canale = 1; 30uint32_t myCustomColor = carrier.leds.Color(255,100,50);// inserted 19-1 31File audience; 32 33const unsigned long RAI1 = 2283498029; // RAI1 triplet hashed 34const unsigned long RAI2 = 2284683324; // RAI2 triplet hashed 35const unsigned long RAI3 = 2284683323; // RAI3 triplet hashed 36const unsigned long RETE4 = 846798962; // Rete4 triplet hashed 37const unsigned long CANALE5 = 846798963; // Canale 5 triplet hashed 38const unsigned long ITALIA1 = 846798964; // Italia 1 triplet hashed 39const unsigned long LA7 = 3582080439; // La7 triplet hashed 40const unsigned long TV8 = 3540717605; // TV 8 triplet hashed 41const unsigned long NOVE = 3045597136; // Canale 9 triplet hashed 42 43float cRai1 = 0, cRai2 = 0, cGlobal = 0, cRai3 = 0, cRete4 = 0, cCanale5 = 0, cItalia1 = 0, cLa7 = 0, cTv8 = 0, cNove = 0, cUnknown = 0; 44 45char serverAddress[20] = " "; // CAM WiFi Address. Initially blank. 46int port = 24666; // CAM WiFi Port 47 48WiFiClient wifia; 49 50void printWifiStatus() 51{ 52 // print the SSID of the network you're attached to: 53 Serial.print("SSID: "); 54 Serial.println(WiFi.SSID()); 55 56 // print your board's IP address: 57 IPAddress ip = WiFi.localIP(); 58 Serial.print("IP Address: "); 59 Serial.println(ip); 60 61 // print the received signal strength: 62 long rssi = WiFi.RSSI(); 63 Serial.print("Signal strength (RSSI):"); 64 Serial.print(rssi); 65 Serial.println(" dBm"); 66} 67 68void serviceFound(const char* type, MDNSServiceProtocol /*proto*/, 69 const char* name, IPAddress ip, 70 unsigned short port, 71 const char* txtContent) 72{ 73 if (NULL == name) 74 { 75 Serial.print("Finished discovering services of type "); 76 Serial.println(type); 77 } 78 else 79 { 80 foundIP=ip; 81 sprintf(serverAddress, "%d.%d.%d.%d", foundIP[0], foundIP[1], foundIP[2],foundIP[3]); 82 Serial.print("Found: '"); 83 Serial.print(name); 84 Serial.print("' at "); 85 Serial.print(ip); 86 Serial.print(", port "); 87 Serial.print(port); 88 Serial.println(" (TCP)"); 89 90 if (txtContent) 91 { 92 Serial.print("\ txt record: "); 93 94 char buf[256]; 95 char len = *txtContent++; 96 int i = 0; 97 98 while (len) 99 { 100 i = 0; 101 102 while (len--) 103 buf[i++] = *txtContent++; 104 105 buf[i] = '\\0'; 106 Serial.print(buf); 107 len = *txtContent++; 108 109 if (len) 110 Serial.print(", "); 111 else 112 Serial.println(); 113 } 114 } 115 } 116} 117 118 119 120void setup() { 121 //CARRIER_CASE = false; 122 char inputdata[1] = {0x20}; 123 char datachar[20]; 124 unsigned long Fposition; 125 Serial.begin(9600); 126 delay(1500); 127 128 if (!carrier.begin()) 129 { 130 Serial.println("Carrier not connected, check connections"); 131 while (1); 132 } 133 134 carrier.leds.setBrightness(30); 135 // carrier.leds.fill(myCustomColor, 0, 5); 136 // carrier.leds.show(); 137 138 // Defined in thingProperties.h 139 initProperties(); 140 141 // Connect to Arduino IoT Cloud 142 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 143 144 /* 145 The following function allows you to obtain more information 146 related to the state of network and IoT Cloud connection and errors 147 the higher number the more granular information youll get. 148 The default is 0 (only errors). 149 Maximum is 4 150 */ 151 setDebugMessageLevel(0); 152 ArduinoCloud.printDebugInfo(); 153 154 Serial.print("\ 155Start WiFiDiscoveringServices on "); Serial.println(BOARD_NAME); 156 Serial.println(MDNS_GENERIC_VERSION); 157 158 Serial.print("Attempting to connect to SSID: "); Serial.println(SSID); 159 WiFi.begin(SSID, PASS); 160 161 delay(1000); 162 163 // attempt to connect to Wifi network: 164 while (status != WL_CONNECTED) 165 { 166 // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 167 status = WiFi.status(); 168 delay(1000); 169 } 170 171 printWifiStatus(); 172 173 hostname.toLowerCase(); 174 hostname.replace(" ", "-"); 175 hostname.replace("_", "-"); 176 177 Serial.print("Registering mDNS hostname: "); Serial.println(hostname); 178 Serial.print("To access, using "); Serial.print(hostname); Serial.println(".local"); 179 180 mdns.begin(WiFi.localIP(), hostname.c_str()); 181 mdns.setServiceFoundCallback(serviceFound); 182 183 Serial.println("Reading audience.txt"); 184 audience = SD.open("audience.txt"); 185 if (audience) { 186 Serial.println("audience.txt:"); 187 188 for (int j = 0; j < 12; j++) { 189 for(int i = 0; inputdata[0] != '\r'; i++){ 190 audience.read(inputdata,1); 191 datachar[i] = inputdata[0]; 192 } 193 Fposition = audience.position(); 194 audience.seek(Fposition+1); 195 inputdata[0] = 0x20; 196 Serial.println(datachar); 197 switch (j) 198 { 199 case 0: 200 cGlobal = atof(datachar); 201 tGlobal = cGlobal-3600; 202 Serial.print("cGlobal in Float = "); 203 Serial.println(cGlobal); 204 break; 205 case 1: 206 cRai1 = atof(datachar); 207 tRai1 = cRai1/cGlobal*100; 208 Serial.print("cRai1 in Float = "); 209 Serial.println(cRai1); 210 break; 211 case 2: 212 cRai2 = atof(datachar); 213 tRai2 = cRai2/cGlobal*100; 214 Serial.print("cRai2 in Float = "); 215 Serial.println(cRai2); 216 break; 217 case 3: 218 cRai3 = atof(datachar); 219 tRai3 = cRai3/cGlobal*100; 220 Serial.print("cRai3 in Float = "); 221 Serial.println(cRai3); 222 break; 223 case 4: 224 cRete4 = atof(datachar); 225 tRete4 = cRete4/cGlobal*100; 226 Serial.print("cRete4 in Float = "); 227 Serial.println(cRete4); 228 break; 229 case 5: 230 cCanale5 = atof(datachar); 231 tCanale5 = cCanale5/cGlobal*100; 232 Serial.print("cCanale5 in Float = "); 233 Serial.println(cCanale5); 234 break; 235 case 6: 236 cItalia1 = atof(datachar); 237 tItalia1 = cItalia1/cGlobal*100; 238 Serial.print("cItalia1 in Float = "); 239 Serial.println(cItalia1); 240 break; 241 case 7: 242 cLa7 = atof(datachar); 243 tLa7 = cLa7/cGlobal*100; 244 Serial.print("cLa7 in Float = "); 245 Serial.println(cLa7); 246 break; 247 case 8: 248 cTv8 = atof(datachar); 249 tTv8 = cTv8/cGlobal*100; 250 Serial.print("cTv8 in Float = "); 251 Serial.println(cTv8); 252 break; 253 case 9: 254 cNove = atof(datachar); 255 tNove = cNove/cGlobal*100; 256 Serial.print("cNove in Float = "); 257 Serial.println(cNove); 258 break; 259 case 10: 260 cUnknown = atof(datachar); 261 tUnknown = cUnknown/cGlobal*100; 262 Serial.print("cUnknown in Float = "); 263 Serial.println(cUnknown); 264 break; 265 case 11: 266 startDate = atof(datachar); 267 Serial.print("startDate = "); 268 Serial.println(startDate); 269 break; 270 } 271 272 } 273 // close the file: 274 Serial.println("Closing file audience.txt"); 275 audience.close(); 276 } else { 277 // if the file didn't open, print an error: 278 Serial.println("error opening audience.txt"); 279 } 280 281 282} 283 284void loop() { 285 ArduinoCloud.update(); 286 char serviceName[256]="_sdtvwcam"; // Standard name of the CAM WiFi 287 upTime = WiFi.getTime(); 288 289 if (serverAddress[0] != 0x20) 290 { 291 if (SD.remove("audience.txt") != true) 292 Serial.println("removal of audience.txt not successful"); 293 audience = SD.open("audience.txt",FILE_WRITE); 294 if (audience) { 295 Serial.print("Writing to audience.txt..."); 296 audience.println(cGlobal); 297 audience.println(cRai1); 298 audience.println(cRai2); 299 audience.println(cRai3); 300 audience.println(cRete4); 301 audience.println(cCanale5); 302 audience.println(cItalia1); 303 audience.println(cLa7); 304 audience.println(cTv8); 305 audience.println(cNove); 306 audience.println(cUnknown); 307 audience.println(startDate); 308 // close the file: 309 audience.close(); 310 Serial.println("done."); 311 } else { 312 // if the file didn't open, print an error: 313 Serial.println("error opening audience.txt"); 314 } 315 } 316 317 if (serverAddress[0] != 0x20) 318 { 319 carrier.leds.fill(myCustomColor, 0, 5); 320 carrier.leds.show(); 321 tVon = true; 322 rai1 = false; 323 rai2 = false; 324 rai3 = false; 325 rete4 = false; 326 canale5 = false; 327 italia1 = false; 328 la7 = false; 329 tv8 = false; 330 nove = false; 331 unknownch = false; 332 333 } 334 else 335 { 336 carrier.leds.fill(myCustomColor, 0, 1); 337 carrier.leds.show(); 338 tVon = false; 339 rai1 = false; 340 rai2 = false; 341 rai3 = false; 342 rete4 = false; 343 canale5 = false; 344 italia1 = false; 345 la7 = false; 346 tv8 = false; 347 nove = false; 348 unknownch = false; 349 } 350 351 // You can use the "isDiscoveringService()" function to find out whether the 352 // mDNS library is currently discovering service instances. 353 // If so, we skip this input, since we want our previous request to continue. 354 if (!mdns.isDiscoveringService()) 355 { 356 Serial.print("Discovering services of type '"); 357 Serial.print(serviceName); 358 Serial.println("' via Multi-Cast DNS (Bonjour)..."); 359 360 mdns.startDiscoveringService(serviceName, MDNSServiceTCP, 5000); 361 } 362 363 if (serverAddress[0] != 0x20) 364 readChannel(); 365 366 // This actually runs the mDNS module. YOU HAVE TO CALL THIS PERIODICALLY, 367 // OR NOTHING WILL WORK! 368 // Preferably, call it once per loop(). 369 mdns.run(); 370} 371 372 373void readChannel() { 374 DynamicJsonDocument doc(1024); 375 //DynamicJsonDocument TV(1024); 376 //char returnFromCAM[500]; 377 char channeltuned[13]; 378 unsigned long chTuned; 379 char foundOID[4]; 380 Serial.println ("Network IP of CAMWiFi OK!"); 381 Serial.println (cGlobal); 382 delay (5000); 383 384 tRai1 = cRai1/cGlobal*100; 385 Serial.print("tRai1 = "); 386 Serial.println(tRai1); 387 tRai2 = cRai2/cGlobal*100; 388 Serial.print("tRai2 = "); 389 Serial.println(tRai2); 390 tRai3 = cRai3/cGlobal*100; 391 Serial.print("tRai3 = "); 392 Serial.println(tRai3); 393 tRete4 = cRete4/cGlobal*100; 394 Serial.print("tRete4 = "); 395 Serial.println(tRete4); 396 tCanale5 = cCanale5/cGlobal*100; 397 Serial.print("tCanale5 = "); 398 Serial.println(tCanale5); 399 tItalia1 = cItalia1/cGlobal*100; 400 Serial.print("tItalia1 = "); 401 Serial.println(tItalia1); 402 tLa7 = cLa7/cGlobal*100; 403 Serial.print("tLa7 = "); 404 Serial.println(tLa7); 405 tTv8 = cTv8/cGlobal*100; 406 Serial.print("tTv8 = "); 407 Serial.println(tTv8); 408 tNove = cNove/cGlobal*100; 409 Serial.print("tNove = "); 410 Serial.println(tNove); 411 tUnknown = cUnknown/cGlobal*100; 412 Serial.print("tUnknown = "); 413 Serial.println(tUnknown); 414 tGlobal = cGlobal-3600; 415 upTime = WiFi.getTime(); 416 cGlobal = cGlobal + 5; 417 418 419 420 String contentType = "application/json"; 421 char postHello[250] = "command:deviceHello,\ 422\ clientID:wapp,\ 423 sessionID:0090FFA,\ 424 version:2,\ 425 param: {\ 426 }"; 427 HttpClient client = HttpClient(wifia, serverAddress, port); 428 client.post("/deviceHello", contentType, postHello); 429 // read the status code and body of the response 430 int statusCode = client.responseStatusCode(); 431 String returnFromCAM = client.responseBody(); 432 Serial.print("Status code: "); 433 Serial.println(statusCode); 434 Serial.print("Response: "); 435 Serial.println(returnFromCAM); 436 DeserializationError error = deserializeJson(doc, returnFromCAM); 437 if (error) { 438 Serial.print(F("deserializeJson() failed: ")); 439 Serial.println(error.f_str()); 440 return; 441 } 442 443 const char* command = doc["command"]; 444 int Version = doc["version"]; 445 446 const char* OID = doc["data"]["TV"]["tuned_on"]["OID"]; 447 const char* TID = doc["data"]["TV"]["tuned_on"]["TID"]; 448 const char* SID = doc["data"]["TV"]["tuned_on"]["SID"]; 449 Serial.println (" "); 450 Serial.print("Command parsed = "); 451 Serial.println(command); 452 Serial.print("Version parsed = "); 453 Serial.println(Version); 454 Serial.print("Tuned On = "); 455 Serial.print(OID); 456 Serial.print(" "); 457 Serial.print(TID); 458 Serial.print(" "); 459 Serial.print(SID); 460 Serial.println(" "); 461 Serial.println(" "); 462 463 sprintf(channeltuned,"%s%s%s",OID,TID,SID); 464 Serial.println(channeltuned); 465 //chTuned=atoi(channeltuned); 466 chTuned = hash(channeltuned); 467 Serial.print("Channel with Hash = "); 468 Serial.println(chTuned); 469 470 switch (chTuned) 471 { 472 case RAI1: 473 Serial.println("RAI 1"); 474 rai1 = true; 475 cRai1 = cRai1+5; 476 break; 477 case RAI2: 478 Serial.println("RAI 2"); 479 // rai1 = false; 480 rai2 = true; 481 cRai2 = cRai2 + 5; 482 break; 483 case RAI3: 484 Serial.println("RAI 3"); 485 rai3 = true; 486 cRai3 = cRai3 + 5; 487 break; 488 case RETE4: 489 Serial.println("RETE 4"); 490 rete4 = true; 491 cRete4 = cRete4 + 5; 492 break; 493 case CANALE5: 494 Serial.println("CANALE 5"); 495 canale5 = true; 496 cCanale5 = cCanale5 + 5; 497 break; 498 case ITALIA1: 499 Serial.println("ITALIA 1"); 500 italia1 = true; 501 cItalia1 = cItalia1 + 5; 502 break; 503 case LA7: 504 Serial.println("LA7"); 505 la7 = true; 506 cLa7 = cLa7 + 5; 507 break; 508 case TV8: 509 Serial.println("TV 8"); 510 tv8 = true; 511 cTv8 = cTv8 + 5; 512 break; 513 case NOVE: 514 Serial.println("CANALE 9"); 515 nove = true; 516 cNove = cNove + 5; 517 break; 518 default: 519 unknownch = true; 520 cUnknown = cUnknown + 5; 521 } 522} 523 524unsigned long hash(char *str) 525{ 526 unsigned long hash = 5381; 527 int c; 528 529 while (c = *str++) 530 hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 531 532 return hash; 533} 534 535 536 537/* 538 Since BReset is READ_WRITE variable, onBResetChange() is 539 executed every time a new value is received from IoT Cloud. 540*/ 541void onBResetChange() { 542 // Add your code here to act upon BReset change 543 Serial.println(); 544 Serial.println(); 545 Serial.println(); 546 Serial.println(); 547 Serial.println(); 548 Serial.print("bReset Changed! = "); 549 Serial.println(bReset); 550 Serial.println(); 551 Serial.println(); 552 Serial.println(); 553 Serial.println(); 554 Serial.println(); 555 if (bReset == false) 556 return; 557 Serial.println(); 558 Serial.println(); 559 Serial.println(); 560 Serial.println(); 561 Serial.println(); 562 Serial.println("Reset Button Pressed TRUE!"); 563 Serial.println(); 564 Serial.println(); 565 Serial.println(); 566 Serial.println(); 567 Serial.println(); 568 569 cGlobal = 0.00; 570 cRai1 = 0.00; 571 cRai2 = 0.00; 572 cRai3 = 0.00; 573 cRete4 = 0.00; 574 cCanale5 = 0.00; 575 cItalia1 = 0.00; 576 cLa7 = 0.00; 577 cTv8 = 0.00; 578 cNove = 0.00; 579 cUnknown = 0.00; 580 startDate = WiFi.getTime(); 581 582} 583
Definition file of the Audience measurement
arduino
1/**************************************************************************************************************************** 2 defines.h 3 mDNS library to support mDNS (registering services) and DNS-SD (service discovery). 4 5 Based on and modified from https://github.com/arduino-libraries/ArduinoMDNS 6 Built by Khoi Hoang https://github.com/khoih-prog/MDNS_Generic 7 Licensed under MIT license 8 9 Original Author: Georg Kaindl (http://gkaindl.com) 10 11 This file is part of Arduino EthernetBonjour. 12 13 EthernetBonjour is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License 14 as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 15 16 EthernetBonjour is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public License along with EthernetBonjour. 20 If not, see <http://www.gnu.org/licenses/>. 21 *****************************************************************************************************************************/ 22 23#ifndef defines_h 24#define defines_h 25 26#define SYSTEM_ENDIAN _ENDIAN_BIG_ 27 28#define MDNS_DEBUG_PORT Serial 29#define _MDNS_LOGLEVEL_ 1 30 31#define DEBUG_WIFININA_PORT Serial 32// Debug Level from 0 to 4 33#define _WIFININA_LOGLEVEL_ 1 34 35#if defined(ESP32) 36 37 #define BOARD_TYPE ARDUINO_BOARD 38 #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) 39 40 #define WIFI_NETWORK_ESP true 41 #define WIFI_NETWORK_TYPE WIFI_NETWORK_ESP 42 43#elif defined(ESP8266) 44 #error ESP8266 not supported. Please use native ESP8266mDNS library 45#endif 46 47#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \\ 48 || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \\ 49 || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \\ 50 || defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD21E18A__) || defined(__SAMD51__) || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) \\ 51 || defined(__SAMD51G19A__) || defined(__SAMD51P19A__) || defined(__SAMD21G18A__) ) 52 #if defined(WIFININA_USE_SAMD) 53 #undef WIFININA_USE_SAMD 54 #endif 55 #define WIFININA_USE_SAMD true 56 57 #if defined(ARDUINO_SAMD_ZERO) 58 #define BOARD_TYPE "SAMD Zero" 59 #elif defined(ARDUINO_SAMD_MKR1000) 60 #define BOARD_TYPE "SAMD MKR1000" 61 #elif defined(ARDUINO_SAMD_MKRWIFI1010) 62 #define BOARD_TYPE "SAMD MKRWIFI1010" 63 #define WIFI_NETWORK_WIFI101 true 64 #define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFI101 65 #elif defined(ARDUINO_SAMD_NANO_33_IOT) 66 #define BOARD_TYPE "SAMD NANO_33_IOT" 67 #define WIFI_NETWORK_WIFININA true 68 #define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA 69 #elif defined(ARDUINO_SAMD_MKRFox1200) 70 #define BOARD_TYPE "SAMD MKRFox1200" 71 #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) 72 #define BOARD_TYPE "SAMD MKRWAN13X0" 73 #elif defined(ARDUINO_SAMD_MKRGSM1400) 74 #define BOARD_TYPE "SAMD MKRGSM1400" 75 #elif defined(ARDUINO_SAMD_MKRNB1500) 76 #define BOARD_TYPE "SAMD MKRNB1500" 77 #elif defined(ARDUINO_SAMD_MKRVIDOR4000) 78 #define BOARD_TYPE "SAMD MKRVIDOR4000" 79 #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) 80 #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" 81 #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) 82 #define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS" 83 #elif defined(ADAFRUIT_METRO_M0_EXPRESS) 84 #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" 85 #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) 86 #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" 87 #elif defined(ADAFRUIT_GEMMA_M0) 88 #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" 89 #elif defined(ADAFRUIT_TRINKET_M0) 90 #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" 91 #elif defined(ADAFRUIT_ITSYBITSY_M0) 92 #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" 93 #elif defined(ARDUINO_SAMD_HALLOWING_M0) 94 #define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0" 95 #elif defined(ADAFRUIT_METRO_M4_EXPRESS) 96 #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" 97 #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) 98 #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" 99 #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) 100 #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" 101 #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) 102 #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" 103 #elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS) 104 #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" 105 #elif defined(ADAFRUIT_PYPORTAL) 106 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" 107 #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) 108 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO" 109 #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) 110 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" 111 #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) 112 #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" 113 #elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS) 114 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" 115 #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) 116 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" 117 #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) 118 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" 119 #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) 120 #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" 121 #elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS) 122 #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" 123 #elif defined(SEEED_WIO_TERMINAL) 124 #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" 125 #elif defined(SEEED_FEMTO_M0) 126 #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" 127 #elif defined(SEEED_XIAO_M0) 128 #define BOARD_TYPE "SAMD SEEED_XIAO_M0" 129 #elif defined(Wio_Lite_MG126) 130 #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" 131 #elif defined(WIO_GPS_BOARD) 132 #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" 133 #elif defined(SEEEDUINO_ZERO) 134 #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" 135 #elif defined(SEEEDUINO_LORAWAN) 136 #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" 137 #elif defined(SEEED_GROVE_UI_WIRELESS) 138 #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" 139 #elif defined(__SAMD21E18A__) 140 #define BOARD_TYPE "SAMD21E18A" 141 #elif defined(__SAMD21G18A__) 142 #define BOARD_TYPE "SAMD21G18A" 143 #elif defined(__SAMD51G19A__) 144 #define BOARD_TYPE "SAMD51G19A" 145 #elif defined(__SAMD51J19A__) 146 #define BOARD_TYPE "SAMD51J19A" 147 #elif defined(__SAMD51P19A__) 148 #define BOARD_TYPE "__SAMD51P19A__" 149 #elif defined(__SAMD51J20A__) 150 #define BOARD_TYPE "SAMD51J20A" 151 #elif defined(__SAM3X8E__) 152 #define BOARD_TYPE "SAM3X8E" 153 #elif defined(__CPU_ARC__) 154 #define BOARD_TYPE "CPU_ARC" 155 #elif defined(__SAMD51__) 156 #define BOARD_TYPE "SAMD51" 157 #else 158 #define BOARD_TYPE "SAMD Unknown" 159 #endif 160 161#endif 162 163#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \\ 164 defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \\ 165 defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) 166 #if defined(WIFININA_USE_NRF52) 167 #undef WIFININA_USE_NRF52 168 #endif 169 #define WIFININA_USE_NRF52 true 170 171 #if defined(NRF52840_FEATHER) 172 #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" 173 #elif defined(NRF52832_FEATHER) 174 #define BOARD_TYPE "NRF52832_FEATHER" 175 #elif defined(NRF52840_FEATHER_SENSE) 176 #define BOARD_TYPE "NRF52840_FEATHER_SENSE" 177 #elif defined(NRF52840_ITSYBITSY) 178 #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" 179 #elif defined(NRF52840_CIRCUITPLAY) 180 #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" 181 #elif defined(NRF52840_CLUE) 182 #define BOARD_TYPE "NRF52840_CLUE" 183 #elif defined(NRF52840_METRO) 184 #define BOARD_TYPE "NRF52840_METRO_EXPRESS" 185 #elif defined(NRF52840_PCA10056) 186 #define BOARD_TYPE "NORDIC_NRF52840DK" 187 #elif defined(NINA_B302_ublox) 188 #define BOARD_TYPE "NINA_B302_ublox" 189 #elif defined(NINA_B112_ublox) 190 #define BOARD_TYPE "NINA_B112_ublox" 191 #elif defined(PARTICLE_XENON) 192 #define BOARD_TYPE "PARTICLE_XENON" 193 #elif defined(MDBT50Q_RX) 194 #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" 195 #elif defined(ARDUINO_NRF52_ADAFRUIT) 196 #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" 197 #else 198 #define BOARD_TYPE "nRF52 Unknown" 199 #endif 200 201#endif 202 203#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) 204 #if defined(WIFININA_USE_SAMDUE) 205 #undef WIFININA_USE_SAMDUE 206 #endif 207 #define WIFININA_USE_SAMDUE true 208 209 // For SAM DUE 210 #if defined(ARDUINO_SAM_DUE) 211 #define BOARD_TYPE "SAM DUE" 212 #elif defined(__SAM3X8E__) 213 #define BOARD_TYPE "SAM SAM3X8E" 214 #else 215 #define BOARD_TYPE "SAM Unknown" 216 #endif 217 218#endif 219 220#if ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) || defined(STM32F7) || \\ 221 defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \\ 222 defined(STM32WB) || defined(STM32MP1) ) && !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 223 #if defined(WIFININA_USE_STM32) 224 #undef WIFININA_USE_STM32 225 #endif 226 #define WIFININA_USE_STM32 true 227 228 #if defined(STM32F0) 229 #warning STM32F0 board selected 230 #define BOARD_TYPE "STM32F0" 231 #elif defined(STM32F1) 232 #warning STM32F1 board selected 233 #define BOARD_TYPE "STM32F1" 234 #elif defined(STM32F2) 235 #warning STM32F2 board selected 236 #define BOARD_TYPE "STM32F2" 237 #elif defined(STM32F3) 238 #warning STM32F3 board selected 239 #define BOARD_TYPE "STM32F3" 240 #elif defined(STM32F4) 241 #warning STM32F4 board selected 242 #define BOARD_TYPE "STM32F4" 243 #elif defined(STM32F7) 244 #warning STM32F7 board selected 245 #define BOARD_TYPE "STM32F7" 246 #elif defined(STM32L0) 247 #warning STM32L0 board selected 248 #define BOARD_TYPE "STM32L0" 249 #elif defined(STM32L1) 250 #warning STM32L1 board selected 251 #define BOARD_TYPE "STM32L1" 252 #elif defined(STM32L4) 253 #warning STM32L4 board selected 254 #define BOARD_TYPE "STM32L4" 255 #elif defined(STM32H7) 256 #warning STM32H7 board selected 257 #define BOARD_TYPE "STM32H7" 258 #elif defined(STM32G0) 259 #warning STM32G0 board selected 260 #define BOARD_TYPE "STM32G0" 261 #elif defined(STM32G4) 262 #warning STM32G4 board selected 263 #define BOARD_TYPE "STM32G4" 264 #elif defined(STM32WB) 265 #warning STM32WB board selected 266 #define BOARD_TYPE "STM32WB" 267 #elif defined(STM32MP1) 268 #warning STM32MP1 board selected 269 #define BOARD_TYPE "STM32MP1" 270 #else 271 #warning STM32 unknown board selected 272 #define BOARD_TYPE "STM32 Unknown" 273 #endif 274 275#endif 276 277#ifdef CORE_TEENSY 278 279 #if defined(WIFININA_USE_TEENSY) 280 #undef WIFININA_USE_TEENSY 281 #endif 282 #define WIFININA_USE_TEENSY true 283 284 #if defined(__IMXRT1062__) 285 // For Teensy 4.1/4.0 286 #define BOARD_TYPE "TEENSY 4.1/4.0" 287 #elif defined(__MK66FX1M0__) 288 #define BOARD_TYPE "Teensy 3.6" 289 #elif defined(__MK64FX512__) 290 #define BOARD_TYPE "Teensy 3.5" 291 #elif defined(__MKL26Z64__) 292 #define BOARD_TYPE "Teensy LC" 293 #elif defined(__MK20DX256__) 294 #define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete) 295 #elif defined(__MK20DX128__) 296 #define BOARD_TYPE "Teensy 3.0" 297 #elif defined(__AVR_AT90USB1286__) 298 #error Teensy 2.0++ not supported yet 299 #elif defined(__AVR_ATmega32U4__) 300 #error Teensy 2.0 not supported yet 301 #else 302 // For Other Boards 303 #define BOARD_TYPE "Unknown Teensy Board" 304 #endif 305 306#endif 307 308#if ( defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || defined(ARDUINO_GENERIC_RP2040) ) 309 #if defined(WIFININA_USE_RP2040) 310 #undef WIFININA_USE_RP2040 311 #endif 312 #define WIFININA_USE_RP2040 true 313 314 // Default pin 5 (in Mbed) or 17 to SS/CS 315 #if defined(ARDUINO_ARCH_MBED) 316 // For RPI Pico using Arduino Mbed RP2040 core 317 // SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5 318 319 #define USE_THIS_SS_PIN 5 320 321 #if defined(BOARD_NAME) 322 #undef BOARD_NAME 323 #endif 324 325 #if defined(ARDUINO_NANO_RP2040_CONNECT) 326 #define BOARD_TYPE "MBED NANO_RP2040_CONNECT" 327 #define WIFI_NETWORK_WIFININA true 328 #define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA 329 #elif defined(ARDUINO_RASPBERRY_PI_PICO) 330 #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" 331 #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) 332 #define BOARD_TYPE "MBED ADAFRUIT_FEATHER_RP2040" 333 #elif defined(ARDUINO_GENERIC_RP2040) 334 #define BOARD_TYPE "MBED GENERIC_RP2040" 335 #else 336 #define BOARD_TYPE "MBED Unknown RP2040" 337 #endif 338 339 #else 340 // For RPI Pico using E. Philhower RP2040 core 341 // SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17 342 #define USE_THIS_SS_PIN 17 343 344 #endif 345 346 #define SS_PIN_DEFAULT USE_THIS_SS_PIN 347 348 // For RPI Pico 349 #warning Use RPI-Pico RP2040 architecture 350#endif 351 352#if ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 353 354 #if defined(BOARD_NAME) 355 #undef BOARD_NAME 356 #endif 357 358 #if defined(CORE_CM7) 359 #warning Using Portenta H7 M7 core 360 #define BOARD_TYPE "PORTENTA_H7_M7" 361 #else 362 #warning Using Portenta H7 M4 core 363 #define BOARD_TYPE "PORTENTA_H7_M4" 364 #endif 365 366 #define WIFI_NETWORK_PORTENTA_H7 true 367 #define WIFI_NETWORK_TYPE WIFI_NETWORK_PORTENTA_H7 368 369#elif (ESP32) 370 371 #define USE_WIFI_NINA false 372 373 // To use the default WiFi library here 374 #define USE_WIFI_CUSTOM false 375 376#endif 377 378#ifndef BOARD_NAME 379 #define BOARD_NAME BOARD_TYPE 380#endif 381 382#endif //defines_h 383
Clod Definition File for Arduino TV audience measurement project
arduino
1 2// Code generated by Arduino IoT Cloud, DO NOT EDIT. 3 4#include <ArduinoIoTCloud.h> 5#include <Arduino_ConnectionHandler.h> 6 7//const char THING_ID[] = "26f93dbd-eb78-4e57-8764-71926746b99c"; 8 9const char SSID[] = "SSID"; // Network SSID (name) 10const char PASS[] = "PASSWORD"; // Network password (use for WPA, or use as key for WEP) 11 12void onBResetChange(); 13 14bool rai1; 15bool rai2; 16bool rai3; 17bool rete4; 18bool canale5; 19bool italia1; 20bool la7; 21bool tv8; 22bool nove; 23bool tVon; 24bool unknownch; 25bool bReset=false; 26CloudTime upTime; 27CloudTime startDate; 28float tRai1 = 0, tRai2 = 0, tRai3 = 0, tRete4 = 0, tCanale5 = 0, tItalia1 = 0, tLa7 = 0, tTv8 = 0, tNove = 0, tUnknown, tGlobal = 0; 29 30void initProperties(){ 31 32 ArduinoCloud.addProperty(tGlobal, READ, ON_CHANGE, NULL); 33 ArduinoCloud.addProperty(rai1, READ, ON_CHANGE, NULL); 34 ArduinoCloud.addProperty(rai2, READ, ON_CHANGE, NULL); 35 ArduinoCloud.addProperty(rai3, READ, ON_CHANGE, NULL); 36 ArduinoCloud.addProperty(rete4, READ, ON_CHANGE, NULL); 37 ArduinoCloud.addProperty(canale5, READ, ON_CHANGE, NULL); 38 ArduinoCloud.addProperty(italia1, READ, ON_CHANGE, NULL); 39 ArduinoCloud.addProperty(la7, READ, ON_CHANGE, NULL); 40 ArduinoCloud.addProperty(tv8, READ, ON_CHANGE, NULL); 41 ArduinoCloud.addProperty(nove, READ, ON_CHANGE, NULL); 42 ArduinoCloud.addProperty(unknownch, READ, ON_CHANGE, NULL); 43 ArduinoCloud.addProperty(tVon, READ, ON_CHANGE, NULL); 44 ArduinoCloud.addProperty(tRai1, READ, ON_CHANGE, NULL); 45 ArduinoCloud.addProperty(tRai2, READ, ON_CHANGE, NULL); 46 ArduinoCloud.addProperty(tRai3, READ, ON_CHANGE, NULL); 47 ArduinoCloud.addProperty(tRete4, READ, ON_CHANGE, NULL); 48 ArduinoCloud.addProperty(tCanale5, READ, ON_CHANGE, NULL); 49 ArduinoCloud.addProperty(tItalia1, READ, ON_CHANGE, NULL); 50 ArduinoCloud.addProperty(tLa7, READ, ON_CHANGE, NULL); 51 ArduinoCloud.addProperty(tTv8, READ, ON_CHANGE, NULL); 52 ArduinoCloud.addProperty(tNove, READ, ON_CHANGE, NULL); 53 ArduinoCloud.addProperty(tUnknown, READ, ON_CHANGE, NULL); 54 ArduinoCloud.addProperty(upTime, READ, ON_CHANGE, NULL); 55 ArduinoCloud.addProperty(bReset, READWRITE, ON_CHANGE, onBResetChange); 56 ArduinoCloud.addProperty(startDate, READ, ON_CHANGE, NULL); 57 58} 59 60WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS); 61
Arduino Audience Measurement
arduino
It's used to monitor Live TV audience. This is part of the #cloudgames2022 #arduinocloudgames and #acg2022
1/*************************************************************************************************** 2 3 Arduino Audience Measurement 4 Sketch created by Carlo Stramaglia for the 5 Arduino Cloud Games. My pitch has been selected on 6 Jan 26th 2022. 7 This 8 sketch aims to measure the behaviur of users while watching Television. 9 10 11 Please check on my youtube channel https://www.youtube.com/c/CarloStramaglia for 12 latest projects 13 Project start date: Jan 30th 2022 14 Project end date: March 15 11th 2022 16 Location: Monza (Italy) 17 Board: Arduino MKR WiFi 1010 (Opl Kit) 18 19 Device: CAM WiFi see www.camwifi.it for more info 20 Thanks to mDNS library 21 (Georg Kaindl) for the IP discovery section 22****************************************************************************************************/ 23 24#include 25 "thingProperties.h" 26#include <ArduinoHttpClient.h> 27#include "defines.h" 28#include 29 <ArduinoJson.h> 30#include <Arduino_MKRIoTCarrier.h> //Inserted 19-1 31 32MKRIoTCarrier 33 carrier; //Inserted 19-1 34String hostname = BOARD_TYPE; 35WiFiUDP udp; 36#include 37 <MDNS_Generic.h> 38int status = WL_IDLE_STATUS; // the Wifi radio's status 39MDNS 40 mdns(udp); 41IPAddress foundIP; 42int canale = 1; 43uint32_t myCustomColor = 44 carrier.leds.Color(255,100,50);// inserted 19-1 45File audience; 46 47const unsigned 48 long RAI1 = 2283498029; // RAI1 triplet hashed 49const unsigned long RAI2 = 50 2284683324; // RAI2 triplet hashed 51const unsigned long RAI3 = 2284683323; 52 // RAI3 triplet hashed 53const unsigned long RETE4 = 846798962; // Rete4 triplet 54 hashed 55const unsigned long CANALE5 = 846798963; // Canale 5 triplet hashed 56const 57 unsigned long ITALIA1 = 846798964; // Italia 1 triplet hashed 58const unsigned 59 long LA7 = 3582080439; // La7 triplet hashed 60const unsigned long TV8 = 61 3540717605; // TV 8 triplet hashed 62const unsigned long NOVE = 3045597136; 63 // Canale 9 triplet hashed 64 65float cRai1 = 0, cRai2 = 0, cGlobal = 0, cRai3 66 = 0, cRete4 = 0, cCanale5 = 0, cItalia1 = 0, cLa7 = 0, cTv8 = 0, cNove = 0, cUnknown 67 = 0; 68 69char serverAddress[20] = " "; // CAM WiFi Address. Initially blank. 70int 71 port = 24666; // CAM WiFi Port 72 73WiFiClient wifia; 74 75void printWifiStatus() 76{ 77 78 // print the SSID of the network you're attached to: 79 Serial.print("SSID: 80 "); 81 Serial.println(WiFi.SSID()); 82 83 // print your board's IP address: 84 85 IPAddress ip = WiFi.localIP(); 86 Serial.print("IP Address: "); 87 Serial.println(ip); 88 89 90 // print the received signal strength: 91 long rssi = WiFi.RSSI(); 92 Serial.print("Signal 93 strength (RSSI):"); 94 Serial.print(rssi); 95 Serial.println(" dBm"); 96} 97 98void 99 serviceFound(const char* type, MDNSServiceProtocol /*proto*/, 100 const 101 char* name, IPAddress ip, 102 unsigned short port, 103 const 104 char* txtContent) 105{ 106 if (NULL == name) 107 { 108 Serial.print("Finished 109 discovering services of type "); 110 Serial.println(type); 111 } 112 else 113 114 { 115 foundIP=ip; 116 sprintf(serverAddress, "%d.%d.%d.%d", foundIP[0], 117 foundIP[1], foundIP[2],foundIP[3]); 118 Serial.print("Found: '"); 119 Serial.print(name); 120 121 Serial.print("' at "); 122 Serial.print(ip); 123 Serial.print(", port 124 "); 125 Serial.print(port); 126 Serial.println(" (TCP)"); 127 128 if 129 (txtContent) 130 { 131 Serial.print("\ txt record: "); 132 133 char 134 buf[256]; 135 char len = *txtContent++; 136 int i = 0; 137 138 while 139 (len) 140 { 141 i = 0; 142 143 while (len--) 144 buf[i++] 145 = *txtContent++; 146 147 buf[i] = '\\0'; 148 Serial.print(buf); 149 150 len = *txtContent++; 151 152 if (len) 153 Serial.print(", 154 "); 155 else 156 Serial.println(); 157 } 158 } 159 } 160} 161 162 163 164void 165 setup() { 166 //CARRIER_CASE = false; 167 char inputdata[1] = {0x20}; 168 char 169 datachar[20]; 170 unsigned long Fposition; 171 Serial.begin(9600); 172 delay(1500); 173 174 175 if (!carrier.begin()) 176 { 177 Serial.println("Carrier not connected, check 178 connections"); 179 while (1); 180 } 181 182 carrier.leds.setBrightness(30); 183 184 // carrier.leds.fill(myCustomColor, 0, 5); 185 // carrier.leds.show(); 186 187 188 // Defined in thingProperties.h 189 initProperties(); 190 191 // Connect to 192 Arduino IoT Cloud 193 ArduinoCloud.begin(ArduinoIoTPreferredConnection); 194 195 196 /* 197 The following function allows you to obtain more information 198 related 199 to the state of network and IoT Cloud connection and errors 200 the higher number 201 the more granular information youll get. 202 The default is 0 (only errors). 203 204 Maximum is 4 205 */ 206 setDebugMessageLevel(0); 207 ArduinoCloud.printDebugInfo(); 208 209 210 Serial.print("\ 211Start WiFiDiscoveringServices on "); Serial.println(BOARD_NAME); 212 213 Serial.println(MDNS_GENERIC_VERSION); 214 215 Serial.print("Attempting to connect 216 to SSID: "); Serial.println(SSID); 217 WiFi.begin(SSID, PASS); 218 219 delay(1000); 220 221 222 // attempt to connect to Wifi network: 223 while (status != WL_CONNECTED) 224 225 { 226 // Connect to WPA/WPA2 network. Change this line if using open or 227 WEP network: 228 status = WiFi.status(); 229 delay(1000); 230 } 231 232 printWifiStatus(); 233 234 235 hostname.toLowerCase(); 236 hostname.replace(" ", "-"); 237 hostname.replace("_", 238 "-"); 239 240 Serial.print("Registering mDNS hostname: "); Serial.println(hostname); 241 242 Serial.print("To access, using "); Serial.print(hostname); Serial.println(".local"); 243 244 245 mdns.begin(WiFi.localIP(), hostname.c_str()); 246 mdns.setServiceFoundCallback(serviceFound); 247 248 249 Serial.println("Reading audience.txt"); 250 audience = SD.open("audience.txt"); 251 252 if (audience) { 253 Serial.println("audience.txt:"); 254 255 for (int 256 j = 0; j < 12; j++) { 257 for(int i = 0; inputdata[0] != '\ '; i++){ 258 audience.read(inputdata,1); 259 260 datachar[i] = inputdata[0]; 261 } 262 Fposition = audience.position(); 263 264 audience.seek(Fposition+1); 265 inputdata[0] = 0x20; 266 Serial.println(datachar); 267 268 switch (j) 269 { 270 case 0: 271 cGlobal = atof(datachar); 272 273 tGlobal = cGlobal-3600; 274 Serial.print("cGlobal in Float = 275 "); 276 Serial.println(cGlobal); 277 break; 278 case 1: 279 280 cRai1 = atof(datachar); 281 tRai1 = cRai1/cGlobal*100; 282 Serial.print("cRai1 283 in Float = "); 284 Serial.println(cRai1); 285 break; 286 case 287 2: 288 cRai2 = atof(datachar); 289 tRai2 = cRai2/cGlobal*100; 290 291 Serial.print("cRai2 in Float = "); 292 Serial.println(cRai2); 293 294 break; 295 case 3: 296 cRai3 = atof(datachar); 297 tRai3 298 = cRai3/cGlobal*100; 299 Serial.print("cRai3 in Float = "); 300 Serial.println(cRai3); 301 302 break; 303 case 4: 304 cRete4 = atof(datachar); 305 tRete4 306 = cRete4/cGlobal*100; 307 Serial.print("cRete4 in Float = "); 308 Serial.println(cRete4); 309 310 break; 311 case 5: 312 cCanale5 = atof(datachar); 313 314 tCanale5 = cCanale5/cGlobal*100; 315 Serial.print("cCanale5 316 in Float = "); 317 Serial.println(cCanale5); 318 break; 319 case 320 6: 321 cItalia1 = atof(datachar); 322 tItalia1 = cItalia1/cGlobal*100; 323 324 Serial.print("cItalia1 in Float = "); 325 Serial.println(cItalia1); 326 327 break; 328 case 7: 329 cLa7 = atof(datachar); 330 tLa7 331 = cLa7/cGlobal*100; 332 Serial.print("cLa7 in Float = "); 333 Serial.println(cLa7); 334 335 break; 336 case 8: 337 cTv8 = atof(datachar); 338 tTv8 339 = cTv8/cGlobal*100; 340 Serial.print("cTv8 in Float = "); 341 Serial.println(cTv8); 342 343 break; 344 case 9: 345 cNove = atof(datachar); 346 tNove 347 = cNove/cGlobal*100; 348 Serial.print("cNove in Float = "); 349 Serial.println(cNove); 350 351 break; 352 case 10: 353 cUnknown = atof(datachar); 354 355 tUnknown = cUnknown/cGlobal*100; 356 Serial.print("cUnknown 357 in Float = "); 358 Serial.println(cUnknown); 359 break; 360 case 361 11: 362 startDate = atof(datachar); 363 Serial.print("startDate 364 = "); 365 Serial.println(startDate); 366 break; 367 } 368 369 370 } 371 // close the file: 372 Serial.println("Closing file 373 audience.txt"); 374 audience.close(); 375 } else { 376 // if the file 377 didn't open, print an error: 378 Serial.println("error opening audience.txt"); 379 380 } 381 382 383} 384 385void loop() { 386 ArduinoCloud.update(); 387 char serviceName[256]="_sdtvwcam"; 388 // Standard name of the CAM WiFi 389 upTime = WiFi.getTime(); 390 391 if (serverAddress[0] 392 != 0x20) 393 { 394 if (SD.remove("audience.txt") != true) 395 Serial.println("removal 396 of audience.txt not successful"); 397 audience = SD.open("audience.txt",FILE_WRITE); 398 399 if (audience) { 400 Serial.print("Writing to audience.txt..."); 401 audience.println(cGlobal); 402 403 audience.println(cRai1); 404 audience.println(cRai2); 405 audience.println(cRai3); 406 407 audience.println(cRete4); 408 audience.println(cCanale5); 409 audience.println(cItalia1); 410 411 audience.println(cLa7); 412 audience.println(cTv8); 413 audience.println(cNove); 414 415 audience.println(cUnknown); 416 audience.println(startDate); 417 // 418 close the file: 419 audience.close(); 420 Serial.println("done."); 421 422 } else { 423 // if the file didn't open, print an error: 424 Serial.println("error 425 opening audience.txt"); 426 } 427 } 428 429 if (serverAddress[0] != 0x20) 430 431 { 432 carrier.leds.fill(myCustomColor, 0, 5); 433 carrier.leds.show(); 434 435 tVon = true; 436 rai1 = false; 437 rai2 = false; 438 rai3 439 = false; 440 rete4 = false; 441 canale5 = false; 442 italia1 = false; 443 444 la7 = false; 445 tv8 = false; 446 nove = false; 447 unknownch 448 = false; 449 450 } 451 else 452 { 453 carrier.leds.fill(myCustomColor, 454 0, 1); 455 carrier.leds.show(); 456 tVon = false; 457 rai1 = false; 458 459 rai2 = false; 460 rai3 = false; 461 rete4 = false; 462 canale5 463 = false; 464 italia1 = false; 465 la7 = false; 466 tv8 = false; 467 468 nove = false; 469 unknownch = false; 470 } 471 472 // You can use the 473 "isDiscoveringService()" function to find out whether the 474 // mDNS library 475 is currently discovering service instances. 476 // If so, we skip this input, since 477 we want our previous request to continue. 478 if (!mdns.isDiscoveringService()) 479 480 { 481 Serial.print("Discovering services of type '"); 482 Serial.print(serviceName); 483 484 Serial.println("' via Multi-Cast DNS (Bonjour)..."); 485 486 mdns.startDiscoveringService(serviceName, 487 MDNSServiceTCP, 5000); 488 } 489 490 if (serverAddress[0] != 0x20) 491 readChannel(); 492 493 494 // This actually runs the mDNS module. YOU HAVE TO CALL THIS PERIODICALLY, 495 496 // OR NOTHING WILL WORK! 497 // Preferably, call it once per loop(). 498 mdns.run(); 499} 500 501 502void 503 readChannel() { 504 DynamicJsonDocument doc(1024); 505 //DynamicJsonDocument TV(1024); 506 507 //char returnFromCAM[500]; 508 char channeltuned[13]; 509 unsigned long chTuned; 510 511 char foundOID[4]; 512 Serial.println ("Network IP of CAMWiFi OK!"); 513 Serial.println 514 (cGlobal); 515 delay (5000); 516 517 tRai1 = cRai1/cGlobal*100; 518 Serial.print("tRai1 519 = "); 520 Serial.println(tRai1); 521 tRai2 = cRai2/cGlobal*100; 522 Serial.print("tRai2 523 = "); 524 Serial.println(tRai2); 525 tRai3 = cRai3/cGlobal*100; 526 Serial.print("tRai3 527 = "); 528 Serial.println(tRai3); 529 tRete4 = cRete4/cGlobal*100; 530 Serial.print("tRete4 531 = "); 532 Serial.println(tRete4); 533 tCanale5 = cCanale5/cGlobal*100; 534 Serial.print("tCanale5 535 = "); 536 Serial.println(tCanale5); 537 tItalia1 = cItalia1/cGlobal*100; 538 539 Serial.print("tItalia1 = "); 540 Serial.println(tItalia1); 541 tLa7 = cLa7/cGlobal*100; 542 543 Serial.print("tLa7 = "); 544 Serial.println(tLa7); 545 tTv8 = cTv8/cGlobal*100; 546 547 Serial.print("tTv8 = "); 548 Serial.println(tTv8); 549 tNove = cNove/cGlobal*100; 550 551 Serial.print("tNove = "); 552 Serial.println(tNove); 553 tUnknown = cUnknown/cGlobal*100; 554 555 Serial.print("tUnknown = "); 556 Serial.println(tUnknown); 557 tGlobal = cGlobal-3600; 558 559 upTime = WiFi.getTime(); 560 cGlobal = cGlobal + 5; 561 562 563 564 String 565 contentType = "application/json"; 566 char postHello[250] = "command:deviceHello,\ 567\ clientID:wapp,\ 568 569 sessionID:0090FFA,\ 570 version:2,\ 571 param: {\ 572 }"; 573 HttpClient 574 client = HttpClient(wifia, serverAddress, port); 575 client.post("/deviceHello", 576 contentType, postHello); 577 // read the status code and body of the response 578 579 int statusCode = client.responseStatusCode(); 580 String returnFromCAM = client.responseBody(); 581 582 Serial.print("Status code: "); 583 Serial.println(statusCode); 584 Serial.print("Response: 585 "); 586 Serial.println(returnFromCAM); 587 DeserializationError error = deserializeJson(doc, 588 returnFromCAM); 589 if (error) { 590 Serial.print(F("deserializeJson() failed: 591 ")); 592 Serial.println(error.f_str()); 593 return; 594 } 595 596 597 const char* command = doc["command"]; 598 int Version = doc["version"]; 599 600 601 const char* OID = doc["data"]["TV"]["tuned_on"]["OID"]; 602 const 603 char* TID = doc["data"]["TV"]["tuned_on"]["TID"]; 604 const char* SID = 605 doc["data"]["TV"]["tuned_on"]["SID"]; 606 Serial.println (" "); 607 Serial.print("Command 608 parsed = "); 609 Serial.println(command); 610 Serial.print("Version parsed = 611 "); 612 Serial.println(Version); 613 Serial.print("Tuned On = "); 614 Serial.print(OID); 615 616 Serial.print(" "); 617 Serial.print(TID); 618 Serial.print(" "); 619 Serial.print(SID); 620 621 Serial.println(" "); 622 Serial.println(" "); 623 624 sprintf(channeltuned,"%s%s%s",OID,TID,SID); 625 626 Serial.println(channeltuned); 627 //chTuned=atoi(channeltuned); 628 chTuned 629 = hash(channeltuned); 630 Serial.print("Channel with Hash = "); 631 Serial.println(chTuned); 632 633 634 switch (chTuned) 635 { 636 case RAI1: 637 Serial.println("RAI 1"); 638 639 rai1 = true; 640 cRai1 = cRai1+5; 641 break; 642 case RAI2: 643 644 Serial.println("RAI 2"); 645 // rai1 = false; 646 rai2 = 647 true; 648 cRai2 = cRai2 + 5; 649 break; 650 case RAI3: 651 Serial.println("RAI 652 3"); 653 rai3 = true; 654 cRai3 = cRai3 + 5; 655 break; 656 case 657 RETE4: 658 Serial.println("RETE 4"); 659 rete4 = true; 660 cRete4 661 = cRete4 + 5; 662 break; 663 case CANALE5: 664 Serial.println("CANALE 665 5"); 666 canale5 = true; 667 cCanale5 = cCanale5 + 5; 668 break; 669 670 case ITALIA1: 671 Serial.println("ITALIA 1"); 672 italia1 = true; 673 674 cItalia1 = cItalia1 + 5; 675 break; 676 case LA7: 677 Serial.println("LA7"); 678 679 la7 = true; 680 cLa7 = cLa7 + 5; 681 break; 682 case TV8: 683 684 Serial.println("TV 8"); 685 tv8 = true; 686 cTv8 = cTv8 + 687 5; 688 break; 689 case NOVE: 690 Serial.println("CANALE 9"); 691 692 nove = true; 693 cNove = cNove + 5; 694 break; 695 default: 696 697 unknownch = true; 698 cUnknown = cUnknown + 5; 699 } 700} 701 702unsigned 703 long hash(char *str) 704{ 705 unsigned long hash = 5381; 706 int c; 707 708 709 while (c = *str++) 710 hash = ((hash << 5) + hash) + c; /* hash * 33 711 + c */ 712 713 return hash; 714} 715 716 717 718/* 719 Since BReset is READ_WRITE 720 variable, onBResetChange() is 721 executed every time a new value is received from 722 IoT Cloud. 723*/ 724void onBResetChange() { 725 // Add your code here to act upon 726 BReset change 727 Serial.println(); 728 Serial.println(); 729 Serial.println(); 730 731 Serial.println(); 732 Serial.println(); 733 Serial.print("bReset Changed! = 734 "); 735 Serial.println(bReset); 736 Serial.println(); 737 Serial.println(); 738 739 Serial.println(); 740 Serial.println(); 741 Serial.println(); 742 if (bReset 743 == false) 744 return; 745 Serial.println(); 746 Serial.println(); 747 Serial.println(); 748 749 Serial.println(); 750 Serial.println(); 751 Serial.println("Reset Button Pressed 752 TRUE!"); 753 Serial.println(); 754 Serial.println(); 755 Serial.println(); 756 757 Serial.println(); 758 Serial.println(); 759 760 cGlobal = 0.00; 761 cRai1 762 = 0.00; 763 cRai2 = 0.00; 764 cRai3 = 0.00; 765 cRete4 = 0.00; 766 cCanale5 767 = 0.00; 768 cItalia1 = 0.00; 769 cLa7 = 0.00; 770 cTv8 = 0.00; 771 cNove = 0.00; 772 773 cUnknown = 0.00; 774 startDate = WiFi.getTime(); 775 776} 777
Definition file of the Audience measurement
arduino
1/**************************************************************************************************************************** 2 3 defines.h 4 mDNS library to support mDNS (registering services) and DNS-SD 5 (service discovery). 6 7 Based on and modified from https://github.com/arduino-libraries/ArduinoMDNS 8 9 Built by Khoi Hoang https://github.com/khoih-prog/MDNS_Generic 10 Licensed under 11 MIT license 12 13 Original Author: Georg Kaindl (http://gkaindl.com) 14 15 16 This file is part of Arduino EthernetBonjour. 17 18 EthernetBonjour is free 19 software: you can redistribute it and/or modify it under the terms of the GNU Lesser 20 General Public License 21 as published by the Free Software Foundation, either 22 version 3 of the License, or (at your option) any later version. 23 24 EthernetBonjour 25 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 26 even the implied warranty of 27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 28 See the GNU Lesser General Public License for more details. 29 30 You should 31 have received a copy of the GNU Lesser General Public License along with EthernetBonjour. 32 33 If not, see <http://www.gnu.org/licenses/>. 34 *****************************************************************************************************************************/ 35 36#ifndef 37 defines_h 38#define defines_h 39 40#define SYSTEM_ENDIAN _ENDIAN_BIG_ 41 42#define 43 MDNS_DEBUG_PORT Serial 44#define _MDNS_LOGLEVEL_ 1 45 46#define 47 DEBUG_WIFININA_PORT Serial 48// Debug Level from 0 to 4 49#define _WIFININA_LOGLEVEL_ 50 1 51 52#if defined(ESP32) 53 54 #define BOARD_TYPE ARDUINO_BOARD 55 56 #define ESP_getChipId() ((uint32_t)ESP.getEfuseMac()) 57 58 #define 59 WIFI_NETWORK_ESP true 60 #define WIFI_NETWORK_TYPE WIFI_NETWORK_ESP 61 62 63#elif defined(ESP8266) 64 #error ESP8266 not supported. Please use native 65 ESP8266mDNS library 66#endif 67 68#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) 69 || defined(ARDUINO_SAMD_MKRWIFI1010) \\ 70 || defined(ARDUINO_SAMD_NANO_33_IOT) 71 || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) 72 \\ 73 || defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) 74 || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \\ 75 || 76 defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD21E18A__) || defined(__SAMD51__) 77 || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) \\ 78 || defined(__SAMD51G19A__) 79 || defined(__SAMD51P19A__) || defined(__SAMD21G18A__) ) 80 #if defined(WIFININA_USE_SAMD) 81 82 #undef WIFININA_USE_SAMD 83 #endif 84 #define WIFININA_USE_SAMD true 85 86 87 #if defined(ARDUINO_SAMD_ZERO) 88 #define BOARD_TYPE "SAMD 89 Zero" 90 #elif defined(ARDUINO_SAMD_MKR1000) 91 #define BOARD_TYPE "SAMD 92 MKR1000" 93 #elif defined(ARDUINO_SAMD_MKRWIFI1010) 94 #define BOARD_TYPE 95 "SAMD MKRWIFI1010" 96 #define WIFI_NETWORK_WIFI101 true 97 98 #define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFI101 99 #elif defined(ARDUINO_SAMD_NANO_33_IOT) 100 101 #define BOARD_TYPE "SAMD NANO_33_IOT" 102 #define WIFI_NETWORK_WIFININA 103 true 104 #define WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA 105 106 #elif defined(ARDUINO_SAMD_MKRFox1200) 107 #define BOARD_TYPE "SAMD MKRFox1200" 108 109 #elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) ) 110 111 #define BOARD_TYPE "SAMD MKRWAN13X0" 112 #elif defined(ARDUINO_SAMD_MKRGSM1400) 113 114 #define BOARD_TYPE "SAMD MKRGSM1400" 115 #elif defined(ARDUINO_SAMD_MKRNB1500) 116 117 #define BOARD_TYPE "SAMD MKRNB1500" 118 #elif defined(ARDUINO_SAMD_MKRVIDOR4000) 119 120 #define BOARD_TYPE "SAMD MKRVIDOR4000" 121 #elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) 122 123 #define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS" 124 125 #elif defined(ADAFRUIT_FEATHER_M0_EXPRESS) 126 #define BOARD_TYPE "SAMD21 127 ADAFRUIT_FEATHER_M0_EXPRESS" 128 #elif defined(ADAFRUIT_METRO_M0_EXPRESS) 129 130 #define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS" 131 #elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0) 132 133 #define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0" 134 #elif 135 defined(ADAFRUIT_GEMMA_M0) 136 #define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0" 137 138 #elif defined(ADAFRUIT_TRINKET_M0) 139 #define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0" 140 141 #elif defined(ADAFRUIT_ITSYBITSY_M0) 142 #define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0" 143 144 #elif defined(ARDUINO_SAMD_HALLOWING_M0) 145 #define BOARD_TYPE "SAMD21 146 ARDUINO_SAMD_HALLOWING_M0" 147 #elif defined(ADAFRUIT_METRO_M4_EXPRESS) 148 #define 149 BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS" 150 #elif defined(ADAFRUIT_GRAND_CENTRAL_M4) 151 152 #define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4" 153 #elif defined(ADAFRUIT_FEATHER_M4_EXPRESS) 154 155 #define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS" 156 #elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS) 157 158 #define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS" 159 #elif 160 defined(ADAFRUIT_TRELLIS_M4_EXPRESS) 161 #define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS" 162 163 #elif defined(ADAFRUIT_PYPORTAL) 164 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL" 165 166 #elif defined(ADAFRUIT_PYPORTAL_M4_TITANO) 167 #define BOARD_TYPE "SAMD51 168 ADAFRUIT_PYPORTAL_M4_TITANO" 169 #elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS) 170 171 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS" 172 #elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) 173 174 #define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE" 175 #elif 176 defined(ADAFRUIT_PYGAMER_M4_EXPRESS) 177 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS" 178 179 #elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS) 180 #define BOARD_TYPE "SAMD51 181 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS" 182 #elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4) 183 184 #define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4" 185 #elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS) 186 187 #define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS" 188 #elif 189 defined(ADAFRUIT_HALLOWING_M4_EXPRESS) 190 #define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS" 191 192 #elif defined(SEEED_WIO_TERMINAL) 193 #define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL" 194 195 #elif defined(SEEED_FEMTO_M0) 196 #define BOARD_TYPE "SAMD SEEED_FEMTO_M0" 197 198 #elif defined(SEEED_XIAO_M0) 199 #define BOARD_TYPE "SAMD SEEED_XIAO_M0" 200 201 #elif defined(Wio_Lite_MG126) 202 #define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126" 203 204 #elif defined(WIO_GPS_BOARD) 205 #define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD" 206 207 #elif defined(SEEEDUINO_ZERO) 208 #define BOARD_TYPE "SAMD SEEEDUINO_ZERO" 209 210 #elif defined(SEEEDUINO_LORAWAN) 211 #define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN" 212 213 #elif defined(SEEED_GROVE_UI_WIRELESS) 214 #define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS" 215 216 #elif defined(__SAMD21E18A__) 217 #define BOARD_TYPE "SAMD21E18A" 218 219 #elif defined(__SAMD21G18A__) 220 #define BOARD_TYPE "SAMD21G18A" 221 222 #elif defined(__SAMD51G19A__) 223 #define BOARD_TYPE "SAMD51G19A" 224 225 #elif defined(__SAMD51J19A__) 226 #define BOARD_TYPE "SAMD51J19A" 227 228 #elif defined(__SAMD51P19A__) 229 #define BOARD_TYPE "__SAMD51P19A__" 230 231 #elif defined(__SAMD51J20A__) 232 #define BOARD_TYPE "SAMD51J20A" 233 234 #elif defined(__SAM3X8E__) 235 #define BOARD_TYPE "SAM3X8E" 236 #elif 237 defined(__CPU_ARC__) 238 #define BOARD_TYPE "CPU_ARC" 239 #elif defined(__SAMD51__) 240 241 #define BOARD_TYPE "SAMD51" 242 #else 243 #define BOARD_TYPE "SAMD 244 Unknown" 245 #endif 246 247#endif 248 249#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) 250 || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \\ 251 defined(NRF52840_FEATHER_SENSE) 252 || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) 253 || \\ 254 defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) 255 || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) ) 256 #if defined(WIFININA_USE_NRF52) 257 258 #undef WIFININA_USE_NRF52 259 #endif 260 #define WIFININA_USE_NRF52 true 261 262 263 #if defined(NRF52840_FEATHER) 264 #define BOARD_TYPE "NRF52840_FEATHER_EXPRESS" 265 266 #elif defined(NRF52832_FEATHER) 267 #define BOARD_TYPE "NRF52832_FEATHER" 268 269 #elif defined(NRF52840_FEATHER_SENSE) 270 #define BOARD_TYPE "NRF52840_FEATHER_SENSE" 271 272 #elif defined(NRF52840_ITSYBITSY) 273 #define BOARD_TYPE "NRF52840_ITSYBITSY_EXPRESS" 274 275 #elif defined(NRF52840_CIRCUITPLAY) 276 #define BOARD_TYPE "NRF52840_CIRCUIT_PLAYGROUND" 277 278 #elif defined(NRF52840_CLUE) 279 #define BOARD_TYPE "NRF52840_CLUE" 280 281 #elif defined(NRF52840_METRO) 282 #define BOARD_TYPE "NRF52840_METRO_EXPRESS" 283 284 #elif defined(NRF52840_PCA10056) 285 #define BOARD_TYPE "NORDIC_NRF52840DK" 286 287 #elif defined(NINA_B302_ublox) 288 #define BOARD_TYPE "NINA_B302_ublox" 289 290 #elif defined(NINA_B112_ublox) 291 #define BOARD_TYPE "NINA_B112_ublox" 292 293 #elif defined(PARTICLE_XENON) 294 #define BOARD_TYPE "PARTICLE_XENON" 295 296 #elif defined(MDBT50Q_RX) 297 #define BOARD_TYPE "RAYTAC_MDBT50Q_RX" 298 299 #elif defined(ARDUINO_NRF52_ADAFRUIT) 300 #define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT" 301 302 #else 303 #define BOARD_TYPE "nRF52 Unknown" 304 #endif 305 306#endif 307 308#if 309 ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) ) 310 #if defined(WIFININA_USE_SAMDUE) 311 312 #undef WIFININA_USE_SAMDUE 313 #endif 314 #define WIFININA_USE_SAMDUE true 315 316 317 // For SAM DUE 318 #if defined(ARDUINO_SAM_DUE) 319 #define BOARD_TYPE "SAM 320 DUE" 321 #elif defined(__SAM3X8E__) 322 #define BOARD_TYPE "SAM SAM3X8E" 323 324 #else 325 #define BOARD_TYPE "SAM Unknown" 326 #endif 327 328#endif 329 330#if 331 ( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3) ||defined(STM32F4) 332 || defined(STM32F7) || \\ 333 defined(STM32L0) || defined(STM32L1) || defined(STM32L4) 334 || defined(STM32H7) ||defined(STM32G0) || defined(STM32G4) || \\ 335 defined(STM32WB) 336 || defined(STM32MP1) ) && !( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) 337 ) 338 #if defined(WIFININA_USE_STM32) 339 #undef WIFININA_USE_STM32 340 #endif 341 342 #define WIFININA_USE_STM32 true 343 344 #if defined(STM32F0) 345 #warning 346 STM32F0 board selected 347 #define BOARD_TYPE "STM32F0" 348 #elif defined(STM32F1) 349 350 #warning STM32F1 board selected 351 #define BOARD_TYPE "STM32F1" 352 #elif 353 defined(STM32F2) 354 #warning STM32F2 board selected 355 #define BOARD_TYPE 356 "STM32F2" 357 #elif defined(STM32F3) 358 #warning STM32F3 board selected 359 360 #define BOARD_TYPE "STM32F3" 361 #elif defined(STM32F4) 362 #warning 363 STM32F4 board selected 364 #define BOARD_TYPE "STM32F4" 365 #elif defined(STM32F7) 366 367 #warning STM32F7 board selected 368 #define BOARD_TYPE "STM32F7" 369 #elif 370 defined(STM32L0) 371 #warning STM32L0 board selected 372 #define BOARD_TYPE 373 "STM32L0" 374 #elif defined(STM32L1) 375 #warning STM32L1 board selected 376 377 #define BOARD_TYPE "STM32L1" 378 #elif defined(STM32L4) 379 #warning 380 STM32L4 board selected 381 #define BOARD_TYPE "STM32L4" 382 #elif defined(STM32H7) 383 384 #warning STM32H7 board selected 385 #define BOARD_TYPE "STM32H7" 386 #elif 387 defined(STM32G0) 388 #warning STM32G0 board selected 389 #define BOARD_TYPE 390 "STM32G0" 391 #elif defined(STM32G4) 392 #warning STM32G4 board selected 393 394 #define BOARD_TYPE "STM32G4" 395 #elif defined(STM32WB) 396 #warning 397 STM32WB board selected 398 #define BOARD_TYPE "STM32WB" 399 #elif defined(STM32MP1) 400 401 #warning STM32MP1 board selected 402 #define BOARD_TYPE "STM32MP1" 403 404 #else 405 #warning STM32 unknown board selected 406 #define BOARD_TYPE "STM32 407 Unknown" 408 #endif 409 410#endif 411 412#ifdef CORE_TEENSY 413 414 #if defined(WIFININA_USE_TEENSY) 415 416 #undef WIFININA_USE_TEENSY 417 #endif 418 #define WIFININA_USE_TEENSY true 419 420 421 #if defined(__IMXRT1062__) 422 // For Teensy 4.1/4.0 423 #define BOARD_TYPE 424 "TEENSY 4.1/4.0" 425 #elif defined(__MK66FX1M0__) 426 #define BOARD_TYPE 427 "Teensy 3.6" 428 #elif defined(__MK64FX512__) 429 #define BOARD_TYPE "Teensy 430 3.5" 431 #elif defined(__MKL26Z64__) 432 #define BOARD_TYPE "Teensy LC" 433 434 #elif defined(__MK20DX256__) 435 #define BOARD_TYPE "Teensy 3.2" // and Teensy 436 3.1 (obsolete) 437 #elif defined(__MK20DX128__) 438 #define BOARD_TYPE "Teensy 439 3.0" 440 #elif defined(__AVR_AT90USB1286__) 441 #error Teensy 2.0++ not supported 442 yet 443 #elif defined(__AVR_ATmega32U4__) 444 #error Teensy 2.0 not supported 445 yet 446 #else 447 // For Other Boards 448 #define BOARD_TYPE "Unknown 449 Teensy Board" 450 #endif 451 452#endif 453 454#if ( defined(ARDUINO_ARCH_RP2040) 455 || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) 456 || defined(ARDUINO_GENERIC_RP2040) ) 457 #if defined(WIFININA_USE_RP2040) 458 #undef 459 WIFININA_USE_RP2040 460 #endif 461 #define WIFININA_USE_RP2040 true 462 463 464 // Default pin 5 (in Mbed) or 17 to SS/CS 465 #if defined(ARDUINO_ARCH_MBED) 466 467 // For RPI Pico using Arduino Mbed RP2040 core 468 // SCK: GPIO2, MOSI: 469 GPIO3, MISO: GPIO4, SS/CS: GPIO5 470 471 #define USE_THIS_SS_PIN 5 472 473 474 #if defined(BOARD_NAME) 475 #undef BOARD_NAME 476 #endif 477 478 #if 479 defined(ARDUINO_NANO_RP2040_CONNECT) 480 #define BOARD_TYPE "MBED 481 NANO_RP2040_CONNECT" 482 #define WIFI_NETWORK_WIFININA true 483 #define 484 WIFI_NETWORK_TYPE WIFI_NETWORK_WIFININA 485 #elif defined(ARDUINO_RASPBERRY_PI_PICO) 486 487 #define BOARD_TYPE "MBED RASPBERRY_PI_PICO" 488 #elif 489 defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) 490 #define BOARD_TYPE "MBED 491 ADAFRUIT_FEATHER_RP2040" 492 #elif defined(ARDUINO_GENERIC_RP2040) 493 #define 494 BOARD_TYPE "MBED GENERIC_RP2040" 495 #else 496 #define 497 BOARD_TYPE "MBED Unknown RP2040" 498 #endif 499 500 #else 501 502 // For RPI Pico using E. Philhower RP2040 core 503 // SCK: GPIO18, MOSI: 504 GPIO19, MISO: GPIO16, SS/CS: GPIO17 505 #define USE_THIS_SS_PIN 17 506 507 508 #endif 509 510 #define SS_PIN_DEFAULT USE_THIS_SS_PIN 511 512 // 513 For RPI Pico 514 #warning Use RPI-Pico RP2040 architecture 515#endif 516 517#if 518 ( defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) ) 519 520 #if 521 defined(BOARD_NAME) 522 #undef BOARD_NAME 523 #endif 524 525 #if defined(CORE_CM7) 526 527 #warning Using Portenta H7 M7 core 528 #define BOARD_TYPE "PORTENTA_H7_M7" 529 530 #else 531 #warning Using Portenta H7 M4 core 532 #define BOARD_TYPE "PORTENTA_H7_M4" 533 534 #endif 535 536 #define WIFI_NETWORK_PORTENTA_H7 true 537 #define WIFI_NETWORK_TYPE 538 WIFI_NETWORK_PORTENTA_H7 539 540#elif (ESP32) 541 542 #define USE_WIFI_NINA 543 false 544 545 // To use the default WiFi library here 546 #define 547 USE_WIFI_CUSTOM false 548 549#endif 550 551#ifndef BOARD_NAME 552 #define 553 BOARD_NAME BOARD_TYPE 554#endif 555 556#endif //defines_h 557
Downloadable files
No schematics required
No schematics required
No schematics required
No schematics required
Comments
Only logged in users can leave comments
cstram
0 Followers
•0 Projects
Table of contents
Intro
0
0