Jun 24, 2012 - General    No Comments

Latest Code

Notice: Undefined index: HTTP_64 in /var/www/vhosts/begerk.co.uk/httpdocs/wp-content/plugins/wp-syntax/geshi/geshi.php on line 1947

Well I thought I’d do some programming on the Arduino this weekend to find that my source code is sat at work so I’ve rewritten it and put it through it’s testing by passing over 10,000 values to my website in very quick succession without fault.

 

#include <SPI.h>
#include <Ethernet.h>
 
byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,150);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
 
 
 
EthernetClient client;
int totalCount = 0;
int loopCount = 0;
int inChar;
 
void setup() {
  Serial.begin(9600);
 
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
 
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  Serial.println("Ready");
}
 
void loop()
{
  client.connect("website.co.uk", 80);
  if(analogRead(5) > 750)
  {
    if (client.connected())
    {
      int reading = analogRead(0);  
 
      float voltage = reading * 5.0;
      voltage /= 1024.0;
 
      float temperatureC = (voltage - 0.5) * 100 ;
      char ascii[32];
      int temp1 = (temperatureC - (int)temperatureC) * 100;
      sprintf(ascii,"%0d.%d", (int)temperatureC, temp1);
      client.println("GET /webpage.php?elec=1&temp=" + String(ascii) +" HTTP/1.1\r\nHost: website.co.uk\r\n");
      totalCount++;
 
 
      Serial.println(temperatureC);
      Serial.println(analogRead(5));
 
      Serial.println(totalCount,DEC);
      while(client.available())
      {
        inChar = client.read();
        Serial.write(inChar);
      }
    }
    else
    {
      Serial.println("Client has failed");
      Serial.println(totalCount,DEC);
      client.connect("website.co.uk", 80);
    }
  }   
 client.stop(); 
}

Got anything to say? Go ahead and leave a comment!

You must be logged in to post a comment.