Controlling Mobius enabled VorTech pump using 0-10V (and BLE)

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
I think I make it work... Simply uploading again the software.
If I set the 0-10V pin to a corresponding 5V it triggers the Feed mode on my pump. There's a way to keep the feed mode until the pin is at 5V?
You don't need the ADC to enable feed mode, you can use a simple digitalRead(GPIO) and add a momentary push-button to activate the feed scene like the below:
esp32-button-wiring-diagram.jpg


You could also add more momentary switches to enable other scenes.

As far as I could test, the Feed scene will switch back to normal after the feed timeout you set in Mobius app is reached, so a potential way to keep the feed scene on is to continually set the feed scene so you're always resetting the timeout counter.

rgrds
 

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
Somehow wasn’t aware of this thread but it does raise the question of “why isn’t there a Home Assistant integration for this”. Even if it’s just feed mode setting.
I guess no one with enough BLE + HA knowledge took the challenge?

I'd say if you run HA on RPi it would be just a matter of writing the python libraries to use the Pi BLE stack to talk to the Mobius devices? As I was able to run a simple python script from my PC's bluetooth adapter to find the Mobius addresses and list their UUIDs.

cheers.
 

theatrus

Valuable Member
View Badges
Joined
Mar 26, 2016
Messages
2,223
Reaction score
3,632
Location
Sacramento, CA area
Rating - 0%
0   0   0
I guess no one with enough BLE + HA knowledge took the challenge?

I'd say if you run HA on RPi it would be just a matter of writing the python libraries to use the Pi BLE stack to talk to the Mobius devices? As I was able to run a simple python script from my PC's bluetooth adapter to find the Mobius addresses and list their UUIDs.

cheers.

I mean I'm not blaming anyone :beaming-face-with-smiling-eyes:

Its all a matter of time - the good thing on the HA front is it has good support for BLE devices directly, including GATT devices which need active connections, as well as using ESP32 devices as bridges to extend reach.
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
145
Reaction score
105
Location
Italy
Rating - 0%
0   0   0
Thanks all for the reply!
You don't need the ADC to enable feed mode, you can use a simple digitalRead(GPIO) and add a momentary push-button to activate the feed scene like the below:
esp32-button-wiring-diagram.jpg


You could also add more momentary switches to enable other scenes.

As far as I could test, the Feed scene will switch back to normal after the feed timeout you set in Mobius app is reached, so a potential way to keep the feed scene on is to continually set the feed scene so you're always resetting the timeout counter.

rgrds
Thank you for the drawing, I'll do some more test... Yes the best thing would be to have an HA direct integration. But for now I can use a Reef-Pi outlet to control the pin on an Atom Lite board as it's super tiny.
I really don't want to switch ON/OFF the outlet of the MP10 to feed the tank..
 

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
There you go, please note this is just a proof of concept and was not well tested:


C++:
/*!
 *
 * MQTT interface for Mobius BLE.
 *
 * HA mqtt auto discovery with a switch and a sensor.
 *  Switch is to set the Feed mode
 *  Sensor is to report the QTY of Mobius devices found by the scan feature
 *  it will intercept the switch to set feed mode and set the Normal schedule back
 * 
 *
 * Work in progress
 *
 */
#include <ESP32_MobiusBLE.h>
#include "ArduinoSerialDeviceEventListener.h"

#include "EspMQTTClient.h"
#include <string>
#include "secrets.h"
#include <esp_task_wdt.h>
#include <ArduinoJson.h>

#ifndef LED_BUILTIN
#define LED_BUILTIN 6
#endif

//1 seconds WDT
#define WDT_TIMEOUT 30
#define EXE_INTERVAL 300000

unsigned long lastExecutedMillis = 0; // variable to save the last executed time

// Configuration for wifi and mqtt
EspMQTTClient client(
  mySSID,                // Your Wifi SSID
  myPassword,            // Your WiFi key
  "homeassistant.local", // MQTT Broker server ip
  mqttUser,              // mqtt username Can be omitted if not needed
  mqttPass,              // mqtt pass Can be omitted if not needed
  "Mobius",              // Client name that uniquely identify your device
  1883                   // MQTT Broker server port
);

