ESP8266+DS18B20 | ESP Wi-Fi | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.
Avatar

Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
ESP8266+DS18B20
No permission to create posts
September 13, 2015
4:03 pm
Avatar
kniazio

Silver
Members
Forum Posts: 19
Member Since:
September 13, 2015
sp_UserOfflineSmall Offline

Does not update the temperature thingspeak.

ESPlorer code:

Communication with MCU...
Got answer! AutoDetect firmware...

NodeMCU firmware detected.
=node.heap()

stdin:2: unexpected symbol near '='
> Last temp: 257500
Temp:25.7500 C

Sending data to thingspeak.com
Closing connection
Got disconnection...
Last temp: 252500
Temp:25.2500 C

Sending data to thingspeak.com
Closing connection
Got disconnection...

my configuration:

init.lua

--init.lua
print("Setting up WIFI...")
wifi.setmode(wifi.STATION)
--modify according your wireless router settings
wifi.sta.config("my-ssid","my-password")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("ds1820.lua")
end
end)

ds1820.lua

-- Measure temperature and post data to thingspeak.com
-- 2014 OK1CDJ
--- Tem sensor DS18B20 is conntected to GPIO0
--- 2015.01.21 sza2 temperature value concatenation bug correction

pin = 3
ow.setup(pin)

counter=0
lasttemp=-999

function bxor(a,b)
local r = 0
for i = 0, 31 do
if ( a % 2 + b % 2 == 1 ) then
r = r + 2^i
end
a = a / 2
b = b / 2
end
return r
end

--- Get temperature from DS18B20
function getTemp()
addr = ow.reset_search(pin)
repeat
tmr.wdclr()

if (addr ~= nil) then
crc = ow.crc8(string.sub(addr,1,7))
if (crc == addr:byte(8)) then
if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
ow.reset(pin)
ow.select(pin, addr)
ow.write(pin, 0x44, 1)
tmr.delay(1000000)
present = ow.reset(pin)
ow.select(pin, addr)
ow.write(pin,0xBE, 1)
data = nil
data = string.char(ow.read(pin))
for i = 1, 8 do
data = data .. string.char(ow.read(pin))
end
crc = ow.crc8(string.sub(data,1,8))
if (crc == data:byte(9)) then
t = (data:byte(1) + data:byte(2) * 256)
if (t > 32768) then
t = (bxor(t, 0xffff)) + 1
t = (-1) * t
end
t = t * 625
lasttemp = t
print("Last temp: " .. lasttemp)
end
tmr.wdclr()
end
end
end
addr = ow.search(pin)
until(addr == nil)
end

--- Get temp and send data to thingspeak.com
function sendData()
getTemp()
t1 = lasttemp / 10000
t2 = (lasttemp >= 0 and lasttemp % 10000) or (10000 - lasttemp % 10000)
print("Temp:"..t1 .. "."..string.format("%04d", t2).." C
")
-- conection to thingspeak.com
print("Sending data to thingspeak.com")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
-- api.thingspeak.com 184.106.153.149
conn:connect(80,'184.106.153.149')
conn:send("GET /update?key=MYAPIKEY&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1
")
conn:send("Host: api.thingspeak.com
")
conn:send("Accept: */*
")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
")
conn:send("
")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)
end

-- send data every X ms to thing speak
tmr.alarm(0, 60000, 1, function() sendData() end )

Please Help Me

September 14, 2015
9:02 am
Avatar
hans

MathWorks
Members
Forum Posts: 4
Member Since:
January 19, 2011
sp_UserOfflineSmall Offline

kniazio,

In the following line:

conn:send("GET /update?key=MYAPIKEY&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1

I want to confirm that have you replaced 'MYAPIKEY' with the destination Channel's API Key?

September 14, 2015
10:44 am
Avatar
kniazio

Silver
Members
Forum Posts: 19
Member Since:
September 13, 2015
sp_UserOfflineSmall Offline

jklol said

kniazio,

In the following line:

conn:send("GET /update?key=MYAPIKEY&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1

I want to confirm that have you replaced 'MYAPIKEY' with the destination Channel's API Key?

I do not really understand.
I typed Write your API Key
Where do I find another API Key

September 14, 2015
11:35 am
Avatar
hans

MathWorks
Members
Forum Posts: 4
Member Since:
January 19, 2011
sp_UserOfflineSmall Offline

kniazio,

From the ThingSpeak Documentation (https://thingspeak.com/docs/channels#api_keys):

Write API Key

Use the Write API Key to update a channel. If your Write API Key is compromised you can generate a new key. If you use MATLAB® Analysis or MATLAB® Visualization, the API info is displayed in the right pane of the app.

To find your Write API Key:
•Click Channels > My Channels.
•Select the channel to update.
•Select API Keys tab.

Read API Key
The Read API Key enables your application to read data from the API. You can generate multiple Read API Keys for different applications.
To get a Read API Key:
•Click Channels > My Channels.
•Select the channel to update
•Select API Keys tab.
•Click Generate New Read API Key.

For example, if I had the channel 123

I would find the Channel's read/write api keys at the following page (after signing in)
https://thingspeak.com/channels/123/api_keys

September 14, 2015
1:03 pm
Avatar
kniazio

Silver
Members
Forum Posts: 19
Member Since:
September 13, 2015
sp_UserOfflineSmall Offline

jklol said

kniazio,

From the ThingSpeak Documentation (https://thingspeak.com/docs/channels#api_keys):

Write API Key

Use the Write API Key to update a channel. If your Write API Key is compromised you can generate a new key. If you use MATLAB® Analysis or MATLAB® Visualization, the API info is displayed in the right pane of the app.

To find your Write API Key:
•Click Channels > My Channels.
•Select the channel to update.
•Select API Keys tab.

Read API Key
The Read API Key enables your application to read data from the API. You can generate multiple Read API Keys for different applications.
To get a Read API Key:
•Click Channels > My Channels.
•Select the channel to update
•Select API Keys tab.
•Click Generate New Read API Key.

For example, if I had the channel 123

I would find the Channel's read/write api keys at the following page (after signing in)
https://thingspeak.com/channels/123/api_keys

I do not want to only read information from and write information urzaądzenia esp8266
I wrote it in the first post
My device sends temperature readings
-- api.thingspeak.com 184.106.153.149
conn:connect(80,'184.106.153.149')
conn:send("GET /update?key=ID9D358UQUxxxxxx&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1
")
conn:send("Host: api.thingspeak.com
")
conn:send("Accept: */*
")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)
")
conn:send("
")
The device esp8266 log I see:
Communication with MCU...
Got answer! AutoDetect firmware...

NodeMCU firmware detected.
=node.heap()

stdin:2: unexpected symbol near '='
> Last temp: 257500
Temp:25.7500 C

Sending data to thingspeak.com
Closing connection
Got disconnection...
Last temp: 252500
Temp:25.2500 C

Sending data to thingspeak.com
Closing connection
Got disconnection...

So like device sends data to thingspeak

But on the side of the chanell do not see changes

September 14, 2015
1:12 pm
Avatar
kniazio

Silver
Members
Forum Posts: 19
Member Since:
September 13, 2015
sp_UserOfflineSmall Offline

Ok otherwise.
My write API Key is
ID9D358UQURTFIMU
My chanell ID is 55753
How will this line with me:
conn:send("GET /update?key=ID9D358UQURTFIMU&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1
")

September 14, 2015
2:34 pm
Avatar
Michel_J

Silver
Members
Forum Posts: 13
Member Since:
February 8, 2015
sp_UserOfflineSmall Offline

I don't know the UA syntax but you need a couple of CrLf. See http://community.thingspeak.com/forum/esp8266-wi-fi/esp8266-module-using-at-comands/#p1802

September 14, 2015
4:01 pm
Avatar
kniazio

Silver
Members
Forum Posts: 19
Member Since:
September 13, 2015
sp_UserOfflineSmall Offline

Michel_J said

I don't know the UA syntax but you need a couple of CrLf. See http://community.thingspeak.com/forum/esp8266-wi-fi/esp8266-module-using-at-comands/#p1802

I think I do not understand.
I want to do something like on this page is described
http://www.instructables.com/id/Low-cost-WIFI-temperature-data-logger-based-on-ESP/?ALLSTEPS

September 14, 2015
7:27 pm
Avatar
Michel_J

Silver
Members
Forum Posts: 13
Member Since:
February 8, 2015
sp_UserOfflineSmall Offline

One screen shot (http://cdn.instructables.com/FS2/5UBI/I4CMNUCJ/FS25UBII4CMNUCJ.LARGE.jpg) of this instructable shows some backslash r backslash n inside the string of the GET. Those backslash r backslash n are CrLf, carriage and line feed.

Your string should look like this:

GET /update?key=ID9D358UQURTFIMU&field1=1.23&headers=false HTTP/1.1{CrLf}
Host: api.thingspeak.com{CrLf}
Connection: close{CrLf}
Accept: */*{CrLf}{CrLf}

I this example the value passed to field1 is 1.23.

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

kusmumichael, petersmith99, Rambant, blakeharriss09, optisol, Niyonzima Fils

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457