Show Posts
Pages: [1] 2 3 ... 12
1  Using Arduino / Networking, Protocols, and Devices / Re: Process call using Arduino Yun on: February 18, 2014, 02:35:10 am
Something wrong with my code?
2  Using Arduino / Networking, Protocols, and Devices / Re: Process call using Arduino Yun on: February 17, 2014, 03:11:31 pm
#! /bin/sh
ping -c 1 google1.com > /dev/null 2>&1
status=$?
echo $status
if [ $status -eq "0" ]
then
   # if status = 0 then write 1 inside the file "connectivity" (overwrite)
   echo "1" > connectivity
else
   echo "0" > connectivity
fi
3  Using Arduino / Networking, Protocols, and Devices / Process call using Arduino Yun on: February 17, 2014, 03:26:49 am
Hi there,
I need to run a script file in my linux side through my arduino sketch code.
The file is located in /arduino/ping.sh and it runs through terminal by "/arduino/ping.sh" and works.
But using my sketch it doesn't. Its like I cannot run the script at all.

Please check my code. I am a rookie in linux so I dont know much about it.

Code:
/*
  Running process using Process class.

 This sketch demonstrate how to run linux processes
 using an Arduino Yún.

 created 5 Jun 2013
 by Cristian Maglie

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/Process

 */

#include <Process.h>

void setup() {
  // Initialize Bridge
  Bridge.begin();

  // Initialize Serial
  Serial.begin(9600);

  // Wait until a Serial Monitor is connected.
  while (!Serial);

  // run various example processes
  runCpuInfo();
}

void loop() {
  // Do nothing here.
}


void runCpuInfo() {
  // Launch "cat /proc/cpuinfo" command (shows info on Atheros CPU)
  // cat is a command line utility that shows the content of a file
  Process p; // Create a process and call it "p"
  p.begin("/arduino/ping.sh"); // Process that launch the "cat" command
  //p.addParameter("/arduino/ping.sh"); // Add the cpuifo file path as parameter to cut
  p.run(); // Run the process and wait for its termination

  // Print command output on the Serial.
  // A process output can be read with the stream methods
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  // Ensure the last bit of data is sent.
  Serial.flush();
}
4  Using Arduino / Programming Questions / Arduino Yun - sketch Memory exceeds limits problem. on: February 15, 2014, 10:15:04 am
hi! I have a memory problem in my Arduino Yun sketch...
The problem occurs in void setup.
i have the code and the log.

When my program checks for the MAC, if MAC is not set yet (no network connection) then it starts setup again.  
By using serial monitor I noticed that every time setup runs it uses more and more ram.
The problem occurs only in void setup, and only if there is not network connection while in setup. If there is network it works fine.

What variable do I forget to clear/reset it? Any clues?

Void Setup Code:
Code:
#include <Bridge.h>
#include <HttpClient.h>
#include <SoftwareSerial.h>
  #include <EEPROM.h>
#include <Process.h>
 
 
 
//  *** USER DEFINED VARIABLES ***
char likename_def[]="Likes=";   //Important! REPLACE pch+ variables with the likename_def length!!!
char wifidef[]="WiFi Status:";
char like_counter_ver[]="U 10";  // Version 1.0
int debug_mode = 1;
 
 
 
 
char macname_def[]="MAC address:";   //Important! REPLACE pch+ variables with the likename_def length!!!
 
char idbuffer[80];
char uuid_def[]="uuid=";   //Important! REPLACE pch+ variables with the likename_def length!!!
char digitsid[35];
 
char * pchmac;
 
// These are the Arduino pins required to create a software seiral
//  instance. We'll actually only use the TX pin.
const int softwareTx = 4;
const int softwareRx = 2;
 
SoftwareSerial s7s(softwareRx, softwareTx);
 
char tempString[4];  // Will be used with sprintf to create strings
 
 
int digits =0;
char inData[150]; // Allocate some space for the string
char inChar; // Where to store the character read
int index = 0; // Index into array; where to store the character
 
 
 
char * pch;
char * pchid;
char * pchwifi;
char * maczero;
 