char* jsonSwitchDiscovery =  "{\
    \"name\":\"Feed Mode\",\
    \"command_topic\":\"homeassistant/switch/mobiusBridge/set\",\
    \"state_topic\":\"homeassistant/switch/mobiusBridge/state\",\
    \"unique_id\":\"mobius01ad\",\
    \"device\":{\
      \"identifiers\":[\
        \"mobridge01ad\"\
      ],\
      \"name\":\"Mobius\",\
      \"manufacturer\": \"xx\",\
      \"model\": \"Mobius BLE Bridge\",\
      \"sw_version\": \"2024.1.0\"\
         }}";

char* jsonSensorDiscovery =  "{ \
    \"name\":\"QTY Devices\",\
    \"state_topic\":\"homeassistant/sensor/mobiusBridge/state\",\
    \"value_template\":\"{{ value_json.qtydevices}}\",\
    \"unique_id\":\"qtydev01ae\",\
    \"device\":{\
      \"identifiers\":[\
        \"mobridge01ad\"\
      ]\
      }\
    }";

bool prevState = false;
bool currState = false;
bool configPublish = false;
bool firstRun = true;

// wifi and mqtt connection established
void onConnectionEstablished()
{
  ESP_LOGI(LOG_TAG, "Connected to MQTT Broker :)");
 
  // Listen for a scene update from mqtt and call the update function
  // May need to do this from the loop(). Test.
  client.subscribe("homeassistant/switch/mobiusBridge/set", [](const String& feedMode) {
    if (feedMode.length() > 0) {
      if (feedMode == "ON") {
        currState = true;
        digitalWrite(LED_BUILTIN, HIGH);
      } else {
        currState = false;
        digitalWrite(LED_BUILTIN, LOW);
      }
      configPublish = false;

      ESP_LOGI(LOG_TAG, "INFO: Update device scene from MQTT trigger: %s\n", feedMode);
    }
  });

}

// Define a device buffer to hold found Mobius devices
MobiusDevice deviceBuffer[20];
int deviceCount = 0;

JsonDocument doc;

void setup() {
  // connect the serial port for logs
  Serial.begin(115200);
  while (!Serial);

  esp_task_wdt_init(WDT_TIMEOUT, true); //enable panic so ESP32 restarts
  esp_task_wdt_add(NULL); //add current thread to WDT watch

  pinMode(LED_BUILTIN, OUTPUT);
  prevState = !currState;
  firstRun = true;

  client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overridded with enableHTTPWebUpdater("user", "password").
 
  // Increase default packet size for HA mqtt json messages
  client.setMaxPacketSize(2048);

  // Initialize the library with a useful event listener
  MobiusDevice::init(new ArduinoSerialDeviceEventListener());

  ESP_LOGI(LOG_TAG, "Setup run");
}

