hc-sr04

qba93
Posts: 138
Joined: Thu Apr 18, 2019 10:09 pm

Post

hej mam czujnik HC-SR04 i płytkę NodeMCU i czy ktoś ma gotowy firmware żeby to sprzęgnąć z suplą? Znalazłem na forum jeden, niby wgrałem przez arduino ale coś nie działa.Pokazuje sieć w wifi esp... ale nie wiem niby łączy ale w konfiguracje wejść nie mogę po przez ip 192.168.4.1. Poniżej daje kod do arduino może coś nie teges w kodzie jest.W supla cloud mam włączoną rejestracje urządzeń jak coś.

Code: Select all

/**
 * Supla.org NodeMCU WiFi minimal example
 * Author: Programistyk - Kamil Kaminski <[email protected]>
 * 
 * This example shows how to configure SuplaDevice for building for NodeMCU within Arduino IDE
 */
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>

#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>

WiFiClient client;

// Setup Supla connection
const char* ssid     = "vodafone"; // Tu wpisz nazwę  swojej sieci WiFi
const char* password = "xx"; // Tu wpisz hasło sowjej sieci WiFi


 int Trig = 5;   // Numer pinu wyzwolenia
 int Echo = 4;   // Numer pinu odpowiedzi
 long EchoTime;  // Czas trwania sygnału ECHO

double get_distance(int channelNumber, double distance) {
   
   // Ustawiamy TRIG w stan niski na 2us
  digitalWrite(Trig, LOW);
  delayMicroseconds(2);
 
  // Ustawiamy TRIG w stan wysoki na 10us
  digitalWrite(Trig, HIGH);
  delayMicroseconds(10);
 
  // Ustawiamy TRIG w stan niski - rozpoczynamy pomiar
  digitalWrite(Trig, LOW);
 
  // Odczytujamy czas trwania stanu wysokiego na pinie ECHO
  EchoTime = pulseIn(Echo, HIGH);
 
  // Obliczamy odległość
  distance = EchoTime / 58; // Odległość w metrach
  distance = distance / 100;// Odległość w centymetrach
  Serial.println(distance); 
   return  distance;
}
   
void setup() {

  pinMode(Trig, OUTPUT);
  pinMode(Echo, INPUT);
  
  Serial.begin(115200);
  delay(10);

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

  // Ethernet MAC address
  uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

  /*
   * Having your device already registered at cloud.supla.org,
   * you want to change CHANNEL sequence or remove any of them,
   * then you must also remove the device itself from cloud.supla.org.
   * Otherwise you will get "Channel conflict!" error.
   */

 

 SuplaDevice.addDistanceSensor();
  SuplaDevice.addRelay(2);     

  SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "xxx",  // SUPLA server address
                    xx,                 // tu wpisz swój Location ID 
                    "xx");               // tu wpisz swoje Location Password

} //setup




void loop() {
  SuplaDevice.iterate();
}

// Supla.org ethernet layer
    int supla_arduino_tcp_read(void *buf, int count) {
        _supla_int_t size = client.available();
       
        if ( size > 0 ) {
            if ( size > count ) size = count;
            return client.read((uint8_t *)buf, size);
        };
    
        return -1;
    };
    
    int supla_arduino_tcp_write(void *buf, int count) {
        return client.write((const uint8_t *)buf, count);
    };
    
    bool supla_arduino_svr_connect(const char *server, int port) {
          return client.connect(server, 2015);
    }
    
    bool supla_arduino_svr_connected(void) {
          return client.connected();
    }
    
    void supla_arduino_svr_disconnect(void) {
         client.stop();
    }
    
    void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {

       // Serial.println("WiFi init");
        WiFi.begin(ssid, password);

        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
        //    Serial.print(".");
        }

        //Serial.print("\nlocalIP: ");
        //Serial.println(WiFi.localIP());
        //Serial.print("subnetMask: ");
        //Serial.println(WiFi.subnetMask());
        //Serial.print("gatewayIP: ");
        //Serial.println(WiFi.gatewayIP());
    }

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
          SuplaDeviceCallbacks cb;
          
          cb.tcp_read = &supla_arduino_tcp_read;
          cb.tcp_write = &supla_arduino_tcp_write;
          cb.eth_setup = &supla_arduino_eth_setup;
          cb.svr_connected = &supla_arduino_svr_connected;
          cb.svr_connect = &supla_arduino_svr_connect;
          cb.svr_disconnect = &supla_arduino_svr_disconnect;
          cb.get_temperature = NULL;
          cb.get_temperature_and_humidity = NULL ;
          cb.get_rgbw_value = NULL;
          cb.set_rgbw_value = NULL;
          cb.get_distance = &get_distance;
          return cb;
}
PS.Mam też mini wemos jak MCU nie zadziała z tym czy jest nie kompatybilne
User avatar
wojtas567
Posts: 2334
Joined: Sun Apr 03, 2016 7:16 pm
Location: Olsztyn

Post

Ten soft nie ma koknfiguratora.
Musisz wpisać dane do własnej sieci wifi, zmienić GUID (bo są same zera) i poniżej wpisać dane do logowania do chmury.
I dopiero wtedy wgraj ten soft.
Pozdrawiam
Wojtek
qba93
Posts: 138
Joined: Thu Apr 18, 2019 10:09 pm

Post

Code: Select all

//Setup Supla connection
const char* ssid     = "vodafone"; // Tu wpisz nazwę  swojej sieci WiFi
const char* password = "xx"; // Tu wpisz hasło sowjej sieci WiFi
tak, tak właśnie to mam w tym kodzie uzupełnione tu na forum tylko zamazałem i kiszka, nie dziala
teraz zauważyłem, że tam jest // może to ma wpływ i nie działa
User avatar
makrz
Posts: 401
Joined: Tue Nov 27, 2018 1:43 pm
Location: Opole

Post

A czy to masz zmienione?

Code: Select all

SuplaDevice.begin(GUID,              // Global Unique Identifier 
                    mac,               // Ethernet MAC address
                    "xxx",  // SUPLA server address
                    xx,                 // tu wpisz swój Location ID 
                    "xx");               // tu wpisz swoje Location Password
i to?

Code: Select all

char GUID[SUPLA_GUID_SIZE] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    // with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
qba93
Posts: 138
Joined: Thu Apr 18, 2019 10:09 pm

Post

To pierwsze tak a ten drugi kod co to jest nie rozumiem co zmienic musze?
User avatar
Robert Błaszczak
Posts: 5222
Joined: Sat Dec 22, 2018 8:55 pm
Location: Zielona Góra
Has thanked: 37 times
Been thanked: 27 times

Post

Wygeneruj GUID na podanej stronie https://www.supla.org/arduino/get-guid i wklej go w miejsce 0x00...
Pozdrawiam
Robert Błaszczak


Moja prywatna strona: www.blaszczak.pl
qba93
Posts: 138
Joined: Thu Apr 18, 2019 10:09 pm

Post

hmmm cos takiego wyskakuje mi ...
unable to find numeric literal operator 'operator"" x'
User avatar
Robert Błaszczak
Posts: 5222
Joined: Sat Dec 22, 2018 8:55 pm
Location: Zielona Góra
Has thanked: 37 times
Been thanked: 27 times

Post

Gdzie Ci taki komunikat wyskakuje?
Pozdrawiam
Robert Błaszczak


Moja prywatna strona: www.blaszczak.pl
qba93
Posts: 138
Joined: Thu Apr 18, 2019 10:09 pm

Post

W ardiuno podczas wgrywania
User avatar
Robert Błaszczak
Posts: 5222
Joined: Sat Dec 22, 2018 8:55 pm
Location: Zielona Góra
Has thanked: 37 times
Been thanked: 27 times

Post

Sprawdź, czy nie masz podwójnych lub braku nawiasów klamrowych.
Pozdrawiam
Robert Błaszczak


Moja prywatna strona: www.blaszczak.pl

Return to “Pomoc”