Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×
ianbren

Connecting Fibaro HC2 to an ESP8266 - two tutorials

Recommended Posts

Hi,

 

I am a newbie, so I do not know how to handle your hint.

This is what browser shows.... 

Please login or register to see this attachment.

Share this post


Link to post
Share on other sites

ok. 

let's first provide your code here

Share this post


Link to post
Share on other sites

Started to create simple VD... just to get json

Please login or register to see this attachment.

local thisdevice = fibaro:getSelfId() 

-- the next line uses the VD information on the ESP8266 
-- to create a HTTP connection object 

local conn = Net.FHttp(fibaro:getValue(thisdevice, 'IPAddress'), fibaro:getValue(thisdevice, 'TCPPort')) 

-- if there's a path name, then put it in the GET() method. 

response, status, errorCode = conn:GET('/json:') 

-- "response"  will hold the JSON coming back 

if response == nil then 
  fibaro:debug('response  = nil ')
elseif response ~= nil then
  fibaro:debug('response  ' .. response)
end
fibaro:debug('status  ' .. status)
fibaro:debug('errorCode   ' .. errorCode)

-- good practice 

fibaro:sleep(1) 

if errorCode == 0 then 
    -- so , you got something back ok 
    -- the Status is not really needed, unless you're going to deal with non-200 HTTP Status codes 

    -- Example processing JSON 

  -- fibaro:debug ("Try to get table")
  jsonTable = json.decode(response) 
  
  --fibaro:debug (json.encode(response))
    
  -- there are three elements that come back in the "101" sample ESP8266 code

  --fibaro:call(thisdevice, "setProperty", "ui.Label1.value", jsonTable.w_temperature)
  --fibaro:call(thisdevice, "setProperty", "ui.Label2.value", jsonTable.Data2) 
  --fibaro:call(thisdevice, "setProperty", "ui.Label3.value", jsonTable.myText) 
else 

    -- so we had a non-zero error code - something went wrong

  fibaro:debug("Error: Code  " .. errorCode) 

end 

Share this post


Link to post
Share on other sites

so, it's VD

 

AFAIK(R) custom headers available... only in scenes, not virtual devices.

Share this post


Link to post
Share on other sites

hmm... do you have an example how to  get json be a scene?

Share this post


Link to post
Share on other sites

I do not find solution how to send http://192.168.1.1/control?cmd=GPIO,12,1 command to esp8266 with Espeasy. I create virtual switch on hc2 and tryng send this but without luck.

Share this post


Link to post
Share on other sites
On 9/20/2017 at 1:23 PM, 10der said:

JFYI:

 

1) ESP8266 Serial ESP-12F Wi-Fi Witty Cloud Development Board + DHT22

Please login or register to see this spoiler.

Hi 10der@,

 

Coole script!
i have qestion, can i take multiple sensors on the same board(total 3), and youse it on fibaro as a different sensors for different rooms?

 

Best regards

Share this post


Link to post
Share on other sites
1 minute ago, Gravity said:

i have qestion, can i take multiple sensors on the same board(total 3), and youse it on fibaro as a different sensors for different rooms?

 

not clear for me... why not? :)

but, one notice VD is not Z-wave device and you can't use it as default sensor in Fibaro  UI, etc

Share this post


Link to post
Share on other sites

Thanks for so fast answer!

I am not so good with coding and use mostly copy, paste function.;)

Sensors will be used in basements in different rooms to monitor temperature, and humidity, and start scens.  I guess in

Please login or register to see this attachment.

need to change

// Connect DHT
DHT dht(D1, DHT22);

DHT dht?(D0, DHT22)

DHT dht?(D5,DHT22)

but what i need to change in VD to know a value from different sensors because is on a same ip adress?

 

Thanks..

Share this post


Link to post
Share on other sites
43 minutes ago, Gravity said:

but what i need to change in VD to know a value from different sensors because is on a same ip adress?

 

first. i still not clear understand you =)

 

1) (let) I have 5 (five) DHT sensors on my Arduino

2) (let) this Arduino is ESP8266. Otherwise, you should connect Arduino via  0/1 pin to ESP to 1/0 pin as COM

3) on ESP create Web Service. (let) for example, Arduino have 192.168.1.77 address and WebServer port is 80

4) code Arduino www handler and endpoint /sensor and /1 /2 /3 /4 /5 - endpoints for DHT sensors data

5) VD in HC2: 

 

Please login or register to see this code.

Please login or register to see this code.

 

NB: the provided code I was wrote here in this forum html editor. so, it can don't works :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×