how use domoticz username and password in esp8266 wifi module use arduino IDE? Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by reza »

Hi guys
i read this wiki page (https://www.domoticz.com/wiki/ESP8266_WiFi_module) and i want know how put the domoticz username and password for login in this code ?

Code: Select all

#include <Wire.h>
#include <SparkFun_Si7021_Breakout_Library.h> //https://github.com/sparkfun/Si7021_Breakout/blob/master/Libraries/Arduino/Si7021/src/SparkFun_Si7021_Breakout_Library.h
#include <ESP8266WiFi.h>

// int status = WL_IDLE_STATUS;     // the Wifi radio's status
WiFiClient client;

// domoticz
 const char * domoticz_server = "192.168.1.10"; //Domoticz port
 int port = 8080; //Domoticz port
 int idx = 5; //IDX for this virtual sensor, found in Setup -> Devices

 float humidity = 0;
 float temp = 0;
  
 // Create Instance of HTU21D or SI7021 temp and humidity sensor and MPL3115A2 barrometric sensor
 Weather sensor;
  
 void setup()
 {
     // Initialize the I2C sensors and ping them
     sensor.begin();
 }

 void loop()
 {
    // Get readings from all sensors
    getWeather();
    printInfo();
    delay(60000); // Wait 60 seconds
 }

 void getWeather()
 {
    // Measure Relative Humidity from the HTU21D or Si7021
    humidity = sensor.getRH();
    // Measure Temperature from the HTU21D or Si7021
    temp = sensor.getTemp();
    // Temperature is measured every time RH is requested. It is faster, therefore, to read it from previous RH measurement with getTemp() instead with readTemp()
 }
   
 void printInfo()
 {
    // Domoticz format /json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT

    if (client.connect(domoticz_server,port)) {

        client.print("GET /json.htm?type=command&param=udevice&idx=");
        client.print(idx);
        client.print("&nvalue=0&svalue=");
        client.print(temp);
        client.print(";");
        client.print(humidity);
        client.print(";0"); //Value for HUM_STAT. Can be one of: 0=Normal, 1=Comfortable, 2=Dry, 3=Wet
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.print(domoticz_server);
        client.print(":");
        client.println(port);
        client.println("User-Agent: Arduino-ethernet");
        client.println("Connection: close");
        client.println();
        
        client.stop();
     }
  }
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by Kedi »

Logic will get you from A to B. Imagination will take you everywhere.
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by reza »

Kedi wrote: Sunday 28 July 2024 8:02 It is all here: https://www.domoticz.com/wiki/Security
thank you for answer
i see it and i know about username and password and the format "https://username:password@IP:PORT/json.htm..."
but i dont know how set this format to a arduino code. where put user and password in the code with what command ?
for example this code is true?

Code: Select all

        
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.print(username);
        client.print(":");
        client.print(password);
        client.print("@");
        client.print(domoticz_server);
        client.print(":");
        client.println(port);
        client.println("User-Agent: Arduino-ethernet");
        client.println("Connection: close");
        client.println();
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by Kedi »

I don't think that will work, I think it should go in the authentication header.
I always post my data to a MQTT server like mosquitto.
This way I can use the posted data multiple ways and all arduino ESP8266 and ESP32 are centralized on the MQTT server.
This is a good guide https://randomnerdtutorials.com/esp8266 ... t-arduino/
Instead of the Node-Red example you could use the domoticz settings

And I always post 'raw' data to MQTT and process it with Node-Red towards Domoticz, this way I can add data like uptime, LWT and RSSI (and others) to the message and can process or view those.

And if you want to use client.println then

Code: Select all

client.println("Authorization: Basic YWRtaW46YXJkdWlubwo=");
The characters after "Basic" in that line are the base64 encoded username and password in the format "username:password".
Logic will get you from A to B. Imagination will take you everywhere.
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by reza »

Kedi wrote: Monday 29 July 2024 8:06 And if you want to use client.println then

Code: Select all

client.println("Authorization: Basic YWRtaW46YXJkdWlubwo=");
The characters after "Basic" in that line are the base64 encoded username and password in the format "username:password".
thank you. Where is my authorization?

This is true?

Code: Select all

client.println("Authorization: Basic YWRtaW46YXJkdWlubwo=username:password");
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by Kedi »

Go to this webiste: https://www.base64encode.org/
put username and password in the form of username:password in the first box
Then click encode
Copy the result in place of the YWRtaW46YXJkdWlubwo=
Logic will get you from A to B. Imagination will take you everywhere.
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by reza »

Kedi wrote: Monday 29 July 2024 15:07 Go to this webiste: https://www.base64encode.org/
put username and password in the form of username:password in the first box
Then click encode
Copy the result in place of the YWRtaW46YXJkdWlubwo=
Oh thank you . But more one qustion.
Now this line... put where this code ? After which line?

Code: Select all

    
    if (client.connect(domoticz_server,port)) {
        client.print("GET/json.htmtype=command&param=udevce&idx=");
        client.print(idx);
        client.print("&nvalue=0&svalue=");
        client.print(temp);
        client.print(";");
        client.print(humidity);
        client.print(";0"); //Value for HUM_STAT. Can be one of: 0=Normal, 1=Comfortable, 2=Dry, 3=Wet
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.print(domoticz_server);
        client.print(":");
        client.println(port);
        client.println("User-Agent: Arduino-ethernet");
        client.println("Connection: close");
        client.println();
        
        client.stop();
     }
  }
  
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by jvdz »

Have a look in this function for the espcam project we made:
https://github.com/Hoeby/ESP32-Doorbell ... z.cpp#L167

It shows how to add the header with the authentication info.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Kedi
Posts: 536
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by Kedi »

reza wrote: Monday 29 July 2024 23:28
Kedi wrote: Monday 29 July 2024 15:07 Go to this webiste: https://www.base64encode.org/
put username and password in the form of username:password in the first box
Then click encode
Copy the result in place of the YWRtaW46YXJkdWlubwo=
Oh thank you . But more one qustion.
Now this line... put where this code ? After which line?

Code: Select all

    
    if (client.connect(domoticz_server,port)) {
        client.print("GET/json.htmtype=command&param=udevce&idx=");
        client.print(idx);
        client.print("&nvalue=0&svalue=");
        client.print(temp);
        client.print(";");
        client.print(humidity);
        client.print(";0"); //Value for HUM_STAT. Can be one of: 0=Normal, 1=Comfortable, 2=Dry, 3=Wet
        client.println(" HTTP/1.1");
        client.print("Host: ");
        client.print(domoticz_server);
        client.print(":");
        client.println(port);
        client.println("User-Agent: Arduino-ethernet");
        client.println("Connection: close");
        client.println();
        
        client.stop();
     }
  }
  
Before or after the User-Agent line, because it is header information.

@jvdz Your link does not work. This should be the same: https://github.com/Hoeby/ESP32-Doorbell ... moticz.cpp
Base64 coding is here done in the source.
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by jvdz »

Kedi wrote: Tuesday 30 July 2024 10:28 @jvdz Your link does not work.
Ah right... That repo is in private mode.. fixed the link to the public version.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
reza
Posts: 112
Joined: Tuesday 13 September 2016 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Contact:

Re: how use domoticz username and password in esp8266 wifi module use arduino IDE?

Post by reza »

Before or after the User-Agent line, because it is header information
Thank you dear 🙏
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest