Show Posts
|
|
Pages: [1]
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / arduino web server client.println wireshark view of the ethernet question
|
on: October 29, 2012, 06:30:10 pm
|
Hi, I have a question concerning the implementation of the webserver code for client.println. Here is what i did, i decided to watch the transmissions using wireshark when the PC goes to the Arduino, and gets the web page. Just to see how the packets were being formed and if they made sense. (You know, speed, net traffic, etc). The HTML could not easily be seen for some reason, but with some work, it became apparent that the arduino is serving up the web page one character at a time, that is, on each back and forth with the computer, the message appears to be being formed as 1 byte long. For each HTTP, the length was one byte! So, for each byte in the client.println(F'<some html junk..>') you end up with over 114 characters being sent, one ethernet frame at a time. 54 going one way, then 60 going into the PC. This means that the single client.println shown below, with almost 100 characters to transmit, will result in 11,400 bytes being transfered. Every single character in the line below consists of a back and forth's between the arduino and the PC. client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/H\r'><INPUT TYPE='submit' VALUE='Light Brighten'></FORM> ")); Could someone explain how i get the arduino to send the entire line in one proper frame! I would expect that this would have taken, 54 bytes from the PC, and then about 160 bytes from the arduino, and not 11,400 bytes, for this line. The stuff seems to work, but appears to be really inefficient use of the network. Suggestions, comments.. Thanks, Walt
|
|
|
|
|
3
|
Community / Exhibition / Gallery / Re: arduino enclosure using plexiglass for the X10 webserver on the arduino
|
on: October 22, 2012, 06:18:36 pm
|
A very nice mini tutorial on controlling arduino via the web, including your smartphone. Useful for lots of applications! yes, this is just an example, but using the x10 became a simple solution. What is nice is that you don't need any app. There are a couple of tricks in this, one being the button, the other is the F for forcing the storage in the flash. I would have assumed that this would be a compiler optimization automatically, but it does not do that, so by forcing the F in the client print, it will save a bunch of memory, and it eliminated a bunch of unreported SRAM overflow issues that resulted in some erratic operations with the debugger. Glad you found it useful, Walt,
|
|
|
|
|
7
|
Topics / Home Automation and Networked Objects / Re: Pushing a html page to a client device when a push button is pressed
|
on: October 14, 2012, 04:12:22 pm
|
Hi, I am not sure I understand your comment... There are lots of web pages that discuss this simple solution. See link below. You are correct that this will result in a Get. But this is standard HTML and its a form method with an action of going to a link. http://www.htmlgoodies.com/tutorials/buttons/article.php/3478871/So-You-Want-A-Link-Button-Huh.htmIs there a better or simpler way to do this type of control for the arduino? That is, to have a page shown on the web browser (running on any platform), with a set of button shown that causes an action in the arduino? I guess I was thinking that not having a program on the computer or an app on the phone, would be a plus. for example, if you run this line in your browser, you will end up with a button that links back to this topic when you push it, (Copy and put it into a HTML file to try). You might be able to put it here but i don't know all the syntax for this list server. <FORM METHOD='LINK' ACTION=' http://arduino.cc/forum/index.php/topic,122196.0.html'><INPUT TYPE='submit' VALUE=' click here and you this post '></FORM> Thanks, Walt,
|
|
|
|
|
8
|
Topics / Home Automation and Networked Objects / Re: X10 webserver with button control HTML video
|
on: October 09, 2012, 06:03:43 pm
|
|
Hi,
I have put links in buttons on the Arduino that will go right to a youtube video. So that is not my question.
My question is how do I post a video here, so you see it in the forum, not just the link. In some forums one might use something like [youtube]videolinkinyoutube[/youtube].... But that didnt work here. Tried it via the insert flash and that didnt work either. So, i know it can be done, but dont know the syntax for this specific forum.
You might know this answer or know where I would find it.
Thank You, Walt,
|
|
|
|
|
9
|
Topics / Home Automation and Networked Objects / Re: Using android phone to control remote dimmer
|
on: October 08, 2012, 09:12:32 pm
|
Hi, I just posted a way to do this using a windows phone, no app required, so it should work with the android. The Arduino doesn't need to be connected with a wifi shield. I used the wireless router in the house, just an ethernet shield and a cable. The Arduino serves up a webpage and then it runs the x10 which do the dimming. So, you access the web page from the android and click the buttons. I have put 'dim and brighten', along with a number of x10 on/off command buttons. The thing about x10, you have to select a specific address and then send an on, then you can dim/brighten. Here is the video link. I posted the code in a previous post. http://youtu.be/0a1vkSB2LQYRegards, Walt,
|
|
|
|
|
10
|
Topics / Home Automation and Networked Objects / Re: X10 webserver with button control HTML video
|
on: October 08, 2012, 06:29:06 pm
|
Hi, ok, here is the code... forgot to upload it. Walt,
/* Web Server with X10 Firecracker control No need for a app, or a program on the PC, this simple arduino program allows web based html button control of the arduino from any browser, on a PC, IPAD, IPOD, smart phone. A Waltsailing Production
* Ethernet shield attached to pins 10, 11, 12, 13 * x10 Firecracker attaches to pins 8 and 9
*/
#include <SPI.h> #include <Ethernet.h> #include <X10Firecracker.h> #include <WString.h>
#define RTS_PIN 8 // RTS line for C17A - DB9 pin 7 #define DTR_PIN 9 // DTR line for C17A - DB9 pin 4 #define BIT_DELAY 1 // mS delay between bits (1 mS OK)
// Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1, 177);
String s = String(30); //string for fetching data from address String cmd = "/X" ; //X is an example of the command that will come after the ethernet address in the GET...
// Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80);
void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.print("Pgm started ");
// start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP());
X10.init(RTS_PIN, DTR_PIN, BIT_DELAY); }
void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; boolean DoPage=true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); if (s.length() < 7) { s.concat(c); } // build up a short string to parse if(s.substring(0,3) == "GET" & DoPage){ // check for the GET from the web page cmd=s.substring(4,6); // get the 2 letters in the string out and call this the CMD, /A, or /B or /H etc, these come in after the GET // Serial.println("CMD="); //Serial.println(cmd); // Got a GET so, compare the received command to the specific command and then do something if (cmd == "/A" && DoPage) { Serial.println(F("Found A Pole Light on ")); X10.sendCmd( hcE, 14, cmdOn ); DoPage = false; } if (cmd == "/B" && DoPage) { Serial.println(F(" Light Dim")); X10.sendCmd( hcE, 14, cmdDim ); DoPage = false; } if (cmd == "/H" && DoPage) { Serial.println(F(" Light Bright")); X10.sendCmd( hcE, 14, cmdBright ); DoPage = false; } if (cmd == "/C" && DoPage) { Serial.println(F("Found C Pole Light Off")); X10.sendCmd( hcE, 14, cmdOff ); DoPage = false; } if (cmd == "/S" && DoPage) { Serial.println(F("Found S Ceiling on")); X10.sendCmd( hcE, 7, cmdOn ); DoPage = false; } if (cmd =="/R" && DoPage) { Serial.println(F("Found T Ceiling Off")); X10.sendCmd( hcE, 7, cmdOff ); DoPage = false; } if (cmd == "/U" && DoPage) { Serial.println(F("Found U Light on")); X10.sendCmd( hcE, 8, cmdOn ); DoPage = false; } if (cmd =="/W" && DoPage) { Serial.println(F("Found W pole lamp Off")); X10.sendCmd( hcE, 8, cmdOff ); DoPage = false; } } // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println(F("HTTP/1.1 200 OK")); client.println(F("Content-Type: text/html")); client.println(F("Connnection: close")); client.println(); client.println(F("<!DOCTYPE HTML>")); client.println(F("<html>")); client.println(F("<head>")); client.println(F("<meta content='text/html; charset=ISO-8859-1'http-equiv='content-type'>")); client.println(F("<title>Walts Arduino Program")); client.println(F("</title>")); client.println(F("</head>")); // the next line sets the background color to something nice like blue client.println(F("<body style='background-color: rgb(0, 0, 153); color: rgb(255, 255, 0);'alink='#cc6600' link='#cc0000' vlink='#993300'>")); // load in a background .jpg for the web page. client.println(F("<BODY BACKGROUND='http://home.comcast.net/%7EWaltschn1/Waltschn1/la_dolce_vita_near_dock_2s.jpg' style='width: 481px; height: 690px;'></span><br>")); // set up some HTML that has buttons with specific actions that link back to the arduino at the address of the arduino and have a specific string client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/A\r'><INPUT TYPE='submit' VALUE='Den Pole Light On '></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/C\r'><INPUT TYPE='submit' VALUE='Den Pole Light Off '></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/S\r'><INPUT TYPE='submit' VALUE='Den Ceiling Light On '></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/R\r'><INPUT TYPE='submit' VALUE='Den Ceiling Light Off '></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/U\r'><INPUT TYPE='submit' VALUE='Den Table Light on '></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/W\r'><INPUT TYPE='submit' VALUE='Den Table Light Off'></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/B\r'><INPUT TYPE='submit' VALUE='Light Dim'></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/H\r'><INPUT TYPE='submit' VALUE='Light Brighten'></FORM> ")); client.println("</html>"); // Clear out the received string s=""; break; } if (c == '\n') { currentLineIsBlank = true; } else if (c != '\r') { currentLineIsBlank = false; } } } client.stop(); Serial.println("client disonnected"); } } // end
|
|
|
|
|
11
|
Topics / Home Automation and Networked Objects / X10 webserver with button control HTML video
|
on: October 08, 2012, 06:19:54 pm
|
Hi, I put a video together that explains how I control the Arduino and X10 from any web browser. It works app free from the ipad, iphone, windows phone or from the computer without any program other than the web browser. I have it set up for operation locally, but I am sure it could be easily modified to run from anyplace outside. No program required anywhere else either, so no apps, or programs running in the PC. http://youtu.be/0a1vkSB2LQYThe Ethernet shield is plugged into the wireless router via the cable. I have an X10 CM17A hooked up to it run the lights. The video is a bit long but explains the code. This works pretty good. But... I would like to know if there is a more standard way to do this, or perhaps a simpler way. And, how do I put the video in to this forum so I can see it rather than just the link showing up? I see other posts like this. Comments/Suggestions? Thanks, Walt,
|
|
|
|
|
12
|
Topics / Home Automation and Networked Objects / Re: Pushing a html page to a client device when a push button is pressed
|
on: October 07, 2012, 09:23:33 pm
|
Hi, Not sure if this helps, but it works for me. This code puts a button on the web page and then the action can take you to a different page, or can control the arduino. If you are running a server on the Arduino, then these do the submit action which is like a specific web page request. The labeled Button is on the web page... and it sends it to the arduino. The arduino serves up the web page, so you don't need a separate server. The first example code sends your browser off to google, from the arduino. The second example, the action 192.168.1.177/A and action 192.168.1.177/B gets you the /A or /B after the GET which is sent back to the server running on the Arduino. This can be parsed out and you can then take action in the arduino code to either do the A function or the B function. Regards, Walt, client.println(F("<FORM METHOD='LINK' ACTION='http://www.google.com'><INPUT TYPE='submit' VALUE='go and google stuff'></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/A\r'><INPUT TYPE='submit' VALUE='Den Pole Light On '></FORM> ")); client.println(F("<FORM METHOD='LINK' ACTION='http://192.168.1.177/C\r'><INPUT TYPE='submit' VALUE='Den Pole Light Off '></FORM> "));
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Re: problem with loading when one more line is added to sketch
|
on: October 06, 2012, 08:07:49 am
|
|
Thanks for the F(...string/litteral...) answer which put this in flash. That cleared up the problem I have since looked at the documentation and can not find any reference to this. Maybe I am missing out on some of the documentation. Where would I have found this?
I will look into the HTML multiple forms/single forms, great suggestion..
Thank You, Walt,
|
|
|
|
|
14
|
Using Arduino / Programming Questions / problem with loading when one more line is added to sketch
|
on: October 03, 2012, 07:10:24 pm
|
Hi, I have been writing a sketch that runs a small web server from the arduino uno. This seems to work just great, except, without any warnings or other indications, the program seems to suffer from some sort of memory use issue during upload if I try to add in just one more line of code. The overall program size is around 14K, out of a max of 32k. The additional code should not be using up the limited SRAM, but maybe it is. In the program there are a number of lines that use client.print to serve up some HTML. An example of them is shown below. If I don't comment out any one of these four working lines of good code the program compiles, and then uploads, but rather than serving up the web page, it shoots fast jibberish out the serial monitor port back to the PC, rather than the expected network activity. It doesn't matter which line is commented out. No errors when compiling, no errors when uploading. That is the puzzle, which is leading me to think it is a memory issue, and since it is less than the flash available, its likely SRAM. They all work fine provided that they are all not in the sketch at the same time. So, here are some simple questions, 1. How do I figure out the memory utilization for the SRAM? Is there a memory map file being stored some place? Is there an assembly listing file available to aid in debug? 2. Are the strings in the client.print, being stored in SRAM or are they being loaded from flash. They are constants, so i would have expected the underlying code to use a pointer to the flash, however it is possible that it is storing these in SRAM, all at once, rather than bringing them one at at time when the line of code is actually being executed. 3. If I am running out of SRAM, is there any easy way to find out? The monitor goes out to lunch when I uncoment any of the additional lines. 4. is there any way to direct the ARduino to force storage of constants in flash, so that the memory can be better managed, or at least understood? 5. The program also uses an X10firecracker library and its associated lower level .h files, such as wiring.h (Not wire.h). Suggestions on how to resolve and debug this would be great. A snipet of the issue is below. Thank You, Walt, client.println("<FORM METHOD='LINK' ACTION=' http://192.168.1.177/XSomething_else\r'><INPUT TYPE='submit' VALUE='Turn on the light'></FORM> "); client.println("<FORM METHOD='LINK' ACTION=' http://192.168.1.177/Ytry_this_one\r'><INPUT TYPE='submit' VALUE='Light on dim it up down and Light off'></FORM> "); // client.println("<FORM METHOD='LINK' ACTION=' http://192.168.1.177/Z\r'><INPUT TYPE='submit' VALUE='Light off'></FORM> "); client.println("<FORM METHOD='LINK' ACTION=' http://192.168.1.177/ZSomething_else\r'><INPUT TYPE='submit' VALUE='Turn off the light'></FORM> ");
|
|
|
|
|