Problème d'envoi Sigfox et code "delay()"

Bonjour à tous,

Mon projet vois la fin bientôt mais je rencontres des problèmes sur deux points :

  • Mes données s'envoi une première fois chez Sigfox, ça boucle, ça lis bien les données, et là l'envoi à sigfox reste planté à "Status : " et la LED clignote à l'infini.

ex :

16:18:58.171 -> Temperature :  (B442884 x100 deg C)
16:18:58.204 -> Humidity :52
16:18:58.204 -> sensorValue 5
16:18:58.204 -> Temperature : 290.72
16:18:58.204 -> Status: 
16:19:05.228 -> 0
16:19:20.282 -> Temperature :  (B412881 x100 deg C)
16:19:20.316 -> Humidity :52
16:19:20.316 -> sensorValue 16
16:19:20.316 -> Temperature : 291.03
16:19:20.316 -> Status:

Les données ne sont pas envoyés a Sigfox.
De ce fait, je ne peux plus utiliser ma fonction bluetooth/infrared pendant ce temps là.
(D'ailleurs est ce possible de rendre le code plus propre etc ?)

  • Je n'arrives pas à récupérer mes données de vibration :

Quand je lis msg.vibra ça me retourne des entiers entre 0,1,2,3 ... alors que de base c'est du float et quand je lis piezoV j'ai bien des chiffres à virgules etc... et sur sigfox j'ai vibra : 0.

Mon custom grammar :

temp::int:16:little-endian humi::uint:8:little-endian  sound::uint:8:little-endian temp2::uint:8:little-endian vibra::int:16:little-endian

Ma carte : MKR FOX 1200
Réseau : Sigfox
Appli : MIT App Inventor

Matériels : Grove Temperature&Humidity | Grove Serial bluetooth | Grove Temperature Sensor | Grove Sound Sensor | Grove 80cm Infrared Proximity Sensor | KY-019 Module Relais 5V | Piezo Vibration Sensor - Large with Mass

Mon code :

// ====================================/ LIBRARY UTILITIES \===================================

#include <SigFox.h> // library Sigfox
#include <TH02_dev.h> // library Grove Temperature & humidity
#include "Arduino.h"
#include "Wire.h" 
#include <math.h> //library Grove Temperature Sensor
#include <ZSharpIR.h> //library Grove Infrared Proximity Sensor


// ==========================/ GROVE INFRARED PROXIMITY SENSOR - PIN A3 \=================== 

#define ir A3 // ir: the pin where your sensor is attached
#define model 1080 // model: an int that determines your sensor: 1080 for GP2Y0A21Y
ZSharpIR SharpIR(ir, model);

// ===============================/ GROVE SOUND SENSOR - PIN A0 \==========================

#define SOUND_SENSOR A0 // define pin capteur Sound A0
#define THRESHOLD_VALUE 100 // Sound seuil critique

// =========================/ GROVE TEMPERATURE & HUMIDITY - PIN I2C \=====================

#define CRITIQUE_VALUE 10000 // Temperature seuil critique

// ============================/ GROVE TEMPERATURE SENSOR - PIN A1 \=======================

const int B = 4275;           // B value of the thermistor
const int R0 = 100000;       // R0 = 100k
#define pinTempSensor A1    // Grove - Temperature Sensor connect to A1
#define MAX_VALUE 80
#define MAX_VALUE_CRITIQUE 100
// ===========================/ GROVE SPDT Relay(30A) - PIN D4 \========================

int relay = 4; // define pin capteur Relay D4

// ========================/ GROVE SERIAL BLUETOOTH - PIN SERIAL \=====================

char state; // return '0' = OFF and '1' = ON by APK bluetooth

// =============================/ PIEZO VIBRATOR - PIN A2 \==========================

const int PIEZO_PIN = A2; // define pin capteur Vibrator A2

// ===================================/ TYPE STRUCT ENVOI MSG \=======================

typedef struct __attribute__ ((packed)) {
  int16_t temper; // 2 octet - Temperature pin I2C
  uint8_t humidity; // 1 octet - Humidity pin I2C
  uint8_t sensorValue; // 1 octet - Sound Sensor pin A0
  uint8_t temperature; // 1 octet - Temperature pin A1
  int16_t vibra; // 2 octet - Vibration pin A2
} sigfox_message_t;


// ==================================================================================

// stub for message which will be sent
sigfox_message_t msg;


// ====================================/ UTILITIES \=================================

void reboot() {
  NVIC_SystemReset();
  while (1);
}


// ==================================================================================

void setup() {
  Serial.begin(9600); // Start Serial with 115200
  Serial1.begin(9600); // Serial Port TX + RX
  TH02.begin(); // Start library Grove Temperature & humidity
  pinMode(relay, OUTPUT); // Initialize relay
  
  while (!Serial);
  if (!SigFox.begin()) {
    Serial.println("SigFox error, rebooting");
    reboot();
  }

  delay(100); // Wait at least 30ms after first configuration
  
  // Enable debug prints and LED indication
  SigFox.debug();

}
  
void loop() {
    
// ===================/ INFRARED PROXIMITY - PIN A3 WITH RELAY - PIN D4 AND BLUETOOTH - PIN SERIAL \===================
  
  unsigned long pepe1 = millis();  // takes the time before the loop on the library begins
  int dis = SharpIR.distance();  // this returns the distance to the object you're measuring
  
  if (Serial1.available()> 0) // if Serial1 is available, return Serial1.read in state
  {
    state = Serial1.read();
  }
  
  if ((dis < 300) && (state == '1')) // if distance of Infrared is < 30cm and state return '1'
  { 
      digitalWrite(relay, HIGH); // RELAY ON
      Serial1.print("RELAY : OFF"); // Send back, to the phone, the String "RELAY : OFF"
      state = 0;
    } 

  if (dis > 300) // if distance of Infrared is > 30cm
  {
    digitalWrite(relay, LOW); // RELAY OFF
  }
  
  if(state == '0') // if state return '0'
    {
    digitalWrite(relay, LOW); // RELAY OFF
    Serial1.print("RELAY : ON"); // Send back, to the phone, the String "RELAY : ON"
    state = 0;
    }
// =====================================/ GROVE TEMPERATURE & HUMIDITY - PIN I2C \=====================
  
  // Read and convert the module temperature of Grove Temperature & humidity
  msg.temper = (int32_t) (TH02.ReadTemperature() * 100.0);

  // Condition temp mini / max / critical
  if(msg.temper > CRITIQUE_VALUE)
    {
      Serial.print("Temperature sueil CRITIQUE : "); //  higher 100°
      Serial.print(" (");
      Serial.print(msg.temper, HEX); // display what we will send in Hexadecimal
      
      Serial.print(msg.temper); // display what we will send in Decimal
      Serial.println(" x100 deg C)");
      //delay(3600000); // 60min waiting
    }
      else
    {
      Serial.print("Temperature : "); //  temp
      Serial.print(" (");
      Serial.print(msg.temper, HEX); // display what we will send in Hexadecimal
      
      Serial.print(msg.temper); // display what we will send in Decimal
      Serial.println(" x100 deg C)");
      //delay(15000); // 15min waiting
    }
    
    // Read and convert the module humidity
    float t = TH02.ReadHumidity();
    msg.humidity = (float) (t);
    Serial.print("Humidity :"); 
    Serial.println(msg.humidity); //  humidity
    
  // ====================================/ GROVE SOUND SENSOR - PIN A0 \=====================
  
  // Read Sound Sensor
  msg.sensorValue = analogRead(SOUND_SENSOR);

  // Condition sueil
  if(msg.sensorValue > THRESHOLD_VALUE) 
     {
      Serial.print("Sensor Sueil CRITIQUE :"); // seuil > 100
      Serial.println(msg.sensorValue);
      //delay(3600000); // 60min d'attente
     }
      else
    {
      Serial.print("sensorValue "); //  seuil 
      Serial.println(msg.sensorValue); 
      //delay(15000); //15min waiting
     }
     
  // =================================/ GROVE TEMPERATURE SENSOR - PIN A1 \==========================

  // Read and convert the module Temperature Sensor
  
  int a = analogRead(pinTempSensor);
  float R = 1023.0/a-1.0;
  R = R0*R;

  msg.temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

  // Condition temp critical
  if(msg.temperature > MAX_VALUE && msg.temperature < MAX_VALUE_CRITIQUE)
    {
      Serial.print("Temperature seuil CRITIQUE : "); //  temp between 80° and 100°
      Serial.print(msg.temperature); // 
      //delay(3600000); // 60min waiting
    } 
    else
    {
      Serial.print("Temperature : "); //  temp
      Serial.print(msg.temperature);
      //delay(15000); // 15min waiting
    }
    
 
// ======================================/ PIEZO VIBRATOR - PIN D2 \=======================================

  // Read Piezo ADC value in, and convert it to a voltage
  int piezoADC = analogRead(PIEZO_PIN);
  float piezoV = piezoADC * 0.103125; // (N*T/2^x)
  Serial.println(piezoV);
  
  msg.vibra = piezoV;
  
  if(msg.vibra > 1.30) 
  {
    Serial.print("Seuil critique: ");
    Serial.println(msg.vibra);
    delay(15000);
  }       

// =========================================================================================================
  
  // Clears all pending interrupts
  SigFox.status();
  delay(1);

  // Send the data
  SigFox.beginPacket();
  SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));

  // Status 
  Serial.println("Status: ");
  Serial.println(SigFox.endPacket());

  SigFox.end();
  delay(15000);
}

