Différences entre versions de « Projets:Testi »

De wikiup
Sauter à la navigation Sauter à la recherche
 
(18 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
 
== Description du projet ==
 
== Description du projet ==
Une fois sur deux
+
test de la date et heure
  
 
== Cahier des charges ==
 
== Cahier des charges ==
 +
<pre>
 +
if (pRemoteService == nullptr) {
 +
</pre>
  
 
== Analyse de l'existant ==
 
== Analyse de l'existant ==
Ligne 15 : Ligne 18 :
  
 
==Code==
 
==Code==
<code>
 
 
<pre>
 
<pre>
 
//
 
//
Ligne 106 : Ligne 108 :
 
//////////End triac related
 
//////////End triac related
  
 
+
static void notifyCallback(
 
+
   BLERemoteCharacteristic* pBLERemoteCharacteristic,
void setup() {
+
   uint8_t* pData,
   //////////triac related/////////////
+
   size_t length,
  Serial.begin(115200);
+
   bool isNotify) {
  Serial.println("init setup triac");
 
 
 
  // Zero crossing detection
 
  // Rising edge is enough : it should generate 100 interrupts per second.
 
  pinMode(21, INPUT_PULLUP);
 
  attachInterrupt(21, rising_edge_isr, RISING);
 
 
 
  // Output configuration
 
  pinMode(16, OUTPUT);
 
 
 
  // Timer prescaler configuration
 
  // with a 80 prescaler value, timer value is
 
  // directly expressed in microseconds
 
  timer = timerBegin(0, 80, true); // croissant
 
  timerStop(timer);
 
  timerAttachInterrupt(timer, &timer_isr, true);
 
  //timerAttachInterrupt(timer, &timer_isr, false);
 
 
 
  ///end of triac related
 
  Serial.println("Starting Arduino BLE Client application...");
 
  BLEDevice::init("");
 
 
 
  // Retrieve a Scanner and set the callback we want to use to be informed when we
 
  // have detected a new device.  Specify that we want active scanning and start the
 
   // scan to run for 5 seconds.
 
  BLEScan* pBLEScan = BLEDevice::getScan();
 
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
 
  pBLEScan->setInterval(1349);
 
  pBLEScan->setWindow(449);
 
  pBLEScan->setActiveScan(true);
 
  pBLEScan->start(5, false);
 
   Serial.println("CLEARDATA");  // on efface les données déjà présentes, s'il y a lieu
 
   Serial.println("LABEL,Temps,W,X,Y,Z");
 
 
 
 
    
 
    
 +
  w = pData[0];//w = perifit[0];
 +
  x = pData[1];
 +
  y = pData[2];
 +
  z = pData[3];
 +
  ps = x + (256 * w);
 +
  pp = z + (256 * y);
 +
  myvalue = map(ps, 180, 2700, 10500, 1500);//If the lamp lights on when should not, put a lower value for 10500. Si l'ampoule s'allume au repos par erreur baisser un peu la valeur de 10500 dans le mapping
  
 +
}
  
} // End of setup.
+
class MyClientCallback : public BLEClientCallbacks {
 +
    void onConnect(BLEClient* pclient) {
 +
    }
  
 
+
    void onDisconnect(BLEClient* pclient) {
// This is the Arduino main loop function.
+
      connected = false;
void loop() {
+
       Serial.println("onDisconnect");
 
 
 
 
  // If the flag "doConnect" is true then we have scanned for and found the desired
 
  // BLE Server with which we wish to connect.  Now we connect to it.  Once we are
 
  // connected we set the connected flag to be true.
 
  if (doConnect == true) {
 
    if (connectToServer()) {
 
      Serial.println("We are now connected to the BLE Server.");
 
    } else {
 
       Serial.println("We have failed to connect to the server; there is nothin more we will do.");
 
 
     }
 
     }
    doConnect = false;
+
};
  }
 
 
 
  // If we are connected to a peer BLE Server, update the characteristic each time we are reached
 
  // with the current time since boot.
 
  
  if (connected) {
+
bool connectToServer() {
    String newValue = "Time since boot: " + String(millis() / 1000);
+
  Serial.print("Forming a connection to ");
    Serial.println("Setting new characteristic value to \"" + newValue + "\"");
+
  Serial.println(myDevice->getAddress().toString().c_str());
  
    // Set the characteristic's value to be the array of bytes that is actually a string.
+
  BLEClient*  pClient  = BLEDevice::createClient();
    // pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length());
+
  Serial.println(" - Created client");
    pRemoteCharacteristic->writeValue(newValue.c_str(), newValue.length());
 
  
   
+
  pClient->setClientCallbacks(new MyClientCallback());
  
   } else if (doScan) {
+
   // Connect to the remove BLE Server.
    BLEDevice::getScan()->start(0);  // this is just eample to start scan after disconnect, most likely there is better way to do it in arduino
+
  pClient->connect(myDevice);  // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
   }
+
   Serial.println(" - Connected to server");
  
   delay(1000); // Delay a second between loops.
+
   // Obtain a reference to the service we are after in the remote BLE server.
} // End of loop
+
  BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
 
</pre>
 
</pre>
</code>
 
 
== Matériel nécessaire ==
 
  
 
==Outils nécessaires==
 
==Outils nécessaires==

Version actuelle datée du 27 octobre 2021 à 16:23

Description du projet

test de la date et heure

Cahier des charges

 if (pRemoteService == nullptr) {

Analyse de l'existant

Equipe (Porteur de projet et contributeurs)

  • Porteurs du projet :
  • Concepteurs/contributeurs :
  • Animateur (coordinateur du projet)
  • Fabmanager référent
  • Responsable de documentation

Code

//

/**
Code to get values from a BLE device based on the following example :https://github.com/nkolban/ESP32_BLE_Arduino/blob/master/examples/BLE_client/BLE_client.ino. 

Updated by Delphine with the great help of Gigi35, from My Human Kit. The customization is appropriated to work with electronic component triac that make it possible to dim the 220V light.
*/
//Triac related
int mydelay = 0;
int myvalue = 0;
int timer_step = 2;
hw_timer_t *timer = NULL;

int counterA = 0;
int counterB = 0;
int counterC = 0;
int counterD = 0;


const int interruption_pin = 21;
const int pot_pin = 34;

//End Triac related

#include "BLEDevice.h"
//#include "BLEScan.h"

// The remote service we wish to connect to.
static BLEUUID serviceUUID("0000aa40-0000-1000-8000-00805f9b34fb"); //Custom here with your values
// The characteristic of the remote service we are interested in.
static BLEUUID    charUUID("0000aa41-0000-1000-8000-00805f9b34fb");//Custom here with your values

static boolean doConnect = false;
static boolean connected = false;
static boolean doScan = false;
static BLERemoteCharacteristic* pRemoteCharacteristic;
static BLEAdvertisedDevice* myDevice;

int perifit[] = {0, 0, 0, 0};

int w;
int x;
int y;
int z;
int pp;
int ps;



///triac related////////////
void IRAM_ATTR rising_edge_isr() {

  if (timer_step == 2) {
    // No need to read anything : it is a rising edge
    // We just need to configure a timer interrupt
    // with current value of mydelay
    timer_step = 0;
    timerAlarmWrite(timer, myvalue, false);
    timerAlarmEnable(timer);
    timerRestart(timer);
    counterA = counterA + 1;
  } else {
    counterD = counterD + 1;
  }
}

void IRAM_ATTR timer_isr() {
  if (timer_step == 0) {
    // Activate triac
    digitalWrite(16, HIGH);
    timer_step = 1;
    // Configure the timer again to end the pulse
    // in 100 us
    timerAlarmWrite(timer, 100, false);
    //timerAlarmWrite(timer, 500,false);
    timerRestart(timer);
    timerAlarmEnable(timer);
    counterB = counterB + 1;
  } else if (timer_step == 1) {
    // End the pulse
    digitalWrite(16, LOW);
    timerStop(timer);
    counterC = counterC + 1;
    timer_step = 2;
  }
}

//////////End triac related

static void notifyCallback(
  BLERemoteCharacteristic* pBLERemoteCharacteristic,
  uint8_t* pData,
  size_t length,
  bool isNotify) {
  
  w = pData[0];//w = perifit[0];
  x = pData[1];
  y = pData[2];
  z = pData[3];
  ps = x + (256 * w);
  pp = z + (256 * y);
  myvalue = map(ps, 180, 2700, 10500, 1500);//If the lamp lights on when should not, put a lower value for 10500. Si l'ampoule s'allume au repos par erreur baisser un peu la valeur de 10500 dans le mapping

}

class MyClientCallback : public BLEClientCallbacks {
    void onConnect(BLEClient* pclient) {
    }

    void onDisconnect(BLEClient* pclient) {
      connected = false;
      Serial.println("onDisconnect");
    }
};

bool connectToServer() {
  Serial.print("Forming a connection to ");
  Serial.println(myDevice->getAddress().toString().c_str());

  BLEClient*  pClient  = BLEDevice::createClient();
  Serial.println(" - Created client");

  pClient->setClientCallbacks(new MyClientCallback());

  // Connect to the remove BLE Server.
  pClient->connect(myDevice);  // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
  Serial.println(" - Connected to server");

  // Obtain a reference to the service we are after in the remote BLE server.
  BLERemoteService* pRemoteService = pClient->getService(serviceUUID);

Outils nécessaires

Coût

Délai estimé

Fichiers source

Etapes de fabrication pas à pas

Durée de fabrication du prototype final

Journal de bord