POCL : Poke : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(MQTT)
(Arduino)
Ligne 78 : Ligne 78 :
 
===Découpe papier===
 
===Découpe papier===
 
===Arduino===
 
===Arduino===
 +
<pre>
 +
/////////////////////////
 +
//      POCL Poke      //
 +
/////////////////////////
 +
/*
 +
* Un POCL imaginé et réalisé au Hackathon POCL à l'édulab Rennes 2 les 9 et 10 décembre 2021.
 +
*
 +
*                                      BROCHAGE                           
 +
                                _________________                       
 +
                              /    D1 mini    \                     
 +
                          -  |[ ]RST        TX[ ]| -                   
 +
                          -  |[ ]A0  -GPIO  RX[ ]| -                   
 +
                              |[ ]D0-16    5-D1[ ]| -                   
 +
                              |[ ]D5-14    4-D2[ ]| -                   
 +
                    Bouton -  |[X]D6-12    0-D3[X]| - ruban de leds           
 +
                          -  |[ ]D7-13    2-D4[ ]| LED_BUILTIN         
 +
                          -  |[ ]D8-15    GND[X]| - GND (Bouton, MP3-TF-16P)           
 +
                          -  |[ ]3V3 .      5V[X]| - ruban de Led       
 +
                              |      +---+      |                   
 +
                              |_______|USB|_______|                     
 +
 +
Matériel :
 +
- des fils dupont.
 +
- un ruban de led RGB WS28B12
 +
- D1 mini (Wemos, LOLIN,...)
 +
- bouton poussoir
 +
- une alimentation 5V
 +
*/
 +
/*
 +
* Un travail d'équipe de :
 +
* Alma Oskouei
 +
* Gaëlle Bescond
 +
* Tony Vanpoucke
 +
* Wing-Anh Luy
 +
* Antony Le Goïc-Auffret
 +
  ___
 +
/ ___ \
 +
|_|  | |
 +
    /_/
 +
    _  ___  _
 +
    |_| |___|_| |_
 +
        ___|_  _|
 +
        |___| |_|
 +
Les petits Débrouillards - décembre 2021 CC-By-Sa http://creativecommons.org/licenses/by-nc-sa/3.0/
 +
// Programme inspiré de celui par Joël Gähwiler
 +
// https://github.com/256dpi/arduino-mqtt
 +
*/
 +
#include <ConditionalPrinter.h>
 +
#include <EncryptedConnectionData.h>
 +
#include <EncryptedConnectionLog.h>
 +
#include <ESP8266WiFiMesh.h>
 +
#include <EspnowConnectionManager.h>
 +
#include <EspnowDatabase.h>
 +
#include <EspnowEncryptionBroker.h>
 +
#include <EspnowMeshBackend.h>
 +
#include <EspnowNetworkInfo.h>
 +
#include <EspnowProtocolInterpreter.h>
 +
#include <EspnowTransmitter.h>
 +
#include <ExpiringTimeTracker.h>
 +
#include <FloodingMesh.h>
 +
#include <HeapMonitor.h>
 +
#include <JsonTranslator.h>
 +
#include <MeshBackendBase.h>
 +
#include <MeshCryptoInterface.h>
 +
#include <MessageData.h>
 +
#include <MutexTracker.h>
 +
#include <NetworkInfo.h>
 +
#include <NetworkInfoBase.h>
 +
#include <PeerRequestLog.h>
 +
#include <RequestData.h>
 +
#include <ResponseData.h>
 +
#include <Serializer.h>
 +
#include <TcpIpMeshBackend.h>
 +
#include <TcpIpNetworkInfo.h>
 +
#include <TimeTracker.h>
 +
#include <TransmissionOutcome.h>
 +
#include <TransmissionResult.h>
 +
#include <TypeConversionFunctions.h>
 +
#include <UtilityFunctions.h>
 +
 +
#include <ESP8266WiFi.h>
 +
#include <MQTT.h>
 +
#include <Adafruit_NeoPixel.h>
 +
 +
const char ssid[] = "iPhone de Antony";
 +
const char pass[] = "12345678";
 +
 +
WiFiClient net;
 +
MQTTClient client;
 +
 +
unsigned long lastMillis = 0;
 +
 +