void loop() {
  // Wait for mqtt and wifi connection
  while(!client.isConnected()){client.loop();};

  // Loop mqtt
  client.loop();


  // create buffer to store the Mobius devices
  MobiusDevice device = deviceBuffer[0];

  if (!configPublish) {
    //Scan BLE and MQTT Publish the main config only on boot or on status change

    //Scan for Mobius devices
    int scanDuration = 15; // in seconds
    deviceCount = 0;

    while (!deviceCount) {
      //Scan until at least one device is returned
      deviceCount = MobiusDevice::scanForMobiusDevices(scanDuration, deviceBuffer,10);
      ESP_LOGD(LOG_TAG, "INFO: Mobius Devices found: %i\n", deviceCount);
      esp_task_wdt_reset();
    }

    if (!client.publish("homeassistant/switch/mobiusBridge/config", jsonSwitchDiscovery)) {  //This one is for the switch
      ESP_LOGD(LOG_TAG, "ERROR: Did not publish");
    }

    if (!client.publish("homeassistant/sensor/mobiusBridge/config", jsonSensorDiscovery)) { //This is for the QTY
      ESP_LOGD(LOG_TAG, "ERROR: Did not publish");
    }

    configPublish = true;
  }

  /***************************************************************
  ************       BLE Connection starts here       ************
  ***************************************************************/
  //inside the mqtt subscribe function onConnectionEstablished(), it will turn the LED on with digitalWrite(LED_BUILTIN, HIGH);
  //using GPIO to proxy the Mobius Scene.
  bool currState = digitalRead(LED_BUILTIN);

    if (prevState != currState) {
    //If Current state is different from previous, publish MQTT state
    ESP_LOGD(LOG_TAG, "INFO: Publishing state");

    if (currState) {
      //This is Feed Mode
      ESP_LOGD(LOG_TAG, "INFO: LED is ON");
      if (!client.publish("homeassistant/switch/mobiusBridge/state", "ON")) {
        ESP_LOGD(LOG_TAG, "ERROR: Did not publish LED on");
      }
    } else {
      //This is Normal Operation
      ESP_LOGD(LOG_TAG, "INFO: LED is OFF");
      if (!client.publish("homeassistant/switch/mobiusBridge/state", "OFF")) {
        ESP_LOGD(LOG_TAG, "ERROR: Did not publish LED off");
      }
    }

    if (!firstRun){
      // Do not connect to device during boot

      for (int i = 0; i < deviceCount; i++) {
        // connect to each device in buffer to set the new scene
        device = deviceBuffer[i];

        int tries = 1;
        //loop until connected or exit after 10 tries
        while(tries<=10){

          // Get manufacturer info
          std::string manuData = device._device->getManufacturerData();

          // Don't connect unless we have a serial number
          if (manuData.length() > 1){
            // Connect, get serialNumber and current scene
            ESP_LOGI(LOG_TAG, "\nINFO: Connect to device number: %i\n", i);
            if (device.connect()) {

              ESP_LOGI(LOG_TAG, "INFO: Connected to: %s\n", device._device->toString().c_str());

              // serialNumber is from byte 11
              std::string serialNumberString = manuData.substr(11, manuData.length());
              char serialNumber[serialNumberString.length() + 1] = {};
              strcpy(serialNumber, serialNumberString.c_str());
              ESP_LOGD(LOG_TAG, "INFO: Device serial number: %s\n", serialNumber);

              //Get Current scene
              uint16_t sceneId = device.getCurrentScene();

              //Convert scene from int to friendly MQTT text
              char currScene[2];
              sprintf(currScene, "%u", sceneId);
              
              // delaying without sleeping
              unsigned long startMillis = millis();
              while (1000 > (millis() - startMillis)) {}

              /*===============================================
              =====               Set Scene               =====
              ===============================================*/
              if ((sceneId!=1) and (currState) ) {
                //Scene is different from feed mode (1), and Feed switch is ON, set device to feed mode
                device.setFeedScene();
              } else if ((sceneId==1) and !currState) {
                //Scene is feed mode (1), and Feed switch is OFF, set device to Normal Schedule
                device.runSchedule();
              }

              //Disconnect from Mobius Device
              device.disconnect();

              //If connection completed, break the loop
              break;
            }
            else {
              tries++;
            }
          }
        }

        //Print error message if didn't connect after 10 tries
        if (tries>9) {
          ESP_LOGE(LOG_TAG, "ERROR: Failed to connect to device");
        }
      }
    }   

    char cstr[20];
    JsonDocument jsonQtyDev;
    jsonQtyDev["qtydevices"] = deviceCount;
    serializeJson(jsonQtyDev, cstr);

    ESP_LOGD(LOG_TAG, "INFO: Mobius BLE device count: %i\n", deviceCount);
    
      if (!client.publish("homeassistant/sensor/mobiusBridge/state", cstr)) {
        ESP_LOGD(LOG_TAG, "ERROR: Did not publish qtyitems");
      }

    prevState = currState;
  }

  firstRun = false;
 
  esp_task_wdt_reset();
}

you also need to create a secrets.h file with:

#define mySSID "SSID"
// Your WiFi key
#define myPassword "WIFI PASS"
// mqtt username Can be omitted if not needed
#define mqttUser "user"
// mqtt pass Can be omitted if not needed
#define mqttPass "mqtt pass"
 

iamdan

Community Member
View Badges
Joined
Jul 1, 2022
Messages
87
Reaction score
74
Location
Western Australia
Rating - 0%
0   0   0
Hi All

Stumbled across this thread and being my first time doing anything with an Arduino and while being in IT i do everything else bar programming lol i am suprised with myself i got as far as i did lol!

I used the esp32-MobiusBLE with the NimBLE-Arduino libraries so many thanks to everyone for their various contributions - I honestly don't know how you have the patience :p

I managed after a lot of trial and error for me and chatgpt for suggestions to code this and getting the Mobius Feed Mode to activate via momentary touching a wire between Pin32 on my ESP32 Dev Board to GND which works:

Code:
#include <ESP32_MobiusBLE.h>
#include "FastLEDDeviceEventListener.h"

const int BUTTON_PIN = 32;

volatile int buttonPressCount = 0;
volatile unsigned long lastDebounceTime = 0;
volatile unsigned long debounceDelay = 50;

MobiusDevice pump; // Define the Mobius device instance

