Przesyłanie danych do SUPLI - urządzenie dystans

McGyver_lodz
Posty: 10
Rejestracja: wt gru 10, 2019 4:59 pm

Szukam pomocy.
Dodałem w SUPLI sensor dystans, , jak mam do niego dopisać zmienną, którą odczytuję z czujnika odległości. Miernik laserowy po I2C. Próbowałem przerobić przykład z hc-sr04, ale ni dy rydy 🙂
Ktoś coś ?
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

Musiałbyś zrobić nową klasę, która dziedziczy po Supla::Sensor::Distance i zaimplementować metody do pobierania danych z tego sensora. Możesz wzorować się na implementacji sensora hc sr04, tylko tam poza samym odczytem jest jeszcze zrobione uśrednianie kliku ostatnich pomiarów.
Widzimy się na Supla Offline Party vol. 2 :!:
McGyver_lodz
Posty: 10
Rejestracja: wt gru 10, 2019 4:59 pm

próbowałem ale nie wiem jak ze zmiennej którą odczytuję z lasera, wcisnąć w miejsce hcsra. Urządzenie w SUPLI już mam stworzone, tylko nie wiem jak przesłać do niego dane
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

Wstaw na forum kod całego programu (bez danych do logowania) z działającym odczytem do jakiejkolwiek zmiennej. Wieczorem przerobię go tak, aby działał
Widzimy się na Supla Offline Party vol. 2 :!:
McGyver_lodz
Posty: 10
Rejestracja: wt gru 10, 2019 4:59 pm

#include <SuplaDevice.h>
#include <supla/sensor/distance.h>
#include <Wire.h>
#include <VL53L0X.h>

VL53L0X sensor;

// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
// Arduino Mega with EthernetShield W5100:
#include <supla/network/ethernet_shield.h>
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Supla::EthernetShield ethernet(mac);

// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
// ESP8266 and ESP32 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("xxxxxl", "xxxxxx");
#endif

int dystans ;

void setup() {


Serial.begin(9600);
Wire.begin();


auto distance = new Supla::Sensor::Distance;


sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1) {}
}
sensor.startContinuous();


// Replace the falowing GUID with value that you can retrieve from https://www.supla.org/arduino/get-guid
char GUID[SUPLA_GUID_SIZE] = {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx};

// Replace the following AUTHKEY with value that you can retrieve from: https://www.supla.org/arduino/get-authkey
char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxxxxxxxxxxxxxxxxxxxxxxxxx};



SuplaDevice.begin(GUID, // Global Unique Identifier
"xxxxxxxxxxx", // SUPLA server address
"xxxxxxxxxxxxxxxxx", // Email address used to login to Supla Cloud
AUTHKEY); // Authorization key
}

void loop() {

dystans =sensor.readRangeSingleMillimeters();
Serial.print(sensor.readRangeSingleMillimeters());
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }

Serial.println();
delay(1000);
SuplaDevice.iterate();
}
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

Tak to mniej więcej może wyglądać.
Kilka rzeczy zrobiłbym inaczej, ale to chwilę więcej czasu by zajęło ;).
Ale przy jednym sensorze powinno wszystko działać.

Kod: Zaznacz cały

#include <SuplaDevice.h>
#include <VL53L0X.h>
#include <Wire.h>
#include <supla/sensor/distance.h>

// Choose proper network interface for your card:
#ifdef ARDUINO_ARCH_AVR
// Arduino Mega with EthernetShield W5100:
#include <supla/network/ethernet_shield.h>
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
Supla::EthernetShield ethernet(mac);

// Arduino Mega with ENC28J60:
// #include <supla/network/ENC28J60.h>
// Supla::ENC28J60 ethernet(mac);
#elif defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
// ESP8266 and ESP32 based board:
#include <supla/network/esp_wifi.h>
Supla::ESPWifi wifi("xxxxxl", "xxxxxx");
#endif

class VL53L0XDSensor : public Supla::Sensor::Distance {
public:
  void onInit() {
    Wire.begin();
    sensor.setTimeout(500);
    if (!sensor.init()) {
      Serial.println("Failed to detect and initialize sensor!");
      while (1) {
      }
    }
    sensor.startContinuous();
  }

  double getValue() { 
    return 0.001 * sensor.readRangeSingleMillimeters(); 
  }

  /*
  // aktualnie klasa Distance robi odczyt co 100 ms, jeśli to za szybko, to
  // odkomentuj tą metodę i zmień "100" na inną wartość.
  void iterateAlways() {
    if (lastReadTime + 100 < millis()) {
      lastReadTime = millis();
      channel.setNewValue(getValue());
    }
  }
  */

  VL53L0X sensor;
};

void setup() {
  Serial.begin(9600);
  auto distance = new VL53L0XDSensor;

  // Replace the falowing GUID with value that you can retrieve from
  // https://www.supla.org/arduino/get-guid
  char GUID[SUPLA_GUID_SIZE] = {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx};

  // Replace the following AUTHKEY with value that you can retrieve from:
  // https://www.supla.org/arduino/get-authkey
  char AUTHKEY[SUPLA_AUTHKEY_SIZE] = {xxxxxxxxxxxxxxxxxxxxxxxxxx};

  SuplaDevice.begin(
      GUID,                // Global Unique Identifier
      "xxxxxxxxxxx",       // SUPLA server address
      "xxxxxxxxxxxxxxxxx", // Email address used to login to Supla Cloud
      AUTHKEY);            // Authorization key
}

void loop() { 
  SuplaDevice.iterate(); 
}
Widzimy się na Supla Offline Party vol. 2 :!:
McGyver_lodz
Posty: 10
Rejestracja: wt gru 10, 2019 4:59 pm

Super działa, gdzie mam dostarczyć piwko ? chyba że będziesz w Łodzi to stawiam
Awatar użytkownika
klew
Posty: 8184
Rejestracja: czw cze 27, 2019 12:16 pm
Lokalizacja: Wrocław

McGyver_lodz pisze: sob cze 19, 2021 9:26 pm Super działa, gdzie mam dostarczyć piwko ? chyba że będziesz w Łodzi to stawiam
Dzięki, nie trzeba :)
Widzimy się na Supla Offline Party vol. 2 :!:
vijay2
Posty: 31
Rejestracja: sob mar 09, 2019 5:54 pm

Witam, mam z aliexpress jedną sztukę VL53L0X chciałem testowo uruchomić ale nie rusza /:
Czy dobrze to podłączyłem? Możliwe, że jest uszkodzony? Albo, że go przegrzałem jak lutowałem piny?
IMG_20220226_210807.jpg
IMG_20220226_210807.jpg (431.86 KiB) Przejrzano 416 razy
Po którymś restarcie zaczął działać :)

Czy macie rozpracowany jakiś typowy czujnik ruchu?
ODPOWIEDZ

Wróć do „Pomoc”