void setup() {
 
 Serial.print("SRAM free1 setup: ");
  Serial.println(freeRam());  
 
  char macbuffer[80];
char digitsmac[20];
 
// start reading from the first byte (romdress 0) of the EEPROM
int romdress = 10;
int multiplydress = 11;
byte romval;
byte multiplyval;
 
 
  if (debug_mode==1) {
  
      while (!Serial); // wait for a serial connection
  }
 
  Serial.begin(9600);
  // Start ethernet
  Serial.println(F("Starting ethernet..."));
 
  // Bridge takes about two seconds to start up
  // it can be helpful to use the on-board LED
  // as an indicator for when it has initialized
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  // Start bridge
  Serial.println(F("Starting bridge..."));
  Bridge.begin();
  digitalWrite(13, HIGH);
 
  Process wifiCheck;  // initialize a new process
 
  wifiCheck.runShellCommand("/usr/bin/pretty-wifi-info.lua");  // command you want to run
 
    // while there's any characters coming back from the
  // process, print them to the serial monitor:
  while (wifiCheck.available() > 0) {
    char c2 = wifiCheck.read();
    Serial.print(c2);
    inData[index] = c2; // Store it
      index++; // Increment where to write nex*-t
      // set connectLoop to zero if a packet arrives
 
      inData[index] = '\0'; // Null terminate the string
  
  }
 
//pchwifi = strstr (inData,wifidef);
 //if (pchwifi != NULL) {
 //  setup();
// }
pchmac = strstr (inData,macname_def);
maczero = strstr (inData, "00:");
  if(pchmac != NULL) {
   // Serial.print("WiFi MAC Result:");
  //Serial.println(pchmac+13);
 //digitsmac = atoi(pchmac+13);
strncpy ( digitsmac, &pchmac[13], 17 );
 memset(inData, 0, sizeof(inData));
 
index=0;
  Serial.print("macdata:");
  Serial.println(digitsmac);
 
  if (maczero != NULL) {
      Serial.println("MAC zero!");
    // strncpy ( digitsmac, &pchmac[13], 17 );
 memset(inData, 0, sizeof(inData));  
memset(digitsmac, 0, sizeof(digitsmac));  
index=0;
setup();
  } //end if maczero
  }
  else {
     Serial.println("MAC Not Found in string!");
     strncpy ( digitsmac, &pchmac[13], 17 );
 memset(inData, 0, sizeof(inData));  
memset(digitsmac, 0, sizeof(digitsmac));  
index=0;
      setup();
  }
 
 
//memset(pchmac, 0, sizeof(pchmac));
//delay(100);
  HttpClient client;
 
  // Make a HTTP request:
   strcpy(macbuffer, "http://mysite.com/bck/ctr/getuuid.php?mac=");
   strcat(macbuffer, digitsmac);
   Serial.print("MAc Buffer:");
   Serial.println(macbuffer);
   client.get(macbuffer);
  
     // if there are incoming bytes available
  // from the server, read them and print them:
  while (client.available()) {
    char c3 = client.read();
    Serial.print(c3);
    inData[index] = c3; // Store it
      index++; // Increment where to write nex*-t
      // set connectLoop to zero if a packet arrives
 
      inData[index] = '\0'; // Null terminate the string
 
  }
 
   Serial.print("inDataid:");
  Serial.println(inData);
   pchid = strstr (inData,uuid_def);
  if(pchid != NULL) {
    Serial.print("Search Result uuid:");
  Serial.println(pchid+5);
 //digits = atoi(pchid+6);
strncpy ( digitsid, &pchid[5], 35 );
 memset(inData, 0, sizeof(inData));  
index=0;
// Serial.print("Digitsid:");
 // Serial.println(digitsid);
 
 
//  delay(100);  // This will make the display update at 10Hz.
 
  }
  else {
     Serial.println("Uuid Not Found in string!");
     strncpy ( digitsid, &pchid[5], 35 );
 memset(inData, 0, sizeof(inData));  
 memset(digitsid, 0, sizeof(digitsid));  
index=0;
     setup();
     // Serial.print("Digitsid:");
 // Serial.println(digitsid);
  }
 
 
 
 
 
 
 
    Serial.println(" ");
 
 
 
 
 
 
   // read a byte from the current romdress of the EEPROM
  romval = EEPROM.read(romdress);
   multiplyval = EEPROM.read(multiplydress);
Serial.println("Reading EEPROM...");
Serial.print("EEPROM Address: ");
  Serial.print(romdress);
  Serial.print("\t");
  Serial.print(", Times Powered ON: ");
  Serial.print(romval+multiplyval*255, DEC);
  Serial.println();
// int val2 = analogRead(0) / 4;
 EEPROM.write(romdress, romval+1);
romval = EEPROM.read(romdress);
if (romval>=255) {
 multiplyval++;
romval=0;
 EEPROM.write(romdress, 0);
  EEPROM.write(multiplydress, multiplyval);
 
}
  // Must begin s7s software serial at the correct baud rate.
  //  The default of the s7s is 9600.
  s7s.begin(9600);
 
  clearDisplay();  // Clears display, resets cursor
  setDecimals(0b00000100);  // Sets digit 3 decimal on
 
  s7s.print(like_counter_ver);  // Displays -HI- on all digits
  delay(3000);
  // clearDisplay();  // Clears display, resets cursor
 
  // Clear the display, and then turn on all segments and decimals
  clearDisplay();  // Clears display, resets cursor
  s7s.print("HI  ");  // Displays -HI- on all digits
  delay(1000);
  s7s.print(" 200");
  delay(1000);
   clearDisplay();  // Clears display, resets cursor
  setDecimals(0b111111);  // Turn on all decimals, colon, apos
 
  // Flash brightness values at the beginning
 
  setBrightness(200);  // High brightness
 
 
  // Clear the display before jumping into loop
 
 
 
  delay(2000);
  Serial.println(F("Ready"));
   clearDisplay();  
setDecimals(0b00010000);  // Sets digit 3 decimal on
}