void setup() {
  Serial.begin(115200);
  while (!Serial);

  pinMode(BUTTON_PIN, INPUT_PULLUP);

  MobiusDevice::init(new FastLEDDeviceEventListener());

  MobiusDevice deviceBuffer[10];

  int count = 0;
  int scanDuration = 5; // in seconds
  while (!count) {
    count = MobiusDevice::scanForMobiusDevices(scanDuration, deviceBuffer);
  }

  int expectedDevices = 1;
  if (count != expectedDevices) {
    Serial.println("Failed to find any Mobius Device");
  }
 
  pump = deviceBuffer[0];
 
  attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonInterrupt, FALLING);
}

void loop() {
  if (buttonPressCount == 1) {
    if (pump.connect()) {
      Serial.println("Started Mobius Feed Mode Scene");
      if(pump.setFeedScene()) {
        // Reset button press count after action
        buttonPressCount = 0;
      }
      pump.disconnect();
    }
  } else if (buttonPressCount == 2) {
    if (pump.connect()) {
      Serial.println("Maintenance Mode");
      uint16_t sceneId = 1234; // Set the custom scene ID
      if(pump.setScene(sceneId)) {
        // Reset button press count after action
        buttonPressCount = 0;
      }
      pump.disconnect();
    }
  }
}

void buttonInterrupt() {
  unsigned long currentMillis = millis();

  if (currentMillis - lastDebounceTime > debounceDelay) {
    buttonPressCount++;
    lastDebounceTime = currentMillis;
  }
}

However i cannot accurately get "maintenance mode" to trigger if i touch twice.

I figured out some code that i accidently lost when my PC BSOD that had worked for shortpress for "feed mode" / longpress for "maintenance mode" but that still had the same issue that i couldnt reliably select "maintenance mode"

I was wondering how i change this code so "feed mode" is when Pin32 to GND is triggered and "maintenance mode" when say Pin33 to GND is triggered?

Now i realise in this code "Maintenance Mode" does nothing it was there for me more as a proof of concept that i can reliably trigger one mode over the other...

What i would like "maintenance mode" to actually do is to revert the pumps back to their scene.

How do i do this?

I have learnt alot about what some of the code does etc however i am a bit dyslexic and would appreciate immensley if someone can provide a sketch based off of the above for what i want as then i can look at my current code and then the new code and i can then understand in my own way why things are changed etc etc

My hope is once i get this sorted i can write up a guide for myself and others to follow that if they want to setup like mine or even if not least its a good starting point.

I did try to compile @Paulo Hanashiro sketch as controlling via home assistant and MQTT would be my ultimate goal aswell but yeah error after error i could not figure out after 5 hours of attempts last night
 

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
the feed mode will expire automatically (at least in my tank it does), but if you want to resume the normal schedule, just need to call function runSchedule() in the same format . It is in my sketch , just below the set feedmode.

@iamdan, I'm also an IT guy but not a coder for sure. You can send me the errors you're getting when compiling the MQTT sketch, we can try to troubleshoot what is happening together.

regards.
 

theatrus

Valuable Member
View Badges
Joined
Mar 26, 2016
Messages
2,223
Reaction score
3,632
Location
Sacramento, CA area
Rating - 0%
0   0   0
Started poking a bit at a Home Assistant command to set the scene, and noticed my Mobius devices have _two_ write characteristics.

0x01FF0103-BA5E-F4EE-5CA1-EB1E5E4B1CE0
And
0x01FF0104-BA5E-F4EE-5CA1-EB1E5E4B1CE0

I’m assuming the library is returning these sequentially and we are operating on the first one?
 

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
Started poking a bit at a Home Assistant command to set the scene, and noticed my Mobius devices have _two_ write characteristics.

0x01FF0103-BA5E-F4EE-5CA1-EB1E5E4B1CE0
And
0x01FF0104-BA5E-F4EE-5CA1-EB1E5E4B1CE0

I’m assuming the library is returning these sequentially and we are operating on the first one?
if you go back to @mard post here, it talks about the FF0104 UUID.

And looking here, the FF010x ids are related to wireless UART service.
 

BeanAnimal

5000 Club Member
View Badges
Joined
Jul 16, 2009
Messages
5,071
Reaction score
8,108
Rating - 0%
0   0   0
Breadboard still laying on desk. Not touched this in months. Maybe soon.
 

Simonv92

