Code Tidy - Pastebin

New     Fork     Embed     View raw     Report

WiShield Client Reading PHP Webpage - c

Embed

You can embed this paste into a blog or website with this code:

<iframe class="codetidy" type="text/html" width="100%" src="http://codetidy.com/paste/embed/307" frameborder="0"></iframe>

Add comment

Captcha
  1. /*?
  2.  * A Gmail Notifier Robot. Based On SimpleClient?
  3.  */?
  4.  ?
  5. #include <WiServer.h>?
  6. #include <Servo.h> ?
  7.  ?
  8. Servo myservo;  // create servo object to control a servo ?
  9. Servo myservo2;  // create servo object to control a servo ?
  10.  ?
  11. #define WIRELESS_MODE_INFRA 1?
  12. #define WIRELESS_MODE_ADHOC 2?
  13.  ?
  14. // Wireless configuration parameters ----------------------------------------?
  15. unsigned char local_ip[] = {192,168,1,14};  // IP address of WiShield?
  16. unsigned char gateway_ip[] = {192,168,1,254};   // router or gateway IP address?
  17. unsigned char subnet_mask[] = {255,255,255,0};  // subnet mask for the local network?
  18. const prog_char ssid[] PROGMEM = {"Klingon Warrior"};       // max 32 bytes?
  19.  ?
  20. unsigned char security_type = 3;    // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2?
  21.  ?
  22. // WPA/WPA2 passphrase?
  23. const prog_char security_passphrase[] PROGMEM = {"DundeeDog"};  // max 64 characters?
  24.  ?
  25. // WEP 128-bit keys?
  26. // sample HEX keys?
  27. prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0?
  28.                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1?
  29.                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2?
  30.                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00  // Key 3?
  31.                 };?
  32.  ?
  33. // setup the wireless mode?
  34. // infrastructure - connect to AP?
  35. // adhoc - connect to another WiFi device?
  36. unsigned char wireless_mode = WIRELESS_MODE_INFRA;?
  37.  ?
  38. unsigned char ssid_len;?
  39. unsigned char security_passphrase_len;?
  40. String dataString;?
  41. String emailCount;?
  42. int substr;?
  43. int rotation = 140;?
  44.  ?
  45. // End of wireless configuration parameters ----------------------------------------?
  46.  ?
  47.  ?
  48. // Function that prints data from the server?
  49. void printData(char* data, int len) {?
  50.   ?
  51.   // Print the data returned by the server?
  52.   // Note that the data is not null-terminated, may be broken up into smaller packets, and ?
  53.   // includes the HTTP header. ?
  54.   while (len-- > 0) {?
  55.     //Serial.print(*(data++));?
  56.     dataString += *(data++);?
  57.     //Serial.print(len);?
  58.   }?
  59.  if(len < 0){?
  60.     substr = dataString.indexOf("#");?
  61.     //substr++;?
  62.     if (substr != -1){?
  63.       emailCount = dataString.substring(substr+1);?
  64.       //Serial.println(dataString.indexOf("#")); ?
  65.       if (emailCount == "0"){?
  66.         rotation = 140; ?
  67.       }?
  68.       else{?
  69.         rotation = 0;?
  70.       }?
  71.       Serial.print("Unread Emails:");?
  72.       Serial.print(emailCount);?
  73.       Serial.print("   RArm-Rotation:");?
  74.       Serial.print(rotation);?
  75.       Serial.println("");?
  76.     }    ?
  77.     //Serial.println(emailCount); ?
  78.     //emailCount = "";?
  79.     dataString = "";?
  80.  }?
  81. }?
  82.  ?
  83.  ?
  84. // IP Address?
  85. uint8 ip[] = {xx,xx,xx,xx};?
  86. GETrequest getCommands(ip, 80, "www.australianrobotics.com.au", "/sites/robot.php?username=xxx&password=xxxx");?
  87.  ?
  88. void setup() {?
  89.   myservo.attach(7);    //left arm ?
  90.   myservo2.attach(6);  //right arm  ?
  91.   ?
  92.   // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages) ?
  93.   WiServer.init(NULL);?
  94.   ?
  95.   // Enable Serial output and ask WiServer to generate log messages (optional)?
  96.   Serial.begin(57600);?
  97.   //WiServer.enableVerboseMode(true);?
  98.  ?
  99.   // Have the processData function called when data is returned by the server?
  100.   getCommands.setReturnFunc(printData);?
  101. }?
  102.  ?
  103.  ?
  104. // Time (in millis) when the data should be retrieved ?
  105. long updateTime = 0;?
  106.  ?
  107. void loop(){?
  108.   myservo2.write(rotation); ?
  109.   // Check if it's time to get an update?
  110.   if (millis() >= updateTime) {?
  111.     getCommands.submit();    ?
  112.     // Get another 30 secs?
  113.     updateTime += 1000 * 30;?
  114.   }?
  115.   ?
  116.   // Run WiServer?
  117.   WiServer.server_task();?
  118.   //Serial.print(dataString);?
  119.  ?
  120.   delay(10);?
  121. }?
© 2011 Code Tidy