And the log:
Code:
Starting ethernet...
Starting bridge...
Current WiFi configuration
Interface name: radio0.network1
Active for: 0 minutes
MAC address: 00:00:00:00:00:00
RX/TX: 0/0 KBs
macdata:00:00:00:00:00:00
MAC zero!
SRAM free1 setup: 628
Starting ethernet...
Starting bridge...
Current WiFi configuration
Interface name: radio0.network1
Active for: 0 minutes
MAC address: 00:00:00:00:00:00
RX/TX: 0/0 KBs
macdata:00:00:00:00:00:00
MAC zero!
SRAM free1 setup: 341
Starting ethernet...
Starting bridge...
Current WiFi configuration
Interface name: radio0.network1
Active for: 0 minutes
MAC address: 00:00:00:00:00:00
RX/TX: 0/0 KBs
macdata:00:00:00:00:00:00B
Ë¥
MAC zero!
SRAM free1 setup:
5  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Yun - how to check if network connection is lost? on: February 13, 2014, 11:29:54 am
hey surfertim.
Its a good thought but i need it to be able to check it through Arduino Sketch.
6  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Yun - how to check if network connection is lost? on: February 13, 2014, 05:31:37 am
Okay, and another solution on checking network for internet connection?
7  Using Arduino / Installation & Troubleshooting / Re: How to successfully reset Arduino Yun on: February 12, 2014, 06:26:13 pm
Just found out that this caused my problem.
Code:
while (!Serial); // wait for a serial connection

So when I need to run arduino, without debugging, I have to use this.
Code:
int debug_mode=0;
if (debug_mode==1) {
   
      while (!Serial); // wait for a serial connection
  }
8  Using Arduino / Installation & Troubleshooting / How to successfully reset Arduino Yun on: February 12, 2014, 05:12:47 pm
Hi there.
I have a sketch running successfully in arduino yun , bu when I unplug the USB from my PC and plug it to a USB power adapter, It turns on, but it never starts the program sketch.
I noticed that the sketch starts only if I run the Serial Monitor on Arduino 1.5 platform.