Mes données sur le back Sigfox :

2 msg à 14 octets sachant que le deuxième msg ne s'envoie pas.
Est ce du que l'intervalle est trop court ? Et que si je mets 15min ça ira ?

Comme vous pouvez le voir, je voulais mettre 15min de delay(15s pour test) entre chaque relevé de mes capteurs mais apparemment faut y mettre après l'envoi de Sigfox car sinon j'attends 15s entre chaque relevé donc j'ai une température à 8h mais l'humidité à 8h15 etc...

De ce fait, je voulais que ma carte envoi des données si jamais un seuil était dépassé mais dans un délai de 1 fois par heure par capteur. Si je mets mon délai après chaque capteurs j'aurais le problème qu'il va attendre 1h avant de lire les autres capteurs.

Tout mes seuils sont pour l'instant indicatif.

Dois-je créer une nouvelle structure pour l'envoi de ces données critique ?

Merci d'avance pour l'aide !

J'ai modifier mon code de la sorte :

// ====================================/ LIBRARY UTILITIES \===================================

#include <SigFox.h> // library Sigfox
#include <TH02_dev.h> // library Grove Temperature & humidity
#include "Arduino.h"
#include "Wire.h" 
#include <math.h> //library Grove Temperature Sensor
#include <ZSharpIR.h> //library Grove Infrared Proximity Sensor


