OpenWrt Forum Archive

Topic: connect openwrt with arduino to get temp in refrigerator

The content of this topic has been archived on 3 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

it's a early trying to conect the route with something real world,it should be use wr703,but in here,i dont wana to chooice a power suply,so i use mr11u in here,but the wr703 should work fine too.

the full process i put in my site,but it's mostly chinese
http://see.sl088.com/wiki/Openwrt%E6%B8 … 7%E5%8F%96

have some test to conect the mr11u to the arduino,i use usb port,it's good fit:
http://see.sl088.com/w/images/f/f8/IMG_7396.JPG

i chooice a temp sensor is 18b20,and with a nice cable:
http://see.sl088.com/w/images/d/db/18b20line.jpg

start connect
http://see.sl088.com/w/images/7/78/IMG_7408.JPG

put it in refrigerator
http://see.sl088.com/w/images/f/fd/IMG_7420.JPG

and i think put the pcb inside it may not a good idea,so i move it out
http://see.sl088.com/w/images/d/dc/IMG_7411.JPG

(Last edited by slboat on 27 May 2013, 16:47)

now i got find a place to settle the route and arudino,so here is seems good
http://see.sl088.com/w/images/b/bb/IMG_7422.JPG

in case the cable leave out,give a tie for the cable
http://see.sl088.com/w/images/f/fa/IMG_7428.JPG

not it should like this
http://see.sl088.com/w/images/5/5f/IMG_7432.JPG

after some hours ago,it become ice
http://see.sl088.com/w/images/f/f0/IMG_7483.JPG

that's the first try,it seems work,so why not put a led inside it,i not use any protection to the pin of led,but it's low cost,so not worry this
http://see.sl088.com/w/images/7/72/IMG_7492.JPG

the final look is not bad
http://see.sl088.com/w/images/7/7f/IMG_7493.JPG
http://see.sl088.com/w/images/c/c9/IMG_7495.JPG

wow!ice and led
http://see.sl088.com/w/images/4/46/IMG_7497.JPG
http://see.sl088.com/w/images/a/ab/IMG_7504.JPG

yes,after this,the pin of led is no luckly
http://see.sl088.com/w/images/1/17/IMG_7512.JPG

now i need write some code to the arduino,here is what i doing:

#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
 
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
 
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
 
  // Start up the library
  sensors.begin();
}
 
void loop(void)
{ 
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  sensors.requestTemperatures(); // Send the command to get temperatures
 
  Serial.print("Temp Now: ");
  Serial.println(sensors.getTempCByIndex(0));  
}

and sure,the main part,the openwrt,i use lua script to do the work,mostly is lua very tiny(only about 200k,and the luci had inside it)

-- slboat_get_temp.lua
-- to get the temp
wserial=io.open("/dev/ttyUSB0","w")
wserial:write("Serial Port OK")
wserial:flush()
rserial=io.open("/dev/ttyUSB0","r")
while true do
chaine = nil
while chaine==nil do
        --to get and to lose the flush
        chaine=rserial:read();rserial:flush()
        if lasttemp ~= chaine then
            outstr=os.date("%x %X", os.time()).."  ".. string.gsub(chaine,"Temp Now: ","The Temp is:")
            print(outstr)
            -- the record file
            f = assert(io.open("temp & ice", "a"))
        -- that's not kind good way,we can save a old string just for write file
            f:write(string.gsub(outstr,"The Temp is:","").."\n");f:close()
            lasttemp = chaine
        else
            print ("The temp has not change yet")
        end
 
end
end

(Last edited by slboat on 27 May 2013, 16:41)

we can run the script just with lua

root@OpenWrt:~/fun4me# lua io232.lua 
^C
^C
root@OpenWrt:~/fun4me# killall lua
root@OpenWrt:~/fun4me# lua io232.lua 
05/13/12 19:47:09  The Temp is:31.19
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
05/13/12 19:47:18  The Temp is:31.12
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
05/13/12 19:47:22  The Temp is:31.19
05/13/12 19:47:23  The Temp is:31.12
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
The temp has not change yet
05/13/12 19:47:30  The Temp is:31.06
05/13/12 19:47:31  The Temp is:31.12
The temp has not change yet
05/13/12 19:47:32  The Temp is:31.06
05/13/12 19:47:33  The Temp is:31.12
05/13/12 19:47:34  The Temp is:31.06
05/13/12 19:47:35  The Temp is:31.12
05/13/12 19:47:36  The Temp is:31.06
05/13/12 19:47:36  The Temp is:31.12
05/13/12 19:47:37  The Temp is:31.06