//=============élément pour le ruban de led et le bouton===============
 +
 +
// Broche de connexion du ruban de LED
 +
#define PIN D3 //
 +
 +
int brocheBouton = 12; //GPIO de la broche D6
 +
 +
// Nombre de Led RDGB dans votre ruban
 +
#define NUMPIXELS 13
 +
 +
// on configurer un riban nommé "pixels"
 +
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
 +
 +
#define T 1 // temps pour gérer le fade du ruban
 +
//==============================================================
 +
 +
void connect() {
 +
  Serial.print("checking wifi...");
 +
  while (WiFi.status() != WL_CONNECTED) {
 +
    Serial.print(".");
 +
    delay(1000);
 +
  }
 +
 +
  Serial.print("\nconnecting...");
 +
  //connection au serveur MQTT : identifiant, canal, mot de passe
 +
  while (!client.connect("GAWELLE", "pocl21", "BauhTg9l28jam1lR")) {
 +
    Serial.print(".");
 +
    delay(1000);
 +
  }
 +
 +
  Serial.println("\nconnected!");
 +
 +
// on s'abonne au sujet (topic) "Poke"
 +
  client.subscribe("/Poke");
 +
  // client.unsubscribe("/hello");
 +
}
 +
 +
void messageReceived(String &topic, String &payload) {
 +
  digitalWrite(LED_BUILTIN, HIGH);
 +
  fade();
 +
  Serial.println("incoming: " + topic + " - " + payload);
 +
  if (payload == "pokou"){
 +
    Serial.println("clic !");
 +
    digitalWrite(LED_BUILTIN, LOW);
 +
    delay(100);
 +
    digitalWrite(LED_BUILTIN, HIGH);
 +
  }
 +
  // Note: Do not use the client in the callback to publish, subscribe or
 +
  // unsubscribe as it may cause deadlocks when other things arrive while
 +
  // sending and receiving acknowledgments. Instead, change a global variable,
 +
  // or push to a queue and handle it in the loop after calling `client.loop()`.
 +
}
 +
 +
void fade() {
 +
  for (int sig=0; sig<3; sig++){
 +
  for (int b=0; b<255; b++){
 +
  pixels.setBrightness(b);
 +
 
 +
  for(int i=0; i<NUMPIXELS; i++) {
 +
    pixels.setPixelColor(i, pixels.Color(150, b, 200));
 +
  }
 +
  pixels.show();  // On allume les rubans
 +
  delay(T);
 +
  }
 +
 +
  for (int b=255; b>1; b--){ //boucle de gestion de la brillance
 +
  pixels.setBrightness(b);
 +
 
 +
  // n'oubliez pas que le premier pixel porte le Numéro 0
 +
  for(int i=0; i<NUMPIXELS; i++) { // Pour chaque pixel...
 +
 +
    // pixels.Color() prends les valeurs RGB de 0,0,0 jusqu'à 255,255,255
 +
    pixels.setPixelColor(i, pixels.Color(b, 100, 100));
 +
  }
 +
  pixels.show();  // on affiche les pixels
 +
  delay(T);
 +
  }
 +
  }
 +
}
 +
 +
void setup() {
 +
  Serial.begin(115200);
 +
  pixels.begin(); //on initialise le ruban "pixels"
 +
  pinMode(brocheBouton,INPUT_PULLUP);
 +
 
 +
  pinMode(LED_BUILTIN, OUTPUT);
 +
  digitalWrite(LED_BUILTIN, HIGH);
 +
  WiFi.begin(ssid, pass);
 +
 +
  // on se connecte au client
 +
  client.begin("pocl21.cloud.shiftr.io", net);
 +
  client.onMessage(messageReceived);
 +
 +
  connect();
 +
}
 +
 +
void loop() {
 +
  pixels.clear(); // Set all pixel colors to 'off'
 +
  pixels.show();
 +
 
 +
  client.loop();
 +
  delay(10);  // <- fixes some issues with WiFi stability
 +
 +
  if (!client.connected()) {
 +
    connect();
 +
  }
 +
 +
  // publish a message roughly every second.
 +
 +
  if ( digitalRead(brocheBouton) == LOW ){
 +
  Serial.println("Appuis Bouton");
 +
  client.publish("/Poke", "pokou");
 +
  delay(250);
 +
  }
 +
}
 +