// ==========================/ GROVE INFRARED PROXIMITY SENSOR - PIN A3 \=================== 

#define ir A3 // ir: the pin where your sensor is attached
#define model 1080 // model: an int that determines your sensor: 1080 for GP2Y0A21Y
ZSharpIR SharpIR(ir, model);

// ===============================/ GROVE SOUND SENSOR - PIN A0 \==========================

#define SOUND_SENSOR A0 // define pin capteur Sound A0
#define THRESHOLD_VALUE 100 // Sound sueil critique

// =========================/ GROVE TEMPERATURE & HUMIDITY - PIN I2C \=====================

#define CRITIQUE_VALUE 10000 // Temperature sueil critique

// ============================/ GROVE TEMPERATURE SENSOR - PIN A1 \=======================

const int B = 4275;           // B value of the thermistor
const int R0 = 100000;       // R0 = 100k
#define pinTempSensor A1    // Grove - Temperature Sensor connect to A1
#define MAX_VALUE 80
#define MAX_VALUE_CRITIQUE 100
// ===========================/ GROVE SPDT Relay(30A) - PIN D4 \========================

int relay = 4; // define pin capteur Relay D4

// ========================/ GROVE SERIAL BLUETOOTH - PIN SERIAL \=====================

char state; // return '0' = OFF and '1' = ON by APK bluetooth

// =============================/ PIEZO VIBRATOR - PIN A2 \==========================

const int PIEZO_PIN = A2; // define pin capteur Vibrator A2

// ===================================/ TYPE STRUCT ENVOI MSG \=======================

typedef struct __attribute__ ((packed)) {
  int16_t temper; // 2 octet - Temperature pin I2C
  uint8_t humidity; // 1 octet - Humidity pin I2C
  uint8_t sensorValue; // 1 octet - Sound Sensor pin A0
  uint8_t temperature; // 1 octet - Temperature pin A1
  float vibra; // 4 octet - Vibration pin A2
} sigfox_message_t;


// ==================================================================================

// stub for message which will be sent
sigfox_message_t msg;


// ====================================/ UTILITIES \=================================

void reboot() {
  NVIC_SystemReset();
  while (1);
}


// ==================================================================================

void setup() {
  Serial.begin(9600); // Start Serial with 115200
  Serial1.begin(9600); // Serial Port TX + RX
  TH02.begin(); // Start library Grove Temperature & humidity
  pinMode(relay, OUTPUT); // Initialize relay
  
  if (!SigFox.begin()) {
    Serial.println("SigFox error, rebooting");
    reboot();
  }

  delay(100); // Wait at least 30ms after first configuration
  
  // Enable debug prints and LED indication
  SigFox.debug();

}


void loop() {
    
// ===================/ INFRARED PROXIMITY - PIN A3 WITH RELAY - PIN D4 AND BLUETOOTH - PIN SERIAL \===================
  
  bluetooth();
  
// =====================================/ GROVE TEMPERATURE & HUMIDITY - PIN I2C \=====================
  
  temper();
    
// ====================================/ GROVE SOUND SENSOR - PIN A0 \=====================
  
  sound();
     
// =================================/ GROVE TEMPERATURE SENSOR - PIN A1 \==========================

  temper2();
 
// ======================================/ PIEZO VIBRATOR - PIN D2 \=======================================

  vibrator();

// =========================================================================================================
  // Clears all pending interrupts
  SigFox.status();
  delay(1);

  // Send the data
  SigFox.beginPacket();
  SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));

  // Status 
  Serial.println("Status: ");
  Serial.println(SigFox.endPacket());

  delay(300000);
 
}

void bluetooth(){
  
  unsigned long pepe1 = millis();  // takes the time before the loop on the library begins
  int dis = SharpIR.distance();  // this returns the distance to the object you're measuring
  Serial.println(dis);
  
  if (Serial1.available()> 0) // if Serial1 is available, return Serial1.read in state
  {
    state = Serial1.read();
  }
  
  if ((dis < 400) && (state == '1')) // if distance of Infrared is < 30cm and state return '1'
  { 
      digitalWrite(relay, HIGH); // RELAY ON
      Serial1.print("RELAY : OFF"); // Send back, to the phone, the String "RELAY : OFF"
      state = 0;
    } 

  if (dis > 400) // if distance of Infrared is > 30cm
  {
    digitalWrite(relay, LOW); // RELAY OFF
  }
  
  if(state == '0') // if state return '0'
    {
    digitalWrite(relay, LOW); // RELAY OFF
    Serial1.print("RELAY : ON"); // Send back, to the phone, the String "RELAY : ON"
    state = 0;
    }
}