and sure we can use nohup to put it run in backgroud,because we dont wana open the ttl still

root@OpenWrt:~/fun4me# nohup lua io232.lua &
root@OpenWrt:~/fun4me# nohup: ignoring input and appending output to `nohup.out'
 
root@OpenWrt:~/fun4me# tail -f temp\ \&\ ice 
05/13/12 19:47:37  31.06
05/13/12 19:47:47  31.00
05/13/12 19:47:48  31.06
05/13/12 19:47:49  31.00
05/13/12 19:47:50  31.06
05/13/12 19:47:50  31.00
05/13/12 19:54:23  30.37
05/13/12 19:54:27  30.44
05/13/12 19:54:27  30.37
05/13/12 19:54:30  30.44
05/13/12 19:54:31  30.37

and i wana to save the file to csv,so i change the code a little bit

-- slboat_get_temp.lua
wserial=io.open("/dev/ttyUSB0","w")
wserial:write("Serial Port OK")
wserial:flush()
rserial=io.open("/dev/ttyUSB0","r")
while true do
chaine = nil
while chaine==nil do
        --to get and to lose the flush
        chaine=rserial:read();rserial:flush()
        if lasttemp ~= chaine then
        -- for csv,we just need a ","
            outstr=os.date("%x %X", os.time()).."  ,  ".. string.gsub(chaine,"Temp Now: ","The Temp is:")
            print(outstr)
            -- the record file,as csv type
            f = assert(io.open("logicetemp.csv", "a"))
        -- that's not kind good way,we can save a old string just for write file
            f:write(string.gsub(outstr,"The Temp is:","").."\n");f:close()
            lasttemp = chaine
        else
            print ("The temp has not change yet")
        end
 
end
end

now run it

root@OpenWrt:~/fun4me# nohup lua io232.lua &
root@OpenWrt:~/fun4me# nohup: ignoring input and appending output to `nohup.out'
 
root@OpenWrt:~/fun4me# tail -f logicetemp.csv 
05/15/12 10:06:49  ,-5.38
05/15/12 10:06:52  ,-5.31
05/15/12 10:06:55  ,-5.25
05/15/12 10:07:05  ,  -5.06
05/15/12 10:07:07  ,  -5.00
05/15/12 10:07:10  ,  -4.94
05/15/12 10:07:12  ,  -4.88
05/15/12 10:07:16  ,  -4.81
05/15/12 10:07:18  ,  -4.75
05/15/12 10:07:21  ,  -4.69
05/15/12 10:07:24  ,  -4.63
05/15/12 10:07:27  ,  -4.56
05/15/12 10:07:30  ,  -4.50
05/15/12 10:07:33  ,  -4.44
05/15/12 10:07:35  ,  -4.38
05/15/12 10:07:05  ,  -5.06
05/15/12 10:07:07  ,  -5.00
05/15/12 10:07:10  ,  -4.94
05/15/12 10:07:12  ,  -4.88
05/15/12 10:07:16  ,  -4.81
05/15/12 10:07:18  ,  -4.75
05/15/12 10:07:21  ,  -4.69
05/15/12 10:07:24  ,  -4.63
05/15/12 10:07:27  ,  -4.56
05/15/12 10:07:30  ,  -4.50
05/15/12 10:07:39  ,  -4.31
05/15/12 10:07:42  ,  -4.25
05/15/12 10:07:44  ,  -4.19
05/15/12 10:07:47  ,  -4.13
05/15/12 10:07:50  ,  -4.06
05/15/12 10:07:53  ,  -4.00
05/15/12 10:07:56  ,  -3.94
05/15/12 10:07:57  ,  -4.00
05/15/12 10:07:57  ,  -3.94
05/15/12 10:07:59  ,  -3.88
05/15/12 10:08:02  ,  -3.81
05/15/12 10:08:06  ,  -3.75
05/15/12 10:08:09  ,  -3.69
05/15/12 10:08:12  ,  -3.63
05/15/12 10:08:14  ,  -3.56
05/15/12 10:08:17  ,  -3.50
05/15/12 10:08:20  ,  -3.44
05/15/12 10:08:23  ,  -3.38
05/15/12 10:08:25  ,  -3.31
05/15/12 10:08:28  ,  -3.25
05/15/12 10:08:31  ,  -3.19
05/15/12 10:08:34  ,  -3.13
05/15/12 10:08:37  ,  -3.06
05/15/12 10:08:40  ,  -3.00
05/15/12 10:08:44  ,  -2.94
05/15/12 10:08:46  ,  -2.88
05/15/12 10:08:49  ,  -2.81
05/15/12 10:08:52  ,  -2.75
05/15/12 10:08:56  ,  -2.69
05/15/12 10:08:59  ,  -2.63
05/15/12 10:09:02  ,  -2.56
05/15/12 10:09:06  ,  -2.50
05/15/12 10:09:08  ,  -2.44
05/15/12 10:09:13  ,  -2.38
05/15/12 10:09:17  ,  -2.31
05/15/12 10:09:19  ,  -2.25
05/15/12 10:09:23  ,  -2.19
05/15/12 10:09:26  ,  -2.13
05/15/12 10:09:30  ,  -2.06
05/15/12 10:09:33  ,  -2.00
05/15/12 10:09:37  ,  -1.94
05/15/12 10:09:41  ,  -1.88