How can I successfully reset Arduino Yun like when we unplug/plug Arduino UNO??
9  Using Arduino / Networking, Protocols, and Devices / Arduino Yun - how to check if network connection is lost? on: February 12, 2014, 04:36:01 pm
Hi there.
I just bought Yun board and I cant make the sketch check for network connectivity.
In Ethernet board all I was using was:
Code:
if(client.connected(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

  }
  else
  {
    Serial.println(F("failed to connect!"));
    
    return 0;
  }
What should I do to accomplish the same in Aruino Yun Board?
I try this with no luck:
Code:
Hi there.
I just bought Yun board and I cant make the sketch check for network connectivity.
In Ethernet board all I was using was:
[code]if(client.connected())
  {
    Serial.println(F("connected"));

  }
  else
  {
    Serial.println(F("failed to connect!"));
    
    return 0;
  }
What should I do to accomplish the same in Aruino Yun Board?[/code]
Quote
Arduino: 1.5.5-r2 (Windows 7), Board: "Arduino Yún"

yun_zoo.ino: In function 'void loop()':
yun_zoo:151: error: 'class HttpClient' has no member named 'connected'
yun_zoo:165: error: return-statement with a value, in function returning 'void'

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
10  Using Arduino / Networking, Protocols, and Devices / Re: search text in HTTP Response on: February 11, 2014, 06:46:58 pm
Thanks!!
11  Using Arduino / Networking, Protocols, and Devices / Re: search text in HTTP Response on: February 11, 2014, 06:25:18 pm
My HTTP Response will eventually more than 1 temps, and all I need to do, is to search a word in a char array and find out the pointer value of "T" if I am searching for "Temp"

My code: (keep in mind its has some testing variables that are not in use and that it uses a 7 segment too)
Code:
#include <SPI.h>
#include <Ethernet.h>


#include <SoftwareSerial.h>

// These are the Arduino pins required to create a software seiral
//  instance. We'll actually only use the TX pin.
const int softwareTx = 8;
const int softwareRx = 7;

SoftwareSerial s7s(softwareRx, softwareTx);

unsigned int counter = 0;  // This variable will count up to 65k
char tempString[10];  // Will be used with sprintf to create strings

char * pch;

// this must be unique
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// change to your network settings
IPAddress ip(192,168,10,194);
IPAddress gateway(192, 168, 10, 150);
IPAddress subnet(255, 255, 255, 0);

// change to your server
IPAddress server(134,124,157,124); // match-me.gr physical server

//Change to your domain name for virtual servers
char serverName[] = "www.mysite.gr";
// If no domain name, use the ip address above
// char serverName[] = "74.125.227.16";

// change to your server's port
int serverPort = 80;

EthernetClient client;
int totalCount = 0;
char pageAdd[64];

char *smsAT;
char inData[250]; // Allocate some space for the string
char inChar; // Where to store the character read
int index = 0; // Index into array; where to store the character

// set this to the number of milliseconds delay
// this is 30 seconds
#define delayMillis 3000

unsigned long thisMillis = 0;
unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  
  // Must begin s7s software serial at the correct baud rate.
  //  The default of the s7s is 9600.
  s7s.begin(9600);

  // Clear the display, and then turn on all segments and decimals
  clearDisplay();  // Clears display, resets cursor
  s7s.print("HI  ");  // Displays -HI- on all digits
  delay(1000);
  s7s.print(" 200");
  delay(1000);
   clearDisplay();  // Clears display, resets cursor
  setDecimals(0b111111);  // Turn on all decimals, colon, apos

  // Flash brightness values at the beginning
  setBrightness(0);  // Lowest brightness
  delay(500);
  setBrightness(127);  // Medium brightness
  delay(500);
  setBrightness(255);  // High brightness
  delay(500);

  // Clear the display before jumping into loop
  clearDisplay();  
  
  

  // disable SD SPI
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // Start ethernet
  Serial.println(F("Starting ethernet..."));
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

  // If using dhcp, comment out the line above
  // and uncomment the next 2 lines

  // if(!Ethernet.begin(mac)) Serial.println(F("failed"));
  // else Serial.println(F("ok"));
  digitalWrite(10,HIGH);

  Serial.println(Ethernet.localIP());

  delay(2000);
  Serial.println(F("Ready"));
}

