Différences entre versions de « Projets:Testi »

De wikiup
Sauter à la navigation Sauter à la recherche
Ligne 16 : Ligne 16 :
 
==Code==
 
==Code==
 
<pre>
 
<pre>
bool connectToServer() {
+
//
  Serial.print("Forming a connection to ");
 
  Serial.println(myDevice->getAddress().toString().c_str());
 
  
  BLEClient* pClient  = BLEDevice::createClient();
+
/**
  Serial.println(" - Created client");
+
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.  
  
  pClient->setClientCallbacks(new MyClientCallback());
+
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;
  
  // Connect to the remove BLE Server.
+
int counterA = 0;
  pClient->connect(myDevice); // if you pass BLEAdvertisedDevice instead of address, it will be recognized type of peer device address (public or private)
+
int counterB = 0;
  Serial.println(" - Connected to server");
+
int counterC = 0;
 +
int counterD = 0;
  
  
  // Obtain a reference to the service we are after in the remote BLE server.
+
const int interruption_pin = 21;
   BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
+
const int pot_pin = 34;
   if (pRemoteService == nullptr) {
+
 
     Serial.print("Failed to find our service UUID: ");
+
//End Triac related
     Serial.println(serviceUUID.toString().c_str());
+
 
     pClient->disconnect();
+
#include "BLEDevice.h"
     return false;
+
//#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;
 
   }
 
   }
  Serial.println(" - Found our service");
+
}
 +
 
 +
//////////End triac related
  
  

Version du 1 juin 2021 à 17:57

Description du projet

Une fois sur deux

Cahier des charges

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


Matériel nécessaire

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