Show Posts
|
|
Pages: [1] 2
|
|
1
|
Topics / Home Automation and Networked Objects / Re: Arduino Mega JSON REST interfaces (for HTML GUIs)
|
on: January 26, 2013, 05:45:26 am
|
Hi llukkari,
Have you tried to do this project with the css and javascript files embedded on the arduino somehow? Do you have any suggestions on how that might be done?
Thanks, Tom
You could probably use the sd card. In my hydrobot project, http://www.cs.helsinki.fi/u/ljlukkar/hydrobot/, I was able to use quite large csv files. I can't see any reason why it wouldn't work for other files as well. You should try to set the http Cache-Control header so that the browser caches the responce and doesn't request it again. Backbone.js, the MV* framework I have used in all the examples, is one of the most light weight out of them all.
|
|
|
|
|
2
|
Topics / Home Automation and Networked Objects / Re: Relay RF Control
|
on: January 13, 2013, 04:25:30 am
|
thanks for the response. I take from your reply that it would be possible for me to control the relay using the RF linkkit.
So i can control my relay without wiring directly to the UNO using this method?
The radio controllable switches I used are so cheap that I wouldn't bother to build the receiving end by myself. And atleast here Finland the legistlation is so that this has been the only legal way I know to control the mains AC with out being a qualified electrician. If you want to use your own relays you could probably use the VirtualWire library instead.
|
|
|
|
|
6
|
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.
|
|
|
|
|
9
|
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. 
|
|
|
|
|
10
|
Using Arduino / Programming Questions / Re: Text Array
|
on: January 08, 2013, 10:08:16 am
|
Or, 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' |
|
|
|
|
|
11
|
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: #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 <? 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 <? $fh = fopen("ledstatus.txt", 'r'); echo fread($fh, 1); fclose($fh); ?>
|
|
|
|
|
12
|
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.
|
|
|
|
|
13
|
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/TodoMost advanced: https://github.com/lasselukkari/Arduino-RC-Timer-Switch/Random: https://github.com/lasselukkari/Weather-Stationhttps://github.com/lasselukkari/PinTogglePS. I just realized I spent many hours reading your blog after stumbling across it while googling yesterday.
|
|
|
|
|
14
|
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.
|
|
|
|
|