here we got a csv file

A benefit about the csv maybe is the excel can support it,so let's use it

here is what i final get:
http://see.sl088.com/w/images/7/7b/Fast_Cap0452.jpg
http://see.sl088.com/w/images/1/11/Fast_Cap0453.jpg

the simple csv file i got is here:
http://see.sl088.com/wiki/%E6%96%87%E4% … cetemp.zip

the further to-do:
to put the arduino mini inside the wr703-it's mostly small.
to use luci show the data,it's easy to get.

i think in here, the cool part is the route is kind low cost,and small,and with a box.it force to do one thing,maybe not strong like Raspberry,but i think a route just more sexy to doing this,and Raspberry pie is too like a pc to me.

Again, a lot of huge and unnecessary images in multiple posts... please, don't do this anymore. You can include 1-2 images and put URLs directing to more pictures - it will be easier to read your topics.

pepe2k wrote:

Again, a lot of huge and unnecessary images in multiple posts... please, don't do this anymore. You can include 1-2 images and put URLs directing to more pictures - it will be easier to read your topics.

sorry,i dont really care that mush,in my site,i just random to put them togher,and my english is really bad too,mostly i just dont post anything here for safely.

As an alternative to this:
- Use a DS9490R USB 1-wire busmaster -> much smaller than an anrduino
- use digitemp or owfs to get the sensor readings
- use rrdtool to create graphics

tmo26 wrote:

- Use a DS9490R USB 1-wire busmaster -> much smaller than an anrduino

You can even just use only 2 GPIOs from router... I'm using some sensors on I2C, on MR3040 (GPIO 1 and 13) smile

Or just 1 GPIO and use 1wire.

with an avr like atmega32  the variety of applications is endless and it's not pricey or power consuming
I think the idea of bringing openwrt and arduino together is pretty neat . I used the uart ( the ar9331 uart can also be set as SPI ) to communicate between arduino and 9331 so the usb can be free for other purposes.
you can also make your own board based on these materials.
take a look at http://arduino.cc/en/uploads/Main/ardui … ign_3b.zip
I've already made an evaluation board and I'm pretty happy with it

(Last edited by ashkanull on 28 May 2013, 11:27)

i see there are lot good idea to do this,the use gpio with one-wire is cool,i hope you guys can share more like this hardware conect to the really world.

that might get you started: http://squidge.sourceforge.net/w1/
and search for "w1_gpio_custom", that should lead you to the folks who already did these things.

The discussion might have continued from here.