Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 28
211  Using Arduino / Programming Questions / Re: Passing a char variable to a function on: April 04, 2012, 06:07:27 am
Many Thanks PaulS

The following works :

Code:
char LCD2ah[5];  // will never hold more than 4 characters of text

strcat(LCD2ah, "Home");

LCD_2(LCD2ah, 0);

void LCD_2(char LCDdata[],int Spos){
212  Using Arduino / Programming Questions / Re: Passing a char variable to a function on: April 04, 2012, 05:51:55 am
ok. if I change the variable declaration to :
Code:
char LCD2ah[5];

then the error is: expected primary-expression before ']' token.  I really don't understand what this means.

213  Using Arduino / Programming Questions / Passing a char variable to a function on: April 04, 2012, 05:41:48 am

I have a function that receives a char and displays it on an LCD screen. The start of the function is :
Code:
void LCD_2(char LCDdata[],int Spos){

In the Loop, I call it with :
Code:
LCD_2("Home", 0);

The above solution is working, but I want to replace the "Home" (hard coded text) with a variable.

I have tried, in the pre-setup :
Code:
char LCD2ah[];

and in the loop code :
Code:
LCD2ah[] = "Home";

but it is not compiling. Where am I going wrong ?
214  Using Arduino / Project Guidance / Re: Another Home Automation... on: April 04, 2012, 04:59:17 am
Just a short note : I have also started a home automation / alarm system and you may want to consider this :

with a BlueTooth device, you have limited range.

If you instead add an ethernet shield on top of the Mega, and connect to a DSL line / router, you can have the Mega serve up a web page that you can access from your PC web browser or phone browser, from anywhere, with on/off switches for each item. You can arm / disarm the system, turn things on and off when you want away from home.

The same code can also be used to send info from your Mega to a text file stored on the internet. So you can log temperature readings, on / off or door contact readings all to your off site web server text file. A simple php page on the same server allows you to view that log file, again from anywhere that you have web access.

215  Using Arduino / Project Guidance / Re: April fools prank payback help? on: April 03, 2012, 12:06:23 pm
borrow his car keys and fill the interior air vents with confetti.
216  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 04:25:50 pm
Thanks Morris

Working like a dream now !!

Thank You so very much.

Lastly, I just have a question about this function, so that I can hopefully understand it properly :
Code:
static char hex_digit(char c)
{  return "01234567890ABCDEF"[c & 0x0F];
}

Is the purpose of this function to return either the character found in the string 01234567890ABCDEF, or if not found, then return the Hex of the 'char c' ?

If so, shouldn't the line 01234567890ABCDEF contain all 26 alpha letters, both upper and lower case ?
217  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 01:08:05 pm
couldn't add :
#include <string.h>
as it doesn't exist in my libraries.

I ran the code without it and working well, except for a few odd characters appearing :

2012-04-02---20:01:32   Setup Completed - System OperationalÝ
2012-04-02---20:01:34   Doors OpenN!

and the   =   converting to   <   in this line :
2012-04-02---20:01:33   EEProm < 0 (sms OFF+ Home)0state

I added the following to the variable :
Code:
char specials[] = "$&+,/:;=?@ <>#%{}|~[]`";

218  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 12:44:44 pm
Many Thanks all. ALMOST there.

now the line :
Code:
client.print(urlencode(buffer,LogTxt));

gives the error : invalid conversion from 'char*' to 'unsigned char*'


Should I just remove all the 'unsigned' keywords ?
219  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 12:25:40 pm
Many Thanks

Now the (hopefully) last issue is : what should be passed to :

Code:
char* urlencode(char* dst,char* src)

as it looks like it is expecting 2 variables to be passed to it.
220  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 12:12:03 pm
Code:
char specials[] = "$&+,/:;=?@ <>#%{}|~[]`"; ///* String containing chars you want encoded */

static char hex_digit(char c)
{  return "01234567890ABCDEF"[c & 0x0F];
}

char* urlencode(char* dst,char* src)
{  char *d = dst;
   while (c = *src++)
   {  if (strchr(specials,c))
      {  *d++ = '%';
         *d++ = hex_digit(c >> 4);
         *d++ = hex_digit(c);
      }
      else *d++ = c;
   }
   return dst;
}

'c' was not declared in this scope
221  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 11:56:34 am
OK. So if I get this right, I add the code sample you kindly supplied below my existing function, and change the specials value to :

Code:
unsigned char specials[] = "$&+,/:;=?@ <>#%{}|\^~[]`"; /* String containing chars you want encoded */

static unsigned char hex_digit(unsigned char c)
{  return "01234567890ABCDEF"[c & 0x0F];
}

unsigned char *urlencode(unsigned char *dst,unsigned char *src)


and in my function I add :
Code:
void LogItWebC(char* LogTxt){

  char URLed = urlencode(LogTxt);

then I get an error on compile :

Invalid conversion from 'char*' to 'unsigned char*'

I have only a basic understanding of why this is happening, but not of how to solve it.

Also, the urlencode function appears to require 2 variables passed to it ( dst and src ). What are they ? I only have 1 char ( LogTxt ) that I want encoded.
222  Using Arduino / Programming Questions / Re: URL encode char* on: April 02, 2012, 09:57:21 am
do you know if there is an available function that can do this without me needing to write code for it ?
223  Using Arduino / Programming Questions / URL encode char* on: April 02, 2012, 09:18:23 am
I have the following function which sends text to a php script. But the php script only gets the first word of the sentence.

How do I convert the LogTxt to something that the php will receive as a sentence ?

eg : sending :  this is a line, of data, 1,2,3

Code:
void LogItWebC(char* LogTxt){

  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.AAA.co.za/serveit.php?data=");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.AAA.co.za");
    client.println();
    delay(250);
    client.stop();
    Serial.println(LogTxt);
    Serial.println("disconnected");
    Serial.println("==================");
  }
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}
    
224  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: April 01, 2012, 04:07:16 pm
Then, you should probably send a close connection after the host. If you send an HTTP/1.1 request, the server may not close that end unless you send that.
Code:
  client.println("Host: www.myserver.com");
  client.println("Connection: close");
  client.println();

wouldn't the client.stop command achieve the same result as Connection: close ?

Anyway, as soon as I commented out the section starting with :
Code:
while(client.connected() && !client.available()) delay(1);

then everything worked as expected. I just can't figure out why the erratic behaviour before that.
225  Using Arduino / Networking, Protocols, and Devices / Re: Error compiling Ethernet sketch on: April 01, 2012, 03:45:47 pm
OK. Trying to understand why strange behaviour on the board.

I have the code working, but still don't understand why I had problems.

My setup :
Mega 2560
new Ethernet Shield
Port forwarding for port 82 set in the router.
Current IP xx.xx.xx.xx:82 viewed from a browser which displays the test page from the Arduino 100% OK :  Zoomkat's simple Arduino 1.0 button ON OFF
 
I had the inputs for my home panic system ( linked to a remote security company ) on pins 14 & 15
The relay that activates the radio signal is on pin 9
LCD was on 2,3,4,5,6,7
 
I moved the LCD to 18,17,16,5,6,7
Also moved the panic inputs to 2,3
 
pins 4 and 10 both empty
 
System works fine, until I try to GET data to my php page.
 
in my temperature sensor reading code, I have added the LogItWeb line here :

Code:
  float tempC1 = readTemperature(outsideThermometer);
  float tempC2 = readTemperature(insideThermometer);
  LogItC("Temp In : ",0);
  LogItF(1,tempC2,0,4);
  LogItWeb(1,tempC2);
  LogItC(" -- Out : ",0);
  LogItF(2,tempC1,1,4);

The LogItWeb goes to :
 
Code:
void LogItWeb(int Location, float LogTxt){
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.myserver.com/serveit.php?data=");
    client.print(Location);
    client.print("--");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.myserver.com");  // i found my server rejects the connection if this line is not present
    client.println();
 
    while(client.connected() && !client.available()) delay(1); //waits for data
    while (client.connected() || client.available()) { //connected or data available
      char c = client.read();
      Serial.print(c);
    }
    client.stop();
    Serial.println("disconnected");
    Serial.println("==================");
  }
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}