</pre>
 +
 
==premier diaporama : Alors ? Comment ça se passe ?==
 
==premier diaporama : Alors ? Comment ça se passe ?==
 
Diaporama type '''Alors ?''': [[media:DiaporamaSuperBrest2021-Alors.odp|Téléchargez et adaptez-le !]]
 
Diaporama type '''Alors ?''': [[media:DiaporamaSuperBrest2021-Alors.odp|Téléchargez et adaptez-le !]]

Version du 10 décembre 2021 à 17:53

Résumé du Projet

Le POCL communautaire.

Ce POCL est interactif, on peut agir sur lui :

  • tapoter
  • appuyer

...

Le projet a été réalisé par Alma, Wing-Anh, Tony, Antony, Gaelle

Il envoie un message à la communauté de ses homomorphes, qui réagissent par une ou des actions perceptibles par leurs possesseurs (signal lumineux, vibration etc...)

membres du projet

Alma, Wing-Anh, Tony, Antony, Gaelle

Prototype qu'on souhaite réaliser

au moins deux POCL Poke pour montrer les interactions

technologie

Boite

je découpe un truc pour faire rentrer les machins.

La boîte est un cylindre dont le matériau laisse passer la lumière comme le plexiglas ou le papier.

Les extrémités du cylindre sont faites de bois découpé au laser afin de renforcer la structure

matériel

  • 1 D1 Mini
  • 1 Ruban de LED ou
  • 1 Bouton poussoir

MQTT

L'interaction entre les POCL passe par un serveur MQTT (Message Queuing Telemetry Transport)

Example


Montage

Découpe du bois

Découpe papier

Arduino

/////////////////////////
//      POCL Poke      //
/////////////////////////
/*
 * Un POCL imaginé et réalisé au Hackathon POCL à l'édulab Rennes 2 les 9 et 10 décembre 2021.
 * 
 *                                      BROCHAGE                            
                                _________________                        
                               /     D1 mini     \                       
                           -  |[ ]RST        TX[ ]| -                    
                           -  |[ ]A0  -GPIO  RX[ ]| -                    
                              |[ ]D0-16    5-D1[ ]| -                    
                              |[ ]D5-14    4-D2[ ]| -                    
                    Bouton -  |[X]D6-12    0-D3[X]| - ruban de leds             
                           -  |[ ]D7-13    2-D4[ ]| LED_BUILTIN          
                           -  |[ ]D8-15     GND[X]| - GND (Bouton, MP3-TF-16P)             
                           -  |[ ]3V3 .      5V[X]| - ruban de Led        
                              |       +---+       |                     
                              |_______|USB|_______|                      

Matériel :
- des fils dupont.
- un ruban de led RGB WS28B12
- D1 mini (Wemos, LOLIN,...)
- bouton poussoir
- une alimentation 5V
*/
/*
 * Un travail d'équipe de :
 * Alma Oskouei
 * Gaëlle Bescond
 * Tony Vanpoucke
 * Wing-Anh Luy
 * Antony Le Goïc-Auffret
   ___
 / ___ \
|_|   | |
     /_/ 
     _   ___   _ 
    |_| |___|_| |_
         ___|_   _|
        |___| |_|
Les petits Débrouillards - décembre 2021 CC-By-Sa http://creativecommons.org/licenses/by-nc-sa/3.0/
// Programme inspiré de celui par Joël Gähwiler
// https://github.com/256dpi/arduino-mqtt
*/
#include <ConditionalPrinter.h>
#include <EncryptedConnectionData.h>
#include <EncryptedConnectionLog.h>
#include <ESP8266WiFiMesh.h>
#include <EspnowConnectionManager.h>
#include <EspnowDatabase.h>
#include <EspnowEncryptionBroker.h>
#include <EspnowMeshBackend.h>
#include <EspnowNetworkInfo.h>
#include <EspnowProtocolInterpreter.h>
#include <EspnowTransmitter.h>
#include <ExpiringTimeTracker.h>
#include <FloodingMesh.h>
#include <HeapMonitor.h>
#include <JsonTranslator.h>
#include <MeshBackendBase.h>
#include <MeshCryptoInterface.h>
#include <MessageData.h>
#include <MutexTracker.h>
#include <NetworkInfo.h>
#include <NetworkInfoBase.h>
#include <PeerRequestLog.h>
#include <RequestData.h>
#include <ResponseData.h>
#include <Serializer.h>
#include <TcpIpMeshBackend.h>
#include <TcpIpNetworkInfo.h>
#include <TimeTracker.h>
#include <TransmissionOutcome.h>
#include <TransmissionResult.h>
#include <TypeConversionFunctions.h>
#include <UtilityFunctions.h>