Active Member
View Badges
Joined
Oct 21, 2014
Messages
145
Reaction score
105
Location
Italy
Rating - 0%
0   0   0
@theatrus can you share with us which sketch are you running and how it is integrated in Home Assistant?
I was able to find a custom integration for Jebao Aqua App, I don't know why there isn't something similar for Ecotech Marine :downcast-face-with-sweat:

I was wondering if something like the MXM module from Apex can be integrated with Reef-Pi or any other system...
 
Last edited:

iamdan

Community Member
View Badges
Joined
Jul 1, 2022
Messages
87
Reaction score
74
Location
Western Australia
Rating - 0%
0   0   0
Here is the code that @Paulo Hanashiro and i have been fiddling with so far:

I am running this on an "ESP32 Dev Board" In Arduino IDE 2.3.2

Libraries are:
--ESP32-MobiusBLE
--ArduinoJson - v7.0.4
--ESPMQTTClient - v1.13.3
--FastLED - v3.7.0
--NimBLE-Arduino - v1.4.1
--PubSubClient - v2.8

Code:
/*!
 *
 * MQTT interface for Mobius BLE.
 *
 * HA mqtt auto discovery with a switch and a sensor.
 *  Switch is to set the Feed mode
 *  Sensor is to report the QTY of Mobius devices found by the scan feature
 *  it will intercept the switch to set feed mode and set the Normal schedule back
 *
 *  TO DO
 *    - Add interrupt GPIO pin to track ATO usage?
 *    - Add a physical button to set feed mode in the tank?
 *    - Add details of Mobius Devices?
 *         - Issues on Device Detail:
 *              - Device address changes from time to time
 *              - Unable to identify the device with current Mobius BLE library (i.e: Vortech pump, Nero Pump, AI Prime, Radion XX, etc.)
 *              - Mobius BLE library do not provide extensive Scene configuration (ATM only Feed Mode, Normal and Maintenance)
 *
 * This example code is released into the public domain.
 * Work in progress
 *
 */
#include <ESP32_MobiusBLE.h>
#include "ArduinoSerialDeviceEventListener.h"

#include "EspMQTTClient.h"
#include <string>
#include "secrets.h"
#include <ArduinoJson.h>

// Define the built-in LED pin if not already defined
#ifndef LED_BUILTIN
#define LED_BUILTIN 2
#endif

// Initialize the MQTT client with WiFi and MQTT broker details
EspMQTTClient client(
  mySSID,                // Your Wifi SSID
  myPassword,            // Your WiFi Password
  "192.168.1.203",       // MQTT Broker Server IP Address
  mqttUser,              // MQTT Username (Can be omitted if not needed)
  mqttPass,              // MQTT Password (Can be omitted if not needed)
  "Mobius",              // Client ID to uniquely identify your device
  1883                   // MQTT Broker Server Port
);

// JSON configuration for the MQTT discovery of the device
char *jsonDiscoveryDevice =  "{\
    \"name\":\"Feed Mode\",\
    \"command_topic\":\"homeassistant/switch/mobiusBridge/set\",\
    \"state_topic\":\"homeassistant/switch/mobiusBridge/state\",\
    \"unique_id\":\"mobius01ad\",\
    \"device\":{\
      \"identifiers\":[\
        \"mobridge01ad\"\
      ],\
      \"name\":\"Mobius\",\
      \"manufacturer\": \"Insert Name Here\",\
      \"model\": \"Mobius BLE Bridge\",\
      \"sw_version\": \"2024.6.0\"\
         }}";

// JSON configuration for the MQTT discovery of the quantity sensor
char *jsonDiscoveryDevice1 =  "{ \
    \"name\":\"QTY Devices\",\
    \"state_topic\":\"homeassistant/sensor/mobiusBridge/state\",\
    \"value_template\":\"{{ value_json.qtydevices}}\",\
    \"unique_id\":\"qtydev01ae\",\
    \"device\":{\
      \"identifiers\":[\
        \"mobridge01ad\"\
      ]\
      }\
    }";

// State variables
bool prevState = false;
bool currState = false;
bool configPublish = false;
bool firstRun = true;

// Callback when the MQTT connection is established
void onConnectionEstablished()
{
  Serial.println("Connected to MQTT Broker :)");
 
  // Listen for a scene update from mqtt and call the update function
  // May need to do this from the loop(). Test.
  client.subscribe("homeassistant/switch/mobiusBridge/set", [](const String& feedMode) {
    if (feedMode.length() > 0) {
      if (feedMode == "ON") {
        Serial.printf("INFO: IS this On?   %s\n", feedMode);
        currState = true;
        digitalWrite(LED_BUILTIN, HIGH);
      } else {
        Serial.printf("INFO: IS this Off?   %s\n", feedMode);
        currState = false;
        digitalWrite(LED_BUILTIN, LOW);
      }
      configPublish = false;

      Serial.printf("INFO: Update device scene from MQTT trigger: %s\n", feedMode);
    }
  });

}

