V7 Chapter 48
Its a blog - Read from the bottom up
Details
288. Fun and Games with GET - 2013-02-14
I am back struggling with making a GET and POST from the Arduino to an Apache server running on localhost. I need to set up an Arduino test sketch, a php script to respond to the sketch, and an Apache server running on my localhost. First the Apache:
-
Download and install Apache and PHP on your machine.
-
Build a Test sketch for your Arduino Ethernet board.
-
Build a Test PHP script
-
Modify the Apache configuration to allow the sketch and the script to talk to each other
-
Run it for a test
Install Apache and PHP - I like this setup best - WampServer. Work with it until you get this on your task bar (the green symbol is the server). If you want to know what a WAMP is see Wikipedia here
Arduino Sketch - Open your Arduino user interface and enter this code:
// Web client #include <PI.h> #include <Ethernet.h> mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Enter a MAC address for your controller
//address printed on a sticker on the shield
//IPAddress server(74,125,224,212); // Google (test with WhoIs:Google)
IPAddress server(192,168,1,113); // (localhost)
// 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; // Define a client
void setup()
{
Serial.begin(115200);// Open serial communications and wait for port to open:
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
if (Ethernet.begin(mac) == 0) // start the Ethernet connection:
{
Serial.println("Failed to configure Ethernet using DHCP");
for(;;) ;// no point in carrying on, so do nothing forevermore:
}
delay(1000);// give the Ethernet shield a second to initialize:
Serial.println("connecting...");
if (client.connect(server, 80)) // if you get a connection, report back via serial:
{
Serial.println("connected");
client.println("GET /arduino.php?testone=ThisIsaTest HTTP/1.0");
// Make a HTTP request:
client.println();
}
else
{
Serial.println("connection failed");
// If you didn't get a connection to the server: } } void loop() { if (client.available()) // if there are incoming bytes available
//from the server, read them and print them:
{
char c = client.read();
Serial.print(c);
}
if (!client.connected()) // if the server's disconnected, stop the client:
{
Serial.println();
Serial.println("disconnecting.");
client.top();
for(;;); // do nothing forevermore:
}
}
|
Arduino Sketch Test.Ino |
PHP Script - With a simple Notepad build this file:
<html> <body> Hello from localhost/arduino.php"> I saw your Event GET and your data: <?php echo $_REQUEST["testone"]; ?> <br /> </body> </html> |
arduino.php |
Save it in your servers 'web' directory. On my machine that is: C:\wamp\public_html
Modify Apache Configuration: Open up your Apache httpd.conf file from the WAMP server icon (the green one). Add the following lines:
# Added by James Brown and does work. <directory C:\wamp\public_html> allow from 127.0.0.1 </directory> |
Directory permission |
Restart your Apache server ( I use 'Restart all services'). This installs the directory permission change.
Run Your Script: When you run the Test.ino file you should see something like this:
Port open |
Results |
That should get you started.
287. Arduino String Crash Blues - 2013-01-29
Do you suffer from the Arduino String Crash Blues? Not sure? Build this sketch and run it.
// This sketch will crash after about three iterations. Its caused by the // Malloc bug in the String library void setup() { Serial.begin(9600); } void loop() { int n = 0; while(n <= 100) { int u = 20*n; int v = 30*n; String(n) + ", " + String(u) + ", " + String(v); Serial.println(str); delay(300); n++; } Serial.println("Done"); } |
Arduino to test for String Crash 'Blues' |
GOOD - If you are 'good to go' what you should see is an incrementing list of number that go to 100 and then repeat. You can shorten the delay if you like to make this test run faster. It should continue to build the list and restart ad infinitum.
BAD - If you are indeed a suffer then what you will see is unpredictable junk. You may see strange characters in the output of the sketch or it may stop running altogether. This is the fix:
-
Make sure your running the latest Arduino. If not download it now (currently vers 1.03)
-
Shut down your Arduino application.
-
Download this file ( malloc.c ). You can copy/past to Notebook for this operation.
-
SaveAs 'malloc.c' in your directory: C:\Program Files\arduino-1.0.3\hardware\arduino\cores\arduino
Caution: Make sure to put this file in your current Arduino applications location. It may be different than shown
-
Restart Arduino and rerun the test.
This fix should not be required past vers 1.03 of Arduino.
286. Pixel Configuration - 2012-12-12
I am attempting to set the configuration start up process for the pixel under development. This is a cut at the state machine.
Shield Init (1) - Power on pixel. At the end of this state the shield is outputting data and the Arduino will be waiting for valid position data from the shield.
Collect Position (2) - At the end of this state the pixel is locked and its location is known
Wait For Event (3) - Starts pixel monitoring waiting for events.
Processing Event (4) - Each event is handled as it is detected
|
285. Crazy Mouse - 2012-11-03
When I configured my development system (Zeke) to control the ublox GPS receiver from its serial port my mouse suddenly started jumping all over the place. Searching the net I turned up this RegEdit change that takes care of the problem for Windows 7.
Here's the fix: Open Regedit. Navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SerMouse, and
change the value "Start" from 3 to 4. Reboot