void vibrator(){

  // Read Piezo ADC value in, and convert it to a voltage
  int piezoADC = analogRead(PIEZO_PIN);
  float piezoV = piezoADC * 0.103125; // (N*T/2^x)
  Serial.println(piezoV);
  
  msg.vibra = piezoV;
  
  if(msg.vibra > 1.30) 
  {
    Serial.print("Sueil critique: ");
    Serial.println(msg.vibra);
    delay(15000);
  }    
}
void temper2(){
// Read and convert the module Temperature Sensor
  
  int a = analogRead(pinTempSensor);
  float R = 1023.0/a-1.0;
  R = R0*R;

  msg.temperature = 1.0/(log(R/R0)/B+1/298.15)-273.15; // convert to temperature via datasheet

  // Condition temp critical
  if(msg.temperature > MAX_VALUE && msg.temperature < MAX_VALUE_CRITIQUE)
    {
      Serial.print("Temperature sueil CRITIQUE : "); //  temp between 80° and 100°
      Serial.print(msg.temperature); // 
      //delay(3600000); // 60min waiting
    } 
    else
    {
      Serial.print("Temperature : "); //  temp
      Serial.print(msg.temperature);
      //delay(15000); // 15min waiting
    }
}
void sound(){
  // Read Sound Sensor
  msg.sensorValue = analogRead(SOUND_SENSOR);

  // Condition sueil
  if(msg.sensorValue > THRESHOLD_VALUE) 
     {
      Serial.print("Sensor Sueil CRITIQUE :"); // seuil > 100
      Serial.println(msg.sensorValue);
      //delay(3600000); // 60min d'attente
     }
      else
    {
      Serial.print("sensorValue "); //  sueuil 
      Serial.println(msg.sensorValue); 
      //delay(15000); //15min waiting
     }
}

void temper(){

  // Read and convert the module temperature of Grove Temperature & humidity
  msg.temper = (int32_t) (TH02.ReadTemperature() * 100.0);

  // Condition temp mini / max / critical
  if(msg.temper > CRITIQUE_VALUE)
    {
      Serial.print("Temperature sueil CRITIQUE : "); //  higher 100°
      Serial.print(" (");
      Serial.print(msg.temper, HEX); // display what we will send in Hexadecimal
      
      Serial.print(msg.temper); // display what we will send in Decimal
      Serial.println(" x100 deg C)");
      //delay(3600000); // 60min waiting
    }
      else
    {
      Serial.print("Temperature : "); //  temp
      Serial.print(" (");
      Serial.print(msg.temper, HEX); // display what we will send in Hexadecimal
      
      Serial.print(msg.temper); // display what we will send in Decimal
      Serial.println(" x100 deg C)");
      //delay(15000); // 15min waiting
    }
    
    // Read and convert the module humidity
    float t = TH02.ReadHumidity();
    msg.humidity = (float) (t);
    Serial.print("Humidity :"); 
    Serial.println(msg.humidity); //  humidity
}

Maintenant, j'ai bien l'envoie des données toutes les 15min ( que j'ai défini pour l'instant ).

Sauf que maintenant, j'ai aucune donnée écris sur le monitor sauf lors de l'envoie.
Et ma function bluetooth ne fonctionne pas.

Si j'enlève :

// Clears all pending interrupts
  SigFox.status();
  delay(1);

  // Send the data
  SigFox.beginPacket();
  SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));

  // Status 
  Serial.println("Status: ");
  Serial.println(SigFox.endPacket());

  delay(300000);

Evidemment, tout marche dans le monitor + ble ...

Pourquoi, l'envoie de données a Sigfox bloque le reste ?

Bon je fais un petit monologue mais au cas où si ça peut aidé quelqu'un.

J'ai utilisé millis() pour utiliser la fonction d'envoi de donnée à SigFox.

Cela permet de "mettre en pause" juste le code qu'on veut. Et de l'activer au moment voulu. Sans bloquer la lecture de mes capteurs et de mon bluetooth.

unsigned long previousMillis = 0;
const long interval = 900000;

void loop(){

bluetooth();
temper();
sound();
temper2();
vibrator();
sigfox();

}

void sigfox(){

  unsigned long currentMillis = millis();

  if( currentMillis - previousMillis >= interval){
    previousMillis = currentMillis;
    
  // Clears all pending interrupts
  SigFox.status();
  delay(1);

  // Send the data
  SigFox.beginPacket();
  SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));

  // Status 
  Serial.println("Status: ");
  Serial.println(SigFox.endPacket());
  }
}

Maintenant, je me penche sur l'envoie des données avec un seuil avec intervalle d'une heure pour chaque capteurs qui remonte ses données.

Je penses créer une structure avec un nom différent + condition pour l'envoie de données et utiliser millis() pour chaque capteurs + fonction sigfox2 qui ce déclenche si la structure est remplie par une donnée.

Bon finalement, j'ai fais comme ça :

#include <SigFox.h> // library Sigfox
#include <TH02_dev.h> // library Grove Temperature & humidity
#include "Arduino.h"
#include "Wire.h"
#include <math.h> //library Grove Temperature Sensor
#include <ZSharpIR.h> //library Grove Infrared Proximity Sensor

#define ir A3 // ir: the pin where your sensor is attached
#define model 1080 // model: an int that determines your sensor: 1080 for GP2Y0A21Y
ZSharpIR SharpIR(ir, model);

#define SOUND_SENSOR A0 // define pin capteur Sound A0
#define THRESHOLD_VALUE 200 // Sound seuil critique

#define CRITIQUE_VALUE 500 // Temperature sueil critique

const int B = 4275;           // B value of the thermistor
const int R0 = 100000;       // R0 = 100k
#define pinTempSensor A1    // Grove - Temperature Sensor connect to A1
#define MAX_VALUE 35

int relay = 4; // define pin capteur Relay D4

char state; // return '0' = OFF and '1' = ON by APK bluetooth

const int PIEZO_PIN = A2; // define pin capteur Vibrator A2

unsigned long previousMillis = 0;
unsigned long previousMillisTempHumidity = 0;
unsigned long previousMillisSound = 0;
unsigned long previousMillisTemper = 0;
unsigned long previousMillisVibrator = 0;

const long interval = 900000; // 15 min
const long interval2 = 3600000; // 1 hour

typedef struct __attribute__ ((packed)) {
  int16_t temper; // 2 octet - Temperature pin I2C
  uint8_t humidity; // 1 octet - Humidity pin I2C
  uint8_t sensorValue; // 1 octet - Sound Sensor pin A0
  uint8_t temperature; // 1 octet - Temperature pin A1
  float vibra; // 4 octet - Vibration pin A2
} sigfox_message_t;


// stub for message which will be sent

sigfox_message_t msg;

void reboot() {
  NVIC_SystemReset();
  while (1);
}

void setup() {
  Serial.begin(9600); // Start Serial with 115200
  Serial1.begin(9600); // Serial Port TX + RX
  TH02.begin(); // Start library Grove Temperature & humidity
  pinMode(relay, OUTPUT); // Initialize relay

  if (!SigFox.begin()) {
    Serial.println("SigFox error, rebooting");
    reboot();
  }
  
  // Enable debug prints and LED indication
  SigFox.debug();

}

void loop() {
  
  bluetooth();
  temperAndHumidity();
  sound();
  temper();
  vibrator();
  sigfox();
  
}
    
void bluetooth() {

  unsigned long pepe1 = millis();  // takes the time before the loop on the library begins
  int dis = SharpIR.distance();  // this returns the distance to the object you're measuring
  Serial.print("Distance : ");
  Serial.println(dis);

  if (Serial1.available() > 0) // if Serial1 is available, return Serial1.read in state
  {
    state = Serial1.read();
  }

  if ((dis < 400) && (state == '1')) // if distance of Infrared is < 30cm and state return '1'
  {
    digitalWrite(relay, HIGH); // RELAY ON
    Serial1.print("RELAY : OFF"); // Send back, to the phone, the String "RELAY : OFF"
    state = 0;
  }

  if (dis > 400) // if distance of Infrared is > 30cm
  {
    digitalWrite(relay, LOW); // RELAY OFF
  }

  if (state == '0') // if state return '0'
  {
    digitalWrite(relay, LOW); // RELAY OFF
    Serial1.print("RELAY : ON"); // Send back, to the phone, the String "RELAY : ON"
    state = 0;
  }
}

void temperAndHumidity() {

  // Read and convert the module temperature of Grove Temperature & humidity
  msg.temper = (int32_t) (TH02.ReadTemperature() * 100.0);

  // Condition
  if (msg.temper > CRITIQUE_VALUE) higher 50°
  {
    unsigned long currentMillisTempHumidity = millis();
    if( currentMillisTempHumidity - previousMillisTempHumidity >= interval2)
    {
      previousMillisTempHumidity = currentMillisTempHumidity;
      
      Serial.print(msg.temper, HEX); // display what we will send in Hexadecimal
      Serial.print(msg.temper); // display what we will send in Decimal
      
      // Clears all pending interrupts
      SigFox.status();
      delay(1);
    
      // Send the data
      SigFox.beginPacket();
      SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));
    
      // Status 
      Serial.print("Status: ");
      Serial.println(SigFox.endPacket());
    }
  }
  else
  {
    Serial.print(msg.temper, HEX); // display what we will send in Hexadecimal
    Serial.print(msg.temper); // display what we will send in Decimal

  }

  // Read and convert the module humidity
  float t = TH02.ReadHumidity();
  msg.humidity = (float) (t);
  Serial.print(msg.humidity); 
}

