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:

  1. Download and install Apache and PHP on your machine.

  2. Build a Test sketch for your Arduino Ethernet board.

  3. Build a Test PHP script

  4. Modify the Apache configuration to allow the sketch and the script to talk to each other

  5. 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
connecting...
connected
HTTP/1.1 200 OK
Date: Thu, 14 Feb 2013 18:51:34 GMT
Server: Apache/2.2.22 (Win32) PHP/5.4.3
X-Powered-By: PHP/5.4.3
Content-Length: 132
Connection: close
Content-Type: text/html

<html>
<body>
Hello from localhost/arduino.php">
I saw your Event GET and your data:
ThisIsaTest<br />

</body>

</html>
disconnecting.

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:

  1. Make sure your running the latest Arduino. If not download it now (currently vers 1.03)

  2. Shut down your Arduino application.

  3. Download this file ( malloc.c ). You can copy/past to Notebook for this operation.

  4. 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

  5. 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.

  1. Set the Serial port (development system to Arduino) to 115,200 baud - In case there is a connection and this is needed for maintenance or development.

  2. Initialize the Shield - Set SoftwareSerial to 38,400 baud on pins 5 & 6.

  3. Set all UART 1 and USB output to zero - This brings the data transfer to a known state. It may require uploading a file from the Arduino storage.

  4. Set RATE Measurement Period to 1000 msec - This is a moderate navigation rate.

  5. Set NAV-SOL to output on UART 1 - This message contains GPSfixOK to detect when the shield has locked up.

  6. Move to Collect Position State (2)

Collect Position (2) - At the end of this state the pixel is locked and its location is known

  1. Arduino waits for NAV-SOL GPSfixOK for a valid position indication. When found it:

  2. Shuts off NAV-SOL - stops transmission of this packet to the Arduino via the UART 1

  3. Turns on NAV-POSLLH - Starts transmission of this packet which contains position data.

  4. When NAV-POSLLH is found extract the latitude, longitude and height above sea level and used from then on

  5. Shut off NAV-POSLLH - Stops the periodic sending of this command

  6. Set UBX-CFG RATE Measurement Period to 200 msec - This allows the fastest response to Events

  7. Set TIM2 output to UART 1 - Routes events to the Arduino

  8. Move to Waiting state (3)

Wait For Event (3) - Starts pixel monitoring waiting for events.

  1. Start a timeout counter - If no events occur within (TBD) minutes generate error code and go to Cold Boot

  2. Extract Parameters - Pick up time from TIM2 and add position data.

Processing Event (4) - Each event is handled as it is detected

  1. Calculate Unix time

  2. Create a Clear Data Stream

  3. Crypto - Create a Crypto String to be POSTed

  4. POST - Send the Crypto string to the remote file server

  5. Signal successful POST with TBD code

  6. Wait in this state processing events as they occur


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