void loop()
{
  thisMillis = millis();

  if(thisMillis - lastMillis > delayMillis)
  {
    lastMillis = thisMillis;

    // Modify next line to load different page
    // or pass values to server
    sprintf(pageAdd,"/temps.php",totalCount);

    // sprintf(pageAdd,"/arduino.php?test=%u",totalCount);

    if(!getPage(server,serverPort,pageAdd)) Serial.print(F("Fail "));
    else Serial.print(F("Pass "));
    totalCount++;
    Serial.println(totalCount,DEC);
  }    
}

byte getPage(IPAddress ipBuf,int thisPort, char *page)
{
  char inChar;
  char outBuf[128];

  Serial.print(F("connecting..."));

  if(client.connect(ipBuf,thisPort))
  {
    Serial.println(F("connected"));

    sprintf(outBuf,"GET %s HTTP/1.1",page);
    client.println(outBuf);
    sprintf(outBuf,"Host: %s",serverName);
    client.println(outBuf);
    client.println(F("Connection: close\r\n"));
  }
  else
  {
    Serial.println(F("failed"));
    return 0;
  }

  // connectLoop controls the hardware fail timeout
  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      inData[index] = inChar; // Store it
      index++; // Increment where to write nex*-t
      // set connectLoop to zero if a packet arrives

      inData[index] = '\0'; // Null terminate the string

      smsAT=strstr (inData,"plain");


      connectLoop = 0;
    }

    connectLoop++;

    // if more than 10000 milliseconds since the last packet
    if(connectLoop > 10000)
    {
      // then close the connection from this end.
      Serial.println();
      Serial.println(F("Timeout"));
      client.stop();
    }
    // this is a delay for the connectLoop timing
    delay(1);
  }

  Serial.println();

  Serial.println(F("disconnecting."));
  // close client end
  Serial.print("smsAT: ");
  Serial.println(smsAT);
  char Temp1[6];
  strncpy(Temp1,&inData[195],5);
  Serial.print("Temp1: ");
  Serial.println(Temp1);
  client.stop();
  int digits = atoi (Temp1);
   Serial.print("digits: ");
  Serial.println(digits);
  
  
//  ********* PROBLEM HERE!!!!!
pch = strstr (inData,"Temp1=");
Serial.println(pch);
  
  
   // Magical sprintf creates a string for us to send to the s7s.
  //  The %4d option creates a 4-digit integer.
  sprintf(tempString, "%4d", digits);

  // This will output the tempString to the S7S
  s7s.print(tempString);
  setDecimals(0b00010000);  // Sets digit 3 decimal on

  counter++;  // Increment the counter
  delay(100);  // This will make the display update at 10Hz.
  
  
  
  memset(inData, 0, sizeof(inData));  
  memset(Temp1, 0, sizeof(Temp1));  
 inChar=0;  
index=0;

  smsAT=0;




  return 1;
}


// Functions NaThAN
// Send the clear display command (0x76)
//  This will clear the display and reset the cursor
void clearDisplay()
{
  s7s.write(0x76);  // Clear display command
}

// Set the displays brightness. Should receive byte with the value
//  to set the brightness to
//  dimmest------------->brightest
//     0--------127--------255
void setBrightness(byte value)
{
  s7s.write(0x7A);  // Set brightness command byte
  s7s.write(value);  // brightness data byte
}

// Turn on any, none, or all of the decimals.
//  The six lowest bits in the decimals parameter sets a decimal
//  (or colon, or apostrophe) on or off. A 1 indicates on, 0 off.
//  [MSB] (X)(X)(Apos)(Colon)(Digit 4)(Digit 3)(Digit2)(Digit1)
void setDecimals(byte decimals)
{
  s7s.write(0x77);
  s7s.write(decimals);
}
Look at
pch = strstr (inData,"Temp1=");
Serial.println(pch);

