Termometro con Arduino IOT cloud

Ciao a tutti, sono nuovo nel mondo dell'IOT e come primo progetto volevo collegare un sensore di temperatura tmp36 ad Arduino Nano 33 e visualizzare i valori della temperatura su una dashboard. Ho collegato la scheda, il WiFi, creato la variabile float per il valore della temperatura e l'ho associata alla scheda. Ora però come faccio a programmarlo? Non ne ho proprio idea.
Grazie in anticipo

Mmm ... non uso Arduino Cloud, ma ... credo (come detto, mai provato) tu debba sviluppare nel sua ambiente e lui ti genera il codice con le variabili che assegna lui ... :roll_eyes:

Guglielmo

Questo è il codice (in gran parte generato dal cloud):

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/f7d094c6-596a-48fc-828e-963975d0570c 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float temperature;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
int termoPin = A7;
void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  pinMode(termoPin, INPUT);
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  float temperature = analogRead(termoPin);
  
  
}



/*
  Since Temperature is READ_WRITE variable, onTemperatureChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTemperatureChange()  {
  // Add your code here to act upon Temperature change
}

Metti anche il contenuto di questo file ... che dovrebbe contenere gli oggetti che hai definito.

Guglielmo

Eccolo:


#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char SSID[]     =     // Network SSID (name)
const char PASS[]     =    // Network password (use for WPA, or use as key for WEP)

void onTemperatureChange();

float temperature;

void initProperties(){

  ArduinoCloud.addProperty(temperature, READWRITE, ON_CHANGE, onTemperatureChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

E questo è il messaggio di errore:

In file included from /run/arduino/sketches/Untitled_dec26a/Untitled_dec26a.ino:18:0:
/run/arduino/sketches/Untitled_dec26a/thingProperties.h:7:1: error: expected ',' or ';' before 'const'
 const char PASS[]     =  SECRET_PASS // Network password (use for WPA, or use as key for WEP)
 ^~~~~
In file included from /run/arduino/sketches/Untitled_dec26a/thingProperties.h:3:0,
                 from /run/arduino/sketches/Untitled_dec26a/Untitled_dec26a.ino:18:
/run/arduino/sketches/Untitled_dec26a/thingProperties.h: In function 'void initProperties()':
/run/arduino/sketches/Untitled_dec26a/thingProperties.h:15:63: error: 'onTemperatureChange' was not declared in this scope
   ArduinoCloud.addProperty(temperature, READWRITE, ON_CHANGE, onTemperatureChange);
                                                               ^
/var/run/arduino/directories-user/libraries/ArduinoIoTCloud/src/ArduinoIoTCloud.h:106:53: note: in definition of macro 'addProperty'
 #define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
                                                     ^~~~~~~~~~~
/run/arduino/sketches/Untitled_dec26a/thingProperties.h:15:63: note: suggested alternative: 'temperature'
   ArduinoCloud.addProperty(temperature, READWRITE, ON_CHANGE, onTemperatureChange);
                                                               ^
/var/run/arduino/directories-user/libraries/ArduinoIoTCloud/src/ArduinoIoTCloud.h:106:53: note: in definition of macro 'addProperty'
 #define addProperty( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
                                                     ^~~~~~~~~~~
In file included from /run/arduino/sketches/Untitled_dec26a/Untitled_dec26a.ino:18:0:
/run/arduino/sketches/Untitled_dec26a/thingProperties.h: At global scope:
/run/arduino/sketches/Untitled_dec26a/thingProperties.h:19:59: error: 'PASS' was not declared in this scope
 WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
                                                           ^~~~
/run/arduino/sketches/Untitled_dec26a/thingProperties.h:19:59: note: suggested alternative: 'DAYS'
 WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
                                                           ^~~~
                                                           DAYS
Multiple libraries were found for "ECCX08.h"
  Used: /run/arduino/directories-data/internal/ArduinoECCX08_1.3.8_fb8ab5b39cf9f121
  Not used: /run/arduino/directories-data/internal/RAK5814-ATECC608A_1.0.0_3080811c7019c906
Multiple libraries were found for "Wire.h"
  Used: /run/arduino/directories-data/packages/arduino/hardware/samd/1.8.13/libraries/Wire
  Not used: /run/arduino/directories-data/internal/FlexWire_1.2.1_1fc5f1d1a14af0e7
Multiple libraries were found for "SPI.h"
  Used: /run/arduino/directories-data/packages/arduino/hardware/samd/1.8.13/libraries/SPI
  Not used: /run/arduino/directories-data/internal/EventEthernet_1.0.0_bd9dd894ef7641f8
Multiple libraries were found for "WiFiNINA.h"
  Used: /run/arduino/directories-data/internal/WiFiNINA_1.8.14_50fd037d6f2f4b4b
  Not used: /run/arduino/directories-data/internal/VEGA_WiFiNINA_1.0.1_ab2db6059607e9f4
  Not used: /run/arduino/directories-data/internal/BetterWiFiNINA_1.3.0_0ccca45bdf408f34

Hai letto bene il messaggio di errore? Quello se ne porta dietro altri a catena ...

Controlla dove dichiari il SSID di aver messo il ';' ...

Guglielmo

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.