// Define a device buffer to hold found Mobius devices
MobiusDevice deviceBuffer[20];
int deviceCount = 0;

JsonDocument doc;

void setup() {
  // connect the serial port for logs
  Serial.begin(115200);
  while (!Serial);

  pinMode(LED_BUILTIN, OUTPUT); // Set LED pin as output
  prevState = !currState;
  firstRun = true;

  client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overridded with enableHTTPWebUpdater("user", "password").
  client.setMaxPacketSize(2048); // Increase default packet size for Home Assistant MQTT json messages

  // Initialize the library with a useful event listener
  MobiusDevice::init(new ArduinoSerialDeviceEventListener());

  Serial.println("Setup run");
}

void loop() {
  // Wait for MQTT and WiFi Connection
  while(!client.isConnected()){client.loop();};

  // Loop MQTT
  client.loop();


  // Create buffer to store the Mobius devices
  MobiusDevice device = deviceBuffer[0];

  if (!configPublish) {
    //Scan BLE and MQTT Publish the main config only on boot or on status change
    Serial.printf("=========================================================\n");
    Serial.printf("     INFO: PUBLISHING THE MAIN CONFIG + BLE SCAN\n");
    Serial.printf("=========================================================\n");

    // Scan for Mobius devices
    int scanDuration = 15; // in seconds
    deviceCount = 0;

    while (!deviceCount) {
      // Scan until at least one device is returned
      deviceCount = MobiusDevice::scanForMobiusDevices(scanDuration, deviceBuffer,10);
      Serial.printf("INFO: Mobius Devices found: %i\n", deviceCount);
    }
    // Publish device discovery configurations
    if (!client.publish("homeassistant/switch/mobiusBridge/config", jsonDiscoveryDevice)) {  //This one is for the switch
      Serial.printf("ERROR: Did not publish");
    }

    if (!client.publish("homeassistant/sensor/mobiusBridge/config", jsonDiscoveryDevice1)) { //This is for the QTY
      Serial.printf("ERROR: Did not publish");
    }

    configPublish = true; // Configuration published
  }

  /***************************************************************
  ************       BLE Connection starts here       ************
  ***************************************************************/
  //inside the mqtt subscribe function onConnectionEstablished(), it will turn the LED on with digitalWrite(LED_BUILTIN, HIGH); using GPIO to proxy the Mobius Scene.

  bool currState = digitalRead(LED_BUILTIN); // Read current state of the LED

    if (prevState != currState) {
    //If Current state is different from previous, publish MQTT state
    Serial.printf("INFO: Publishing state");

    // Publish the current state of the LED
    if (currState) {
      //This is Feed Mode
      Serial.printf("INFO: LED is ON");
      if (!client.publish("homeassistant/switch/mobiusBridge/state", "ON")) {
        Serial.printf("ERROR: Did not publish LED on");
      }
    } else {
      //This is Normal Operation
      Serial.printf("INFO: LED is OFF");
      if (!client.publish("homeassistant/switch/mobiusBridge/state", "OFF")) {
        Serial.printf("ERROR: Did not publish LED off");
      }
    }

    if (!firstRun){
      // Do not connect to device during boot

      for (int i = 0; i < deviceCount; i++) {
        // Connect to each device in buffer to set the new scene
        device = deviceBuffer[i];

        int tries = 1;
        // Loop until connected or exit after 10 tries
        while(tries<=10){
          Serial.printf("\nINFO: Connect to device number: %i\n", i);
          if (device.connect()) {

            // Get Current scene
            uint16_t sceneId = device.getCurrentScene();

            // Convert scene from int to friendly MQTT text
            char currScene[2];
            sprintf(currScene, "%u", sceneId);
        
            // Delaying without sleeping
            unsigned long startMillis = millis();
            while (1000 > (millis() - startMillis)) {}

            /*===============================================
            =====               Set Scene               =====
            ===============================================*/
            if ((sceneId!=1) and (currState) ) {
              // Scene is different from Feed mode (1), and Feed switch is ON, set device to Feed mode
              device.setFeedScene();
            } else if ((sceneId==1) and !currState) {
              // Scene is Feed mode (1), and Feed switch is OFF, set device to Normal Schedule
              device.runSchedule();
            }

            //Disconnect from Mobius Device
            device.disconnect();

            //If connection completed, break the loop
            break;
          }
          else {
            tries++;
          }
        }

        //Print error message if didn't connect after 10 tries
        if (tries>9) {
          ESP_LOGE(LOG_TAG, "ERROR: Failed to connect to device");
        }
      }
    }

    // Create and publish JSON with device count
    char cstr[25];
    sprintf(cstr, "{\"qtydevices\": %d}", deviceCount);

    Serial.printf("INFO: Mobius BLE device count: %i\n", deviceCount);
 
      if (!client.publish("homeassistant/sensor/mobiusBridge/state", cstr)) {
        Serial.printf("ERROR: Did not publish qtyitems");
      }

    prevState = currState; // Update previous state
  }

  unsigned long currentMillis = millis();
  firstRun = false; // First run completed
}