All I need to do is to find out the pointer value that directs to the number just after "=".  Please help me on how to find out the pointer value.
12  Using Arduino / Networking, Protocols, and Devices / Re: search text in HTTP Response on: February 11, 2014, 06:23:15 pm
pch will be the index to the test string if pch is not NULL. In your case
Code:
if(pch != NULL) Serial.println(&inData[pch]);

Invalid types     char[250] [char*] for array subscript
13  Using Arduino / Networking, Protocols, and Devices / search text in HTTP Response on: February 11, 2014, 05:12:48 pm
Hi there!
I am using Ethernet Arduino and I am trying to get some number values of a webpage HTTP Response.
The only thing that I get from the response is "Temp1=25"
So I have an inData char array which contains this text.
I need to find a way to search for the text "Temp1=" and if there is in the inData array, then to point me the pointer value of "T".

I am trying     pch = strstr (inData,"Temp1="); with no luck

Whe I check if pch is 0 or not I see that its value is not zero. But I dont know how to find out the value number.
When I print pch to serial I get nothing.
14  Using Arduino / Networking, Protocols, and Devices / Re: WebClient problem contacting HTTP Server Page on: February 07, 2014, 11:37:02 am
It got it working but i am experiencing another problem. I can get text from a .txt file correctly but when I try from a .php file I get some more characters. Its a problem in parsing.

Debugging using .txt file:
Code:
HTTP/1.1 200 OK
Date: Fri, 07 Feb 2014 15:57:02 GMT
Server: Apache/2.2.14 (Ubuntu)
Last-Modified: Fri, 07 Feb 2014 15:50:56 GMT
ETag: "2485f7-4-4f1d2f4a49f11"
Accept-Ranges: bytes
Content-Length: 4
Vary: Accept-Encoding
Connection: close
Content-Type: text/plain

1478
disconnecting.
Debugging using .php file:
Code:
connecting...connected
HTTP/1.1 200 OK
Date: Fri, 07 Feb 2014 15:58:28 GMT
Server: Apache/2.2.14 (Ubuntu)
X-Powered-By: PHP/5.3.2-1ubuntu4.22
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

4
1478
0


disconnecting.
15  Using Arduino / Networking, Protocols, and Devices / WebClient problem contacting HTTP Server Page on: February 07, 2014, 09:02:51 am
Hi there. I am expieriencing a problem connecting to arduino.cc/latest.txt webpage via my Ethernet board.

I am just copy pasting arduino's example and changing my IP to my networks IP address.
Why is that happening? What should I enter in "myDns"? I just tracert the webpages IP address.
Is that right?

and the code from the example...
Code:
/*
  Repeating Web client
 
 This sketch connects to a a web server and makes a request
 using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
 the Adafruit Ethernet shield, either one will work, as long as it's got
 a Wiznet Ethernet module on board.
 
 This example uses DNS, by assigning the Ethernet client with a MAC address,
 IP address, and DNS address.
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 
 created 19 Apr 2012
 by Tom Igoe
 
 http://arduino.cc/en/Tutorial/WebClientRepeating
 This code is in the public domain.
 
 */

#include <SPI.h>
#include <Ethernet.h>

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
  0xDE, 0xAC, 0xBD, 0xEF, 0xFE, 0xED};
// fill in an available IP address on your network here,
// for manual configuration:
IPAddress ip(192,168,10,170);

// fill in your Domain Name Server address here:
IPAddress myDns(1,1,1,1);

// initialize the library instance:
EthernetClient client;

char server[] = "www.arduino.cc";

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 2*1000;  // delay between updates, in milliseconds

void setup() {
  // start serial port:
  Serial.begin(9600);
  // give the ethernet module time to boot up:
  delay(1000);
  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac, ip, myDns);
  // print the Ethernet board/shield's IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void httpRequest() {
  // if there's a successful connection:
  if (client.connect(server, 80)) {
    Serial.println("connecting...");
    // send the HTTP PUT request:
    client.println("GET /latest.txt HTTP/1.1");
    client.println("Host: www.arduino.cc");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println("disconnecting.");
    client.stop();
  }
}



Pages: [1] 2 3 ... 12