I am trying to make my wishield do both push and pull of the data, but I got some issues with making the push dynamic. (see further down why)
#include <WString.h>
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {10,0,0,15}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"dd-wrt"}; // 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 = {"xxxxxxxxxxxxxxxxxxxxxx"}; // 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 ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL)
{
if (strcmp(URL, "/") == 0)
{
// Use WiServer's print and println functions to write out the page content
WiServer.print(analogRead(0));
WiServer.print("|");
WiServer.print(analogRead(1));
WiServer.print("|");
WiServer.print(analogRead(2));
WiServer.print("|");
WiServer.print(analogRead(3));
WiServer.print("|");
WiServer.print(millivolts(analogRead(4))); //Light sensor
WiServer.print("|");
WiServer.print(Thermister(analogRead(5))); //Converting into Celcius before printing
return true;
}
return false;
}
float millivolts(float val)
{
return (val / 204.0)*1000.0; //*1000 to convert it to millivolts
}
double Thermister(int RawADC)
{
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
long unsigned int lcdUpd;
unsigned long timeDebounce = 10000;
unsigned long inputDebounce = 0;
// 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.
Serial.print(data);
//while (len-- > 0)
//{
//Serial.print(*(data++));
//}
//delay(100);
}
//IP of my NAS
uint8 ip[] = {10,0,0,117};
//Define the request
GETrequest pullServer(ip, 80, "10.0.0.117", "");
void setup()
{
Serial.begin(9600);
Serial.print("$CLEAR\r\n");
Serial.print("$GO 1 1\r\n");
Serial.print("$PRINT mV Temp\r\n");
pullServer.setReturnFunc(printData);
// Initialize WiServer and have it use the sendMyPage function to serve pages
WiServer.init(sendMyPage);
}
void loop()
{
// Run WiServer
WiServer.server_task();
if (millis() - inputDebounce >= timeDebounce) //One minute debounce
{
inputDebounce = millis();
Here it will do the pushing of the data, but if I do
String newURL = "";
newURL.append("/arduino/logging/incomming.php?analog=");
newURL.append(analogRead(0));
newURL.append("|");
newURL.append(analogRead(1));
newURL.append("|");
newURL.append(analogRead(2));
newURL.append("|");
newURL.append(analogRead(3));
newURL.append("|");
newURL.append(analogRead(4));
newURL.append("|");
newURL.append(analogRead(5));
Serial.println(newURL);
pullServer.setURL(newURL);
pullServer.submit();
It won't work, but if I copy the url from the Serial.println(newURL); and do like this
pullServer.setURL("/arduino/logging/incomming.php?analog=367|455|485|544|77|493");
pullServer.submit();
It work as expected, what can the problem here be?
}
if ((millis() - lcdUpd) >= 500 && 1 == 2)
{
lcdUpd = millis();
Serial.print("$GO 2 1\r\n");
Serial.print("$PRINT ");
Serial.print(millivolts(analogRead(4)));
Serial.print(" \r\n");
Serial.print("$GO 2 10\r\n");
Serial.print("$PRINT ");
Serial.print(Thermister(analogRead(5)));
Serial.print("C \r\n");
Serial.print("$GO 3 1\r\n");
}
}