It initially refused to compile, i went and had dinner, come back and ran the compile again as at the time forgot i already tried and it would compile.

I literally just reboot my pc and now i get the same compile error as Paulo does, anyone here have an idea as to why, spent hours and hours trying things to fix this to little effect:

Code:
In file included from C:\Users\Username\Documents\Arduino\libraries\FastLED\src/FastLED.h:79,
                 from C:\Users\Username\Documents\Arduino\libraries\ESP32_MobiusBLE\src\FastLEDDeviceEventListener.h:8,
                 from C:\Users\Username\Documents\Arduino\libraries\ESP32_MobiusBLE\src\FastLEDDeviceEventListener.cpp:5:
C:\Users\Username\Documents\Arduino\libraries\FastLED\src/fastspi.h:157:23: note: '#pragma message: No hardware SPI pins defined.  All SPI access will default to bitbanged output'
  157 | #      pragma message "No hardware SPI pins defined.  All SPI access will default to bitbanged output"
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp: In member function 'bool EspMQTTClient::handleWiFi()':
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:187:5: error: 'WiFi' was not declared in this scope
  187 |     WiFi.disconnect(true);
      |     ^~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:194:27: error: 'WiFi' was not declared in this scope
  194 |   bool isWifiConnected = (WiFi.status() == WL_CONNECTED);
      |                           ^~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:194:44: error: 'WL_CONNECTED' was not declared in this scope; did you mean 'MQTT_CONNECTED'?
  194 |   bool isWifiConnected = (WiFi.status() == WL_CONNECTED);
      |                                            ^~~~~~~~~~~~
      |                                            MQTT_CONNECTED
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:215:27: error: 'WL_CONNECT_FAILED' was not declared in this scope; did you mean 'MQTT_CONNECT_FAILED'?
  215 |       if(WiFi.status() == WL_CONNECT_FAILED || millis() - _lastWifiConnectiomAttemptMillis >= _wifiReconnectionAttemptDelay)
      |                           ^~~~~~~~~~~~~~~~~
      |                           MQTT_CONNECT_FAILED
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp: In member function 'bool EspMQTTClient::handleMQTT()':
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:325:9: error: 'WiFi' was not declared in this scope
  325 |         WiFi.disconnect(true);
      |         ^~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp: In member function 'void EspMQTTClient::onWiFiConnectionEstablished()':
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:362:75: error: 'WiFi' was not declared in this scope
  362 |       Serial.printf("WiFi: Connected (%fs), ip : %s \n", millis()/1000.0, WiFi.localIP().toString().c_str());
      |                                                                           ^~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp: In member function 'void EspMQTTClient::onWiFiConnectionLost()':
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:388:5: error: 'WiFi' was not declared in this scope
  388 |     WiFi.disconnect(true);
      |     ^~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp: In member function 'void EspMQTTClient::connectToWifi()':
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:555:3: error: 'WiFi' was not declared in this scope
  555 |   WiFi.mode(WIFI_STA);
      |   ^~~~
C:\Users\Username\Documents\Arduino\libraries\EspMQTTClient\src\EspMQTTClient.cpp:555:13: error: 'WIFI_STA' was not declared in this scope; did you mean 'WIFI_IF_STA'?
  555 |   WiFi.mode(WIFI_STA);
      |             ^~~~~~~~
      |             WIFI_IF_STA

exit status 1

Compilation error: exit status 1

I'm not concerned about the bitbang part as it and other sketches i have been trialling will compile regardless of that part.......just wiiiieeerddd

Anyways the compiled version thats still running then has issues with MQTT anyway:

