Arduino Question

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

rockytoptim

Supporting Member
HBT Supporter
Joined
May 2, 2009
Messages
762
Reaction score
95
Location
Livonia, MI
Anyone here have expeirence with the WiShield from AsyncLabs for arduino. It adds wifi 802.11b to the arduino. I have some coding questions if anyone is familiar with it.

Thanks
 
Anyone here have expeirence with the WiShield from AsyncLabs for arduino. It adds wifi 802.11b to the arduino. I have some coding questions if anyone is familiar with it.

Thanks

Sorry, haven't played with it yet, but I am considering something like for when I get around to building my fermentation chamber.
 
Well I got the code figured out. So now I can monitor my fermentation temps that are in my detached garage from the house. Its not pretty or near the quality of Yuri's stuff but it will have to do. Note screen dump is not of actual fermentation just testing having it sitting out in my gargare.

WiFiFermentTemperatures.jpg
 
I'm interested in the code details - I have an arduino being shipped to me, and I'm interested in monitoring multiple fermentations as well as mash temps. You're using the WiShield to make it talk to the computer? I'll have the USB arduino (Duamilanove) but would like to find a way to store the data on the arduino itself so that I don't have to have it connected to a computer at all times...
 
The WiShield is for posting sensor data to a webpage. You could probably a PC run a script to read data from the webpage and store it but thats beyond my capability. You can store data on the arduino eeprom but your limited to 512 bytes which isn't much so your going to run out of memory really quick. They do make a SD Shield where you can add a SD card to the arduino and store data to that would be the way to go. Let me know if you have any questions about coding or the sensors. I am new to this coding and Arduino but I will help if I can.
 
I just ordered an arduino and am interested in something like this aswell. My main question is how is the arduino publishing that info to the net? Do you have a script that is collecting data from the arduino?
 
Rather than using the WiShield as a standalone web server, use it to provide a simple XML file to your network. Then use another computer on the network as a web server capable of doing more complex operations. The main page could be kept on the more powerful server and use Ajax to get the XML file. With a bit of scripting, the page could be dynamically updated without reloading.

Here's a JavaScript code snippet from my setup. Behind the scenes, the XML file is dumped to local storage from a serial port on the web server. The function containing this code is run about once per second using the setInterval() method.

Code:
    // get the xml document via Ajax/http
    httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange=function() {
      if(httpRequest.readyState == 4) {
        steamPress = Number(httpRequest.responseText);
      }
    }
    httpRequest.open("GET","./xml/brewhut.xml",false);
    httpRequest.send(null);
    xmlDoc=httpRequest.responseXML;

    // update the global variables by parsing the xml document
    steamPress=Number(xmlDoc.getElementsByTagName("steamPress")[0].childNodes[0].nodeValue);
    steamTemp=Number(xmlDoc.getElementsByTagName("steamTemp")[0].childNodes[0].nodeValue);
    spargeTemp=Number(xmlDoc.getElementsByTagName("spargeTemp")[0].childNodes[0].nodeValue);
    mashTemp=Number(xmlDoc.getElementsByTagName("mashTemp")[0].childNodes[0].nodeValue);
    mashVol=Number(xmlDoc.getElementsByTagName("mashVol")[0].childNodes[0].nodeValue);
    boilVol=Number(xmlDoc.getElementsByTagName("boilVol")[0].childNodes[0].nodeValue);
    steamElement=Number(xmlDoc.getElementsByTagName("steamElement")[0].childNodes[0].nodeValue);
 
Thanks Yuri,
After playing with the WiShield I was looking into doing something like that but wasn't sure what my next step woulde be. WiShield definitely cannot server up a complex webpage and is better left to a better server. I will look into Ajax. Thanks for the response

To Skins Brew: Below is example sketch from the WiSever library.

Code:
/*
 * A simple sketch that uses WiServer to serve a web page
 */


#include <WiServer.h>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};	// IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"};		// max 32 bytes

unsigned char security_type = 0;	// 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};	// max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
				};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------


// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
  
    // Check if the requested URL matches "/"
    if (strcmp(URL, "/") == 0) {
        // Use WiServer's print and println functions to write out the page content
        WiServer.print("<html>");
        WiServer.print("Hello World!");
        WiServer.print("</html>");
        
        // URL was recognized
        return true;
    }
    // URL not found
    return false;
}


void setup() {
  // Initialize WiServer and have it use the sendMyPage function to serve pages
  WiServer.init(sendMyPage);
  
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);
}

void loop(){

  // Run WiServer
  WiServer.server_task();


[COLOR="Red"] //Run Your Temperature control stuff Here.[/COLOR]


  delay(10);
}
 
@Yuri -
So, you can have the arduino append an xml file, or just create a new one with the most recent data? Where does the file itself reside?
 
In my system, the Arduino spits out the text of a complete XML file every 250ms via serial communication. I connect the Arduino directly to the server computer and use a very crude Linux script to capture the serial data and dump it to /var/www/xml/ (a logical location when using Apache2 on Ubuntu). The file is overwritten each time the script runs.

In Tim's system, the entire webpage is stored on and served from the Arduino/WiShield.
 
Ok. So it looks like for what I want to do (charting temp over time, controlling, etc) I need to use the direct connection. I'm not so concerned with the webpage thing. I wonder how hard it'd be to use the SD shield to store data and then dump all of the data to the computer when the arduino is connected via USB...

EDIT: sorry for the mini-hijack
 
Any of the systems in discussion here could be used for datalogging. For my purposes, XML really didn't lend itself to storing a history, so I skipped it. However, see http://twitter.com/kampferstrahl. By posting data from the XML file to Twitter, I get datalogging (eventually I intend to monitor fermentation temps instead of brew day data, but for now it's just kind of fun to watch).

I would not use an SD card AND a direct serial connection. Use one or the other. If you opt for the SD card, you could periodically remove, read, erase, and replace it. With a serial connection, the attached computer could be configured to read and append data to a file, negating the need for the Arduino to have its own storage media.
 
I guess the reason I was thinking of using both the SD and the direct connection was that I'd prefer to have the direct connection but don't have a dedicated computer to be used. Maybe I'm lazy, but I'd really like to have things more automated than having to plug the SD card into my computer. What I was thinking was that the computer receives data in real time when it's plugged in, and when it isn't, the SD card receives the data. When the computer is plugged in after a period of being unplugged, it receives all of the data it "missed" from the SD card, in addition to starting to receive real-time data.
 
Since the Arduino will be semi-permanently installed in a place where power and network access aren't a problem, an ethernet or wireless shield would be a better solution. You would have constant data flow that way.

The reason SD shields are marketed as "dataloggers" is that you can install them on a microprocessor board located anywhere (like in a car with a GPS module or on a mountain top with battery power and weather sensors). Then, when the logging period is complete, you have a record of what happened.
 
Cool. I'm getting a little ahead of myself, as I don't even have this stuff yet, but it's good info. Thanks, Yuri. I'll probably start a thread when I get this stuff rolling.
 
Cool. I'm getting a little ahead of myself, as I don't even have this stuff yet, but it's good info. Thanks, Yuri. I'll probably start a thread when I get this stuff rolling.

You and me both dude. I ordered the Arduino last week and am dying to start messing around with it.
 
Hey Yuri,

Would it be possible to see the script that is copying data off the serial port and putting it into your document root dir?
 
I'm just using a bash script that uses this line:

head -n 11 /dev/ttyUSB0 > /var/www/xml/brewhut.xml

The file is 11 lines long, hence the -n option. Output is redirected to my XML document. It runs either every minute using crontab, or (when I feel like consuming more resources) every 250ms using watch.

If you use the Arduino IDE to upload a sketch (in Linux), the serial port will become unavailable to other system processes for some reason. Running 'screen /dev/ttyUSB0 <baud rate>' and then quitting the screen process with <Ctrl-A> then <k> seems to fix the issue.

Like I said, crude but effective.
 
Back
Top