Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. ESP32, MySensors and function

ESP32, MySensors and function

Scheduled Pinned Locked Moved Development
2 Posts 2 Posters 52 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vidou
    wrote on last edited by
    #1

    Hello everyone. I would like to create a code that allows me to open a door remotely using the MySensors library.

    So I have a rather ugly code that works, but I would like to make it more optimized and readable. So I have this now: In my “main.ino” file :

    #include <MySensors.h>
    #include "Gestion_Porte.hpp"
    
    void receive(const MyMessage &message) // Lors de réception d'un message.
    {
    	if (message.sensor == ID_GESTION_PORTE) // Si c'est message du noeud 0 (gestion de la porte) :
    	{
    		if (message.getBool())
    			Ouverture_Porte(&debugMessage, &etatPorteMessage);
    		else
    			Fermeture_Porte(&debugMessage, &etatPorteMessage);
    		
    		delay(10);
    	}
    

    in my file Gestion_Porte.hpp i've :

    #ifndef GESTIONPORTE_HPP
        #define GESTIONPORTE_HPP
    
        #include <Arduino.h>
        #include <MySensors.h>
    
        void Ouverture_Porte(MyMessage *pDebugMessage, MyMessage *pEtatPorteMessage);
        void Fermeture_Porte(MyMessage *pDebugMessage, MyMessage *pEtatPorteMessage);
    
    #endif
    

    in Gestion_Porte.ino :

    void Ouverture_Porte(MyMessage *pDebugMessage, MyMessage *pEtatPorteMessage)
    {
        unsigned char ouvertureOk = 0;
    
    	pDebugMessage->set("Ouverture de la porte");
    	send(*pDebugMessage);
    
    	if (digitalRead(PIN_FDC_OPEN)) // Si le détecteur de fin de course ouverture n'est pas actif, alors :
        {
            uint64_t timeCount = millis();
    
            digitalWrite(PIN_RELAY_PORTE,HIGH); // Alim 12V pour moteur.
            delay(20);
    
            ledcAttachPin(PIN_DRIVER_IN1, 0); // Attache la pin PIN_DRIVER_IN1 au canal pwm N°0 configuré ci-après.
    	    ledcWrite(0, 250); // Initialise le canal pwm 0 (voir setup()) à un signal pwm de 254 (= 1 logique).
    	    digitalWrite(PIN_DRIVER_IN2, LOW);
    
            while (digitalRead(PIN_FDC_OPEN) && ouvertureOk != 2) // Tant que le fin de course ouverture n'est pas actif :
            {
                if (millis() - timeCount > DELAY_OUVERTURE) // Si on est dans cette boucle plus longtemps que DELAY_OUVERTURE, alors :
                {
                    ouvertureOk = 2; // Valeur 2 = erreur.
                    pDebugMessage->set("Porte bloquee");
                }
    
                delay(2);
            } 
            
            ledcWrite(0, 0); // Met la vitesse du moteur à 0.
            ledcDetachPin(PIN_DRIVER_IN1); // Detache la pin PIN_DRIVER_IN1 du canal pwm N°0.
            digitalWrite(PIN_RELAY_PORTE,LOW); // Coupe l'alim 12V.
            //pinMode(PIN_DRIVER_IN2, INPUT);        
        }
    
    	if(!digitalRead(PIN_FDC_OPEN)) // Si le détecteur de fin de course ouverture est actif,
    	{
            ouvertureOk = 1; // Valeur 1 = Ouvert.
            pDebugMessage->set("Porte ouverte");
        }
    
    	pEtatPorteMessage->set(ouvertureOk); // ouvertureOK = soit 1 soit 2.
    	send(*pDebugMessage);
        send(*pEtatPorteMessage);
    }
    ...
    

    I can’t compile it and I get this error message:

    c:/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\main.cpp.o:C:\usr\Bureau\Emeteur_Recepteur RF24 ESP32 (Poulailler)/.pio/libdeps/ESP32/MySensors/core/MyTransport.cpp:46: multiple definition of _transportReady_cb'; .pio\build\ESP32\src\Gestion_Porte.cpp.o:C:\usr\OneDrive\Bureau\Emeteur_Recepteur RF24 ESP32 (Poulailler)/.pio/libdeps/ESP32/MySensors/core/MyTransport.cpp:46: first defined here c:/usr/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\ESP32\src\main.cpp.o: in function stReadyTransition()':

    I understand that the problem might come from the fact that I have #include <MySensors> in the main and the Gestion_Porte but then I don’t understand how to do with the pointers in my Gestion_Porte file.

    If someone can help me, it would be with pleasure :slight_smile:

    Thank you

    1 Reply Last reply
    0
    • electrikE Offline
      electrikE Offline
      electrik
      wrote on last edited by electrik
      #2

      You should only include the relevant header file in the file Gestion_Porte.hpp, not Mysensors.h
      For example

      #include <core/MyTransport.h>
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      22

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular