Show Posts
Pages: 1 [2] 3
16  Topics / Home Automation and Networked Objects / Re: LAN server without refreshing on: January 10, 2013, 12:39:31 pm
I'm not sure but has the String been fixed yet?

http://code.google.com/p/arduino/issues/detail?id=857

Could it be that?
17  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 10, 2013, 12:08:28 pm
From what I've read polling causes an increase of the use of bandwidth which could affect other users, and it's not in real time so, it is still an option but not the best.

You are polling the server with a 8 bit 16 MHz machine. Even if you would have hundreds of them looping as fast as they can the web server will not be your bottleneck. If it is, drop the HTTP or even the TCP because the headers are most of the messaging.
18  Topics / Home Automation and Networked Objects / Re: Cheap and small RF Rx/Tx on: January 10, 2013, 09:45:30 am
There is a library called "VirtualWire" that adds framing around your message so that it can detect interference.  This can be used to prevent damaged messages from causing unexpected behavior on the receiver.

Documentation for VirtualWire can be found here: http://www.open.com.au/mikem/arduino/VirtualWire.pdf

This migth help also: http://code.google.com/p/rc-switch/. You could use the same protocol and use those kinds of remotes to controll it along with your arduino.
19  Using Arduino / Programming Questions / Re: Text Array on: January 08, 2013, 03:56:03 pm
And the second question?

Absolutely anything can happen, horrible nondeterministic things eg. nasal demon will fly out.
20  Topics / Home Automation and Networked Objects / Re: Sensors on: January 08, 2013, 10:30:43 am
I use something I made myself.

On the center I have ground and +5v lines and the rest of the pins are freely routable with short jumper wires.

You can also rearrange the pins on the other end of the 3 or 4 wire cable with dupoint connectors you are using to connect the sensor, so this works with any sensor that requires 5v and 1 or 2 other IO pins. I have also added some extra +5v and ground pins to the other end of the proto board.

21  Using Arduino / Programming Questions / Re: Text Array on: January 08, 2013, 10:08:16 am
Or,
Code:
char sNames[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sun"};

What does that actually do? And specifically, what does it do if the number of characters in an initialiser string is not 3?

That would create a matrix like this
0
1
2
3
0'S''u''n''\0'
1'M''o''n''\0'
2'T''u''e''\0'
3'W''e''d''\0'
4'T''h''u''\0'
5'F''r''i''\0'
6'S''a''t''\0'
22  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 08, 2013, 08:38:16 am
Here is your code. I had to install new LAMP set up and while making sure everything works I wrote the example for you:

Arduino sketch modified from Ethernet WebClient example:
Code:
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
IPAddress server(192,168,0,12); // Your webserver IP

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);

}

void loop()
{
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /led/ledstatus.php HTTP/1.0");
    client.println();
    delay(1000);
    char c;
    // go trough the responce. as the value we are looking for is in the end of the responce after this loop char c will contain the last char of the respoce, 0 or 1
    while (client.available()) {
      c = client.read();
    }
  
    // if char c converted to an integer is somethning else than 0
    if (atoi(&c)) {
          Serial.println("Led should be on");
          //turn the led on here
        }
        else{
           Serial.println("Led should be off");
           //turn the led off here
        }
  
  }
  else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println("disconnecting.");
    client.stop();
  }
  delay(5000);
}

index.php
Code:
<?
if (isset($_POST['status'])) {
    $fh = fopen("ledstatus.txt", 'w') or die("can't open file");
    $on = $_POST['status'];
    fwrite($fh, $on);
    fclose($fh);

} else {
    $fh = fopen("ledstatus.txt", 'r');
    $on = fread($fh, 1);
    fclose($fh);
}
?>
<!DOCTYPE HTML>
<html>
<body>
<form action="index.php" method="post">
    <label> <input type="radio" name="status" <?if ($on) {echo 'checked = "checked"';} ?> value="1">On</label>
    <label> <input type="radio" name="status" <?if (!$on) {echo 'checked = "checked"';} ?> value="0">Off</label>
    <input type="submit" value="Submit">
</form>
</body>
</html>

ledstatus.php
Code:
<?
    $fh = fopen("ledstatus.txt", 'r');
    echo fread($fh, 1);
    fclose($fh);
?>
23  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 08, 2013, 05:27:38 am
Actually, it's possible to get an arduino to do almost anything on the web.  Ever since plugins became possible (yes, I know it was years and years ago) we could simply 'include' source from an external source.  Just using an iframe we can put an entire web page on the browser with only a few bytes on the arduino.  Heck, we could put almost everything on a web server, and a little src=http://somebigserver/mypage to get it on the user's browser.

I use this little trick to get cool gauges and really big graphs on my little arduino web page.

I'm not sure was this comment for me. If it was, did you notice on my solution Arduino is doing a full CRUD (create, read, update delete) using a JSON Restinterface pretty much atomatically? It is not just loading files from the Internet to the browser.

24  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 07, 2013, 03:57:33 pm
Also, this is a little arduino with very limited capabilities when compared to a web server with all the supporting software they carry.  So, you don't have php, java, or any of that stuff to do work for you.  If you want to get a variable, you have to do it yourself in the arduino code.  This is normally done by constructing a string that indicates what you did and sending it back to the server.

Actually you can do quite a lot if you have an Arduino Mega 2560. I have been working on this lately and wrote a quick seminar paper for school about the subject. You can read the online version here http://www.cs.helsinki.fi/u/ljlukkar/iot/ but as it has been already two months since I wrote that the examples are out dated. How ever I have updated all the examples to GitHub to work with the current versions of the libraries.

All of the following examples also contain a link to dummy UI where you can try out how the UI works. If you are using Chrome open up the developer tools and pay attention what happens on the Network tab. None of these should be thought as real "projects" but instead of just demos. I haven't actually tested do even some of them work properly on all situations and the code is crappy.

The most simple one:
https://github.com/lasselukkari/Todo

Most advanced:
https://github.com/lasselukkari/Arduino-RC-Timer-Switch/

Random:
https://github.com/lasselukkari/Weather-Station
https://github.com/lasselukkari/PinToggle

PS. I just realized I spent many hours reading your blog after stumbling across it while googling yesterday.
25  Topics / Home Automation and Networked Objects / Re: How to control LED using Arduino as a webclient? on: January 07, 2013, 02:15:26 pm
The functionality you are after would in theory require websockets, but you will probably have do with polling.

On Arduino side you will have a loop that will keep making HTTP GET reguests to a url, lets say 192.168.0.11/ledstatus.php. The "192.168.0.11" is the IP address of your web server.

The ledstatus.php shoud serve some kind of responce. In your case it's enough to respond with a number 0 or 1 for on and off state. Read and parse the responce on Arduino and set the led on or off accordingly. The ledstatus.php should read the state from a txt file. It could be ledstatus.txt. Test the ledstastus.php with your browser to make it sure it works the way it should be.

On the server running on the ip 192.168.0.11 you will have php page containing a html form, lets say index.php. The form should have two radio buttons with options: "on" and "off", and button to submit the form.  When the index.php page loads set the correct radio button selected according to value saved to a ledstatus.txt using php. Point the form action to formhandler.php.

The formhandler.php should first read the form parameter then save it to the ledstatus.txt file and then point the browser back to the index.php. You can also combine the formhandler.php and index.php into one file if you first check if the form parameter has been set and save the state if it is found.
26  Topics / Home Automation and Networked Objects / Re: Arduino Mega JSON REST interfaces (for HTML GUIs) on: January 05, 2013, 07:45:56 am
I made a another example.
https://github.com/lasselukkari/Arduino-RC-Timer-Switch

This time the UI is controlling RC switches like these:



Features
  • Controll cheap 433mHz AC switches with arduino and web UI
  • No computer needed as a mediator
  • Multipurpose JSON REST interface
  • Teach devices to arduino by pushing the remote controller buttons
  • Remote controller actions are tracked by the arduino
  • Timers
  • Settings saved to a SD card

Dummy test UI: http://www.cs.helsinki.fi/u/ljlukkar/rcswitch

Setup:
27  Using Arduino / Programming Questions / Re: Adding token to end of URL on: December 21, 2012, 01:41:32 pm
For simple GET/POST parameter handling you will probably do with the Webuino library

Use unix style timestamps. JavaScript date object will be your friend.

I just wrote an examle how a pins high/low state can be controlled using a web interface but it doesn't have the timer functionality you are after.
https://github.com/lasselukkari/PinToggle/blob/master/pintoggle.ino

28  Topics / Home Automation and Networked Objects / Re: Arduino Mega JSON REST interfaces (for HTML GUIs) on: December 19, 2012, 04:44:44 am
Would it be possible to have an example about how to manage some of the PIN's status (something like ON/OFF).

I have an 8-channel relay board and I have been planning to write an example how it could be used as a timer controlled by a web gui. I'll send you a pm once I get it done and uploaded to github.

Thanks a lot !!!

I'm sorry that it has taken so long.

Here is a simple example how to control LOW/HIGH status of a pin.

Settings are saved after eatch change and loaded when the progrmam starts.