Code:
23:31:30.139 -> INFO: Connect to device number: 1
23:31:30.139 -> Starting connection to the device
23:31:33.936 -> Successfully connected to the device
23:31:33.936 -> Successfully sent the request to the device
23:31:34.211 -> A notification was received from the device
23:31:35.294 -> INFO: Mobius BLE device count: 2
23:31:35.294 -> MQTT! publish failed, is the message too long ? (see setMaxPacketSize())
23:31:35.294 -> ERROR: Did not publish qtyitemsMQTT! Lost connection (87.197000s).
23:31:35.329 -> MQTT: Retrying to connect in 15 seconds.
23:31:50.346 -> MQTT: Connecting to broker "192.168.1.203" with client name "Mobius" and username "Daniel" ... (102.198000s) - ok. (102.208000s)
23:31:50.346 -> Connected to MQTT Broker :)
23:31:50.346 -> MQTT: Subscribed to [homeassistant/switch/mobiusBridge/set]
 
Last edited:

theatrus

Valuable Member
View Badges
Joined
Mar 26, 2016
Messages
2,223
Reaction score
3,632
Location
Sacramento, CA area
Rating - 0%
0   0   0
@theatrus can you share with us which sketch are you running and how it is integrated in Home Assistant?
I was able to find a custom integration for Jebao Aqua App, I don't know why there isn't something similar for Ecotech Marine :downcast-face-with-sweat:

I was wondering if something like the MXM module from Apex can be integrated with Reef-Pi or any other system...

I haven't tested anything with direct code - I was poking around how to do this with Home Assistant's built-in Bluetooth device support. It doesn't _look_ hard, but I've only done this as a scoping exercise and not anything real yet.

Home Assistant can use a variety of Bluetooth devices, including WiFi attached ESPHome devices configured as a Bluetooth proxy: https://esphome.io/components/bluetooth_proxy.html

The HA side integration would need to make sure to disconnect from each device after sending the scene set command in order to stay under the 3-connection limit.
 

iamdan

Community Member
View Badges
Joined
Jul 1, 2022
Messages
87
Reaction score
74
Location
Western Australia
Rating - 0%
0   0   0
Update on my shenanigans - Managed to get it to compile again - found on a github post for the Esp32MQTTClient library that v3.00 of the Expressif ESP32 Software breaks compatibility, Downgrading to v2.0.17 makes it compile again but still get the "MQTT! publish failed, is the message too long ? (see setMaxPacketSize())"
 

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
@theatrus can you share with us which sketch are you running and how it is integrated in Home Assistant?
I was able to find a custom integration for Jebao Aqua App, I don't know why there isn't something similar for Ecotech Marine :downcast-face-with-sweat:

I was wondering if something like the MXM module from Apex can be integrated with Reef-Pi or any other system...
Unsure of the capabilities of the MXM module, but @thetastate and I are working on something a little more complex to manage Mobius scenes in HA using mqtt messages. Still on early stages though....
 

theatrus

Valuable Member
View Badges
Joined
Mar 26, 2016
Messages
2,223
Reaction score
3,632
Location
Sacramento, CA area
Rating - 0%
0   0   0
Unsure of the capabilities of the MXM module, but @thetastate and I are working on something a little more complex to manage Mobius scenes in HA using mqtt messages. Still on early stages though....

My suggestion would be to invert this and just use the Bluetooth support directly in HA - its now hardware independent to whatever BLE end equipment you have (USB dongle, etc), if your goal is HA control over the Mobius scenes.
 

Paulo Hanashiro

Community Member
View Badges
Joined
Jun 4, 2013
Messages
56
Reaction score
29
Location
Sydney/Australia
Rating - 0%
0   0   0
My suggestion would be to invert this and just use the Bluetooth support directly in HA - its now hardware independent to whatever BLE end equipment you have (USB dongle, etc), if your goal is HA control over the Mobius scenes.
@theatrus , this would be much better indeed!

It was my initial plan, but found I don't have the skills to even start writing the basic python code, let alone the required HA API integration. :p
 

HAVE YOU EVER KEPT A RARE/UNCOMMON FISH, CORAL, OR INVERT? SHOW IT OFF IN THE THREAD!

  • Yes!

    Votes: 32 45.7%
  • Not yet, but I have one that I want to buy in mind!

    Votes: 9 12.9%
  • No.

    Votes: 26 37.1%
  • Other (please explain).

    Votes: 3 4.3%
Back
Top