void sound() {
  
  // Read Sound Sensor
  msg.sensorValue = analogRead(SOUND_SENSOR);
  
  // Condition seuil
  if (msg.sensorValue > THRESHOLD_VALUE) // seuil > 200
  {
    unsigned long currentMillisSound = millis();
    if( currentMillisSound - previousMillisSound >= interval2)
    {
      previousMillisSound = currentMillisSound;
      
      Serial.println(msg.sensorValue);

      // Clears all pending interrupts
      SigFox.status();
      delay(1);
    
      // Send the data
      SigFox.beginPacket();
      SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));
    
      // Status 
      Serial.print("Status: ");
      Serial.println(SigFox.endPacket());
    }
  }
  else
  {
    Serial.print(msg.sensorValue);
  }
}

void temper() {
  
  // Read and convert the module Temperature Sensor
  int a = analogRead(pinTempSensor);
  float R = 1023.0 / a - 1.0;
  R = R0 * R;

  msg.temperature = 1.0 / (log(R / R0) / B + 1 / 298.15) - 273.15; // convert to temperature via datasheet
  
  // Condition temp critical
  if (msg.temperature > MAX_VALUE) temp > 35° 
  {
    unsigned long currentMillisTemper = millis();
    if( currentMillisTemper - previousMillisTemper >= interval2)
    {
      previousMillisTemper = currentMillisTemper;
       
      Serial.print(msg.temperature); 

      // Clears all pending interrupts
      SigFox.status();
      delay(1);
    
      // Send the data
      SigFox.beginPacket();
      SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));
    
      // Status 
      Serial.print("Status: ");
      Serial.println(SigFox.endPacket());
    }
  }
  else
  {
    Serial.print(msg.temperature);
  }
}

void vibrator() {

  // Read Piezo ADC value in, and convert it to a voltage

  float piezoV = analogRead(PIEZO_PIN) * 0.103125;
  msg.vibra = (float) (piezoV);
  
  if (msg.vibra > 1.30)
  {
    unsigned long currentMillisVibrator = millis();
    if( currentMillisVibrator - previousMillisVibrator >= interval2)
    {
      previousMillisVibrator = currentMillisVibrator;
  
      Serial.print(msg.vibra);

      // Clears all pending interrupts
      SigFox.status();
      delay(1);
    
      // Send the data
      SigFox.beginPacket();
      SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));
    
      // Status 
      Serial.print("Status: ");
      Serial.println(SigFox.endPacket());
    }
  }
}

void sigfox(){

  unsigned long currentMillis = millis();

  if( currentMillis - previousMillis >= interval)
  {
    previousMillis = currentMillis;
    
    // Clears all pending interrupts
    SigFox.status();
    delay(1);
  
    // Send the data
    SigFox.beginPacket();
    SigFox.write((uint8_t*)&msg, sizeof(sigfox_message_t));
  
    // Status 
    Serial.print("Status: ");
    Serial.println(SigFox.endPacket());
  }
}

Si quelqu'un sait comment je peux améliorer ma fonction bluetooth, je suis preneur ! Actuellement quand j'ai la bonne distance + appuyer sur ON c'est allumer, si je m'éloignes ça s'éteins, mais si je me rapproche à la bonne distance ça reste éteins tant que j'ai pas appuyer sur ON de nouveau. J'aimerais qu'il garde en mémoire la dernière donnée "ON" donc "1" de ce fait si j'ai pas appuyer sur OFF quand je me rapproche à la bonne distance mon relais ce rallume. Cela m'évite d'appuyer à nouveau sur ON et de gagner du temps :slight_smile:

1 Like