Jump to content


redback send data to a server running php


  • Please log in to reply
4 replies to this topic

#1 Guest_bret lanius_*

Guest_bret lanius_*
  • Guests

Posted 19 May 2014 - 06:47 PM

I need to send sensor data to my php code hosted on my server. None of the examples seem to show how to do this.

#2 Guest_Guest_*

Guest_Guest_*
  • Guests

Posted 22 May 2014 - 09:49 PM

anyone? this can't be that difficult. is there at least some documentation of what commands the library supports?

#3 Young

Young

    Member

  • Members
  • PipPip
  • 14 posts

Posted 30 May 2014 - 03:16 AM

http://linksprite.co...th_Arduino_Nano

Resources

#4 blanius

blanius

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 29 June 2014 - 11:13 PM

Ok so despite the lack of documentation I did finally get something working but now I need to go to the next thing and make it useful.

 

(Example code is not the same a documentation)

 

I was successful getting the Redback to call a PHP page on my server and get the response with this code (edited out secure info)

/*
 * A simple sketch that uses WiServer to get the hourly weather data from LAX and prints
 * it via the Serial API
 */

#include <WiServer.h>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,35};	// IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,254};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"XXXXXXX"};		// max 32 bytes

unsigned char security_type = 3;	// 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"XXXXXXX"};	// max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
				  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
				};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------


// Function that prints data from the server
void printData(char* data, int len) {
  
  // Print the data returned by the server
  // Note that the data is not null-terminated, may be broken up into smaller packets, and 
  // includes the HTTP header. 
  while (len-- > 0) {
    Serial.print(*(data++));
  } 
}


// IP Address for www.weather.gov  
uint8 ip[] = {198,00,00,000};

// A request that gets the latest METAR weather data for LAX
GETrequest getAlert(ip, 80, "www.myserver.com", "/wateralert.php?message=I%20see%20water%20everywhere");


void setup() {
    // Initialize WiServer (we'll pass NULL for the page serving function since we don't need to serve web pages) 
  WiServer.init(NULL);
  
  // Enable Serial output and ask WiServer to generate log messages (optional)
  Serial.begin(57600);
  WiServer.enableVerboseMode(true);

  // Have the processData function called when data is returned by the server
  getAlert.setReturnFunc(printData);
}


// Time (in millis) when the data should be retrieved 
long updateTime = 0;

void loop(){

  // Check if it's time to get an update
  if (millis() >= updateTime) {
    getAlert.submit();    
    // Get another update one hour from now
    updateTime += 1000 * 60 * 60;
  }
  
  // Run WiServer
  WiServer.server_task();
 
  delay(10);
}

So using that as my starting point I have the following which does everything but I get either no response or I get a 404 page from the server

/*
Email not sending (could be reset is happening so quickly that it can't ))
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA	1
#define WIRELESS_MODE_ADHOC	2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};	// IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,254};	// router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};	// subnet mask for the local network
const prog_char ssid[] PROGMEM = {"XXXXX"};		// max 32 bytes

unsigned char security_type = 3;	// 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"XXXXXXX"};	// max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
					0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	0x00,	// Key 1
					0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	0x00,	// Key 2
					0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	0x00	// Key 3
								};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

const byte waterPin=7;
const byte redPin=A2;
const byte waterAnalogPin=0;
const byte resetPin=5;
int beenhere=false;

void printData(char* data, int len) {
  // Print the data returned by the server
  // Note that the data is not null-terminated, may be broken up into smaller packets, and 
  // includes the HTTP header. 
  while (len-- > 0) {
    Serial.print(*(data++));
  } 
}

uint8 bret_ip[]={198,00,00,000};

GETrequest getAlert(bret_ip, 80, "www.myserver.com", "/wateralert.php?&message=I%20see%20water%20everywhere");



void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600);
  Serial.println("StartUp");
  WiServer.init(NULL);
  WiServer.enableVerboseMode(true);
  Serial.println("Wifi enabled");
  pinMode(waterPin,INPUT);
  pinMode(redPin,OUTPUT);

  pinMode(resetPin,INPUT_PULLUP);
  digitalWrite(redPin,LOW);
  getAlert.setReturnFunc(printData);
 
}





void loop() {
  if (beenhere==true){
    Serial.println("Back in main loop");
    beenhere=false;
  }
  int water=digitalRead(waterPin);  
  
    if (water==LOW){
      Serial.println("ALERT");
     
      alert();
 
    }

 
  delay(10);
}

void noAlert(){
  noTone(6);
  digitalWrite(redPin,LOW);
  beenhere=true;
}

/*
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile ("  jmp 0");  
} 
*/
void reset(){
  Serial.println("Silenced");
  noTone(6);
  delay(500);
 
  while(digitalRead(resetPin)==HIGH){
    digitalWrite(redPin,HIGH);
    delay(500);
    digitalWrite(redPin,LOW);
    delay(500);
  }
  Serial.println("Clearing alarm");
  delay(100);
  //software_Reset();
  noAlert();
}

void alert(){
      tone(6,3000);
      delay(500);
      Serial.println("sending email");
      getAlert.submit();
          // Run WiServer
      WiServer.server_task();
        while(digitalRead(resetPin)==HIGH){
          digitalWrite(redPin,HIGH);
          delay(50);
          digitalWrite(redPin,LOW);
          delay(50);
        }
       reset();
   }



#5 blanius

blanius

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 04 July 2014 - 09:31 PM

I am an idiot, somewhere along the way I used the wrong IP address.... LOL working now.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users