#include <ESP8266WiFi.h>
#include <MQTT.h>
#include <Adafruit_NeoPixel.h>

const char ssid[] = "iPhone de Antony";
const char pass[] = "12345678";

WiFiClient net;
MQTTClient client;

unsigned long lastMillis = 0;

//=============élément pour le ruban de led et le bouton===============

// Broche de connexion du ruban de LED
#define PIN D3 // 

int brocheBouton = 12; //GPIO de la broche D6

// Nombre de Led RDGB dans votre ruban
#define NUMPIXELS 13 

// on configurer un riban nommé "pixels"
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#define T 1 // temps pour gérer le fade du ruban
//==============================================================

void connect() {
  Serial.print("checking wifi...");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }

  Serial.print("\nconnecting...");
  //connection au serveur MQTT : identifiant, canal, mot de passe
  while (!client.connect("GAWELLE", "pocl21", "BauhTg9l28jam1lR")) {
    Serial.print(".");
    delay(1000);
  }

  Serial.println("\nconnected!");

// on s'abonne au sujet (topic) "Poke" 
  client.subscribe("/Poke");
  // client.unsubscribe("/hello");
}

void messageReceived(String &topic, String &payload) {
  digitalWrite(LED_BUILTIN, HIGH);
  fade();
  Serial.println("incoming: " + topic + " - " + payload);
  if (payload == "pokou"){
    Serial.println("clic !");
    digitalWrite(LED_BUILTIN, LOW);
    delay(100);
    digitalWrite(LED_BUILTIN, HIGH);
  }
  // Note: Do not use the client in the callback to publish, subscribe or
  // unsubscribe as it may cause deadlocks when other things arrive while
  // sending and receiving acknowledgments. Instead, change a global variable,
  // or push to a queue and handle it in the loop after calling `client.loop()`.
}

void fade() {
  for (int sig=0; sig<3; sig++){
  for (int b=0; b<255; b++){
  pixels.setBrightness(b);
  
  for(int i=0; i<NUMPIXELS; i++) {
    pixels.setPixelColor(i, pixels.Color(150, b, 200));
  }
  pixels.show();   // On allume les rubans
  delay(T);
  }

  for (int b=255; b>1; b--){ //boucle de gestion de la brillance
  pixels.setBrightness(b);
  
  // n'oubliez pas que le premier pixel porte le Numéro 0
  for(int i=0; i<NUMPIXELS; i++) { // Pour chaque pixel...

    // pixels.Color() prends les valeurs RGB de 0,0,0 jusqu'à 255,255,255
    pixels.setPixelColor(i, pixels.Color(b, 100, 100));
  }
  pixels.show();   // on affiche les pixels
  delay(T);
  }
  }
}

void setup() {
  Serial.begin(115200);
  pixels.begin(); //on initialise le ruban "pixels"
  pinMode(brocheBouton,INPUT_PULLUP);
  
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  WiFi.begin(ssid, pass);

  // on se connecte au client
  client.begin("pocl21.cloud.shiftr.io", net);
  client.onMessage(messageReceived);

  connect();
}

void loop() {
  pixels.clear(); // Set all pixel colors to 'off'
  pixels.show();
  
  client.loop();
  delay(10);  // <- fixes some issues with WiFi stability

  if (!client.connected()) {
    connect();
  }

  // publish a message roughly every second.

  if ( digitalRead(brocheBouton) == LOW ){
  Serial.println("Appuis Bouton"); 
  client.publish("/Poke", "pokou");
  delay(250);
  }
}

premier diaporama : Alors ? Comment ça se passe ?

Diaporama type Alors ?: Téléchargez et adaptez-le !

second diaporama : Et voilà !

Diaporama type Et Voilà ! : Téléchargez et adaptez-le !