I can see that the ethernet code is calling the php file and writing to the txt file on my web server.
I am getting exactly as expected :
IP address : xx.xx.xx.xx 2012-04-01---12:02:27 1--26.25
 
However, once it has run once, it seems to activate my panic system relay ( pin 9) and then freezes the system. The temp readings on the LCD are not updating and I have to re-set the system.
 
Can you see anything in the LogItWeb function that would cause this erratic behaviour ?
 
What I am seeing in the Serial Monitor as soon as I reset is :
 
server/client 1.0 test 12/08/11
Send get1 in serial monitor to test client
Setup Completed - System Operational
Setup Completed - Checking SMS state
EEProm read
EEProm = 0 (sms OFF, Home)
Temp In : 26.25
connected
HTTP/1.1 200 OK
Date: Sun, 01 Apr 2012 10:02:56 GMT
Server: Apache/2.2.16 (Debian) mod_fcgid/2.3.6 mod_ssl/2.2.16 OpenSSL/0.9.8o mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.3-7+squeeze8
Content-Length: 0
Content-Type: text/html

I would expect the next line to be :
-- Out : 26.25
but it would appear that the sketch is freezing in the section where it waits for a reply from the web server.


Next, I added a short delay (250) and commented out the section of code that I think waits for a response from the web server. Everything seems to be working fine now. Could it be that because my web side php script receives the data and writes it to a web side txt file, but doesn't actually send anything back to the Arduino ?
 
I found that before this mod the Rx LED on the ethernet board was on constantly. Was that because it was always waiting for incoming data ?
 
I just don't understand why the unmodified code would activate my panic system relay on pin 9 ( activates the relay with a ground / low signal ).
 
The new function :
 
Code:
void LogItWeb(int Location, float LogTxt){
  if (client.connect(myserver, 80)) {
    Serial.println("connected");
    client.print("GET http://www.imagedisk.co.za/serveit.php?data=");
   
    client.print(Location);
    client.print("--");
    client.print(LogTxt);
    client.println(" HTTP/1.1");
    client.println("Host: www.imagedisk.co.za");
    client.println();
 
    delay(250);
 
//    while(client.connected() && !client.available()) delay(1); //waits for data
//    while (client.connected() || client.available()) { //connected or data available
//      char c = client.read();
//      Serial.print(c);
//    }
 
    client.stop();
 
    Serial.println("disconnected");
    Serial.println("==================");
  }
  else {
    Serial.println("connection failed");
    Serial.println("==================");
  }
}
Pages: 1 ... 13 14 [15] 16 17 ... 28