Source: https://github.com/lasselukkari/PinToggle/blob/master/pintoggle.ino
Code:
#include "SPI.h"
#include "Ethernet.h"
#include "SD.h"
#include "aJSON.h"
#include "WebServer.h"

//define range of pins you want to control
#define FROM_PIN 55
#define TO_PIN 58

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };

WebServer webserver("", 80);
aJsonObject* pins;
File file;

void indexCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) {
server.httpSuccess();
if (type != WebServer::HEAD) {
P(helloMsg) =
"<!DOCTYPE html>\n<html lang=\"en\">\n"
"<head>\n"
"\t<meta charset=\"utf-8\">\n"
"\t<title>Pin Toggle</title>\n"
"\t<link href=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/css/style.css\" rel=\"stylesheet\">\n"
"\t<link href=\'http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700,300\' rel=\'stylesheet\' type=\'text/css\'/>\n"
"</head>\n"
"<body>\n"
"<div class=\"container\">\n"
"\t<div id=\"pin-list\">\n"
"\t</div>\n"
"</div>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/jquery.min.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/lodash.min.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/lib/backbone-min.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/models/pin.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/collections/pins.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/views/pins.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/views/app.js\"></script>\n"
"<script src=\"http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/js/app.js\"></script>\n</body>\n"
"</html>";
server.printP(helloMsg);
}
}

// this method is performed before the reguest is prosessessed and default responce is generated
// server.setPreventDefault(true); disables the default prosessing and responce once
void switchBeforeResposeCmd(WebServer &server, WebServer::ConnectionType type, char * tail, bool tailComplete,
aJsonObject ** collection, aJsonObject ** model) {
if (type == WebServer::PUT) {
if (model != NULL) {
pinMode(aJson.getObjectItem(*model, "pin")->valueint, (bool) aJson.getObjectItem(*model, "low")->valuebool);
}
}

}

// this method is performed after the responce is sent so it doens't block it anymore
void switchAfterResposeCmd(WebServer::ConnectionType type, aJsonObject ** collection, aJsonObject ** model) {
pinMode(53, OUTPUT);

if (SD.exists("pin.txt")) {
SD.remove("pin.txt");
}

file = SD.open("pin.txt", FILE_WRITE);
aJson.print(&**collection, file);
file.close();
}

void setup() {
Serial.begin(9600);
pinMode(53, OUTPUT);

if (!SD.begin(4)) {
Serial.println("SD initialization failed!");
}

if (SD.exists("pin.txt")) { //load settings file if found
file = SD.open("pin.txt");
pins = aJson.parse(file);
file.close();

aJsonObject* current = pins->child;

while (current) {
pinMode(aJson.getObjectItem(current, "pin")->valueint,
(bool) aJson.getObjectItem(current, "low")->valuebool);
current = current->next;
}

} else { //if not found populate dta
pins = aJson.createArray();

for (int i = FROM_PIN; i < TO_PIN + 1; i++) {
pinMode(i, LOW);
pinMode(i, OUTPUT);
aJsonObject* pin = aJson.createObject();
aJson.addItemToObject(pin, "id", aJson.createItem(i - FROM_PIN + 1));
aJson.addItemToObject(pin, "pin", aJson.createItem(i));
aJson.addItemToObject(pin, "low", aJson.createItem(false));
aJson.addItemToArray(pins, pin);
}
}

//add binding to webserver and set actions
webserver.addJSONBinding("pins", &pins);
webserver.setBeforeRequest("pins", &switchBeforeResposeCmd);
webserver.setAfterRequest("pins", &switchAfterResposeCmd);

webserver.setDefaultCommand(&indexCmd);

Ethernet.begin(mac);
webserver.begin();

for (byte i = 0; i < 4; i++) {
Serial.print(Ethernet.localIP()[i]);
if (i < 3) {
Serial.print('.');
}
}
Serial.println();
}

void loop() {
webserver.processConnection();
}

Dummy UI: http://www.cs.helsinki.fi/u/ljlukkar/pincontrol/
29  Using Arduino / Interfacing w/ Software on the Computer / Re: Question about: Arduino control over the Internet on: November 05, 2012, 02:31:00 am
http://arduino.cc/forum/index.php/topic,129122.0.html
30  Topics / Home Automation and Networked Objects / Re: Arduino Mega JSON REST interfaces (for HTML GUIs) on: October 28, 2012, 10:02:46 am
Would it be possible to have an example about how to manage some of the PIN's status (something like ON/OFF).

I have an 8-channel relay board and I have been planning to write an example how it could be used as a timer controlled by a web gui. I'll send you a pm once I get it done and uploaded to github.
Pages: 1 [2] 3