Using curl/http to read a value of a ds18b20

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
hvdwolf
Normal user
Posts: 51
Joined: 09 Jun 2016, 12:37

Using curl/http to read a value of a ds18b20

#1 Post by hvdwolf » 20 Jan 2020, 16:16

Hi,

I have a ds18b20 on my Nodemcu on GPIO pin 2 to read the temperature and a relais on pin 15 to switch the heating on/off. The Esp Easy "website" simply shows me the right temperature.

I want to read/set the values from my linux server as well.
For reading the status of the on/off GPIO pin 2, I simply use something like:

Code: Select all

curl --silent --data 'cmd=status,gpio,15' http://192.168.178.241/control | grep state | awk {'print $2'}
for setting to On/high I use:

Code: Select all

curl --silent --data 'cmd=gpio,15,1' http://192.168.178.241/control
and for setting it to Off/Low I use:

Code: Select all

curl --silent --data 'cmd=gpio,15,0' http://192.168.178.241/control

But how do I read the value of the temperature of my ds18b20?
If I use the same command

Code: Select all

curl --silent --data 'cmd=status,gpio,2' http://192.168.178.241/control
on the GPIO pin 2 where my ds18b20 is connected I get something like:

Code: Select all

{
"log": "",
"plugin": 1,
"pin": 2,
"mode": "output",
"state": 0
}
I can't find it in the cmd (command reference) wiki page.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Using curl/http to read a value of a ds18b20

#2 Post by grovkillen » 20 Jan 2020, 16:24

Use the json endpoint?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

hvdwolf
Normal user
Posts: 51
Joined: 09 Jun 2016, 12:37

Re: Using curl/http to read a value of a ds18b20

#3 Post by hvdwolf » 20 Jan 2020, 19:58

grovkillen wrote: 20 Jan 2020, 16:24 Use the json endpoint?
Thanks for pointing me to the json endpoint. I searched in the forum and found references to javascript code, but I can't completely reproduce it for curl/script use.

Using curl I do

Code: Select all

curl --silent  http://192.168.178.246/json

{"System":{
"Build": 147,
"Unit": 0,
"Uptime": 29005,
"Free RAM": 26472
},
"Sensors":[
{
"TaskName": "woonkamertemperatuur",
"woonkamertemperatuur": 20.37
},
{
"TaskName": "Uptime",
"woonkamer-uptime": 29005.00
}
]}
This gives me the complete json array back which I can parse using search and substring functions.
But is there a way to immediately access the temperature (in this case 20.37).
Like said: Trying options like the javascript examples doesn't give me the value.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Using curl/http to read a value of a ds18b20

#4 Post by grovkillen » 20 Jan 2020, 21:35

http://192.168.178.246/json?tasknr=1

Will filter the json.

See more URL filters here: https://github.com/letscontrolit/ESPEas ... ON.ino#L12

PS. By the looks of your json string it seems to me you're running an old version?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

hvdwolf
Normal user
Posts: 51
Joined: 09 Jun 2016, 12:37

Re: Using curl/http to read a value of a ds18b20

#5 Post by hvdwolf » 20 Jan 2020, 22:49

Thanks a lot.

Yes, I'm still running the r147 version with a minor patch of my own.
Those nodemcus with this version are so extremely stable that I never upgraded. I have 3 of them which keep on running without issues.
But I will now take a look at the new versions as I now wanted to change some things in my config.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Using curl/http to read a value of a ds18b20

#6 Post by grovkillen » 20 Jan 2020, 22:58

The latest are really stable but be aware the that the config isn't compatible with the R147 version so make sure you take the settings some other way (screenshots or notes).
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Post Reply

Who is online

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