Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #15 on: January 09, 2013, 02:56:26 pm » |
if(strcmp(data, "on") == 0) { digitalWrite(led,HIGH); } if(strcmp(data, "off") == 0) { digitalWrite(led,LOW); // Turn the pin off Serial.println("AT+CMGD=1,4"); } What is up with the random indenting? Use Tools + Auto Format to get the code looking reasonable. Why is that AT command sent only when the light is to be turned off? Why is there a 5 second delay after receiving on or off before you do it?
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #16 on: January 09, 2013, 03:04:02 pm » |
sorry,i was a bit excited , int led = 13; int onModulePin = 9; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of SMS to send int count = 0;
int n_sms,x,sms_start; char data[256];
void switchModule(){ digitalWrite(onModulePin,HIGH); delay(2000); digitalWrite(onModulePin,LOW); }
void setup(){
Serial.begin(19200); // UART baud rate delay(2000); pinMode(led, OUTPUT); pinMode(onModulePin, OUTPUT); switchModule(); // switches the module ON
for (int i=0;i < 5;i++){ delay(5000); }
Serial.println("AT+CMGF=1"); // sets the SMS mode to text delay(1000); }
void loop(){ Serial.println("AT+CMGR"); //Reads the first SMS Serial.println("AT+CMGD=1,4"); Serial.flush(); for (x=0;x < 255;x++){ data[x]='\0'; } x=0; do{ while(Serial.available()==0); data[x]=Serial.read(); x++; if(data[x-1]==0x0D&&data[x-2]=='"'){ x=0; } }while(!(data[x-1]=='K'&&data[x-2]=='O'));
data[x-3]='\0'; //finish the string before the OK
Serial.println(data); //shows the message if(strcmp(data, "on") == 0) { digitalWrite(led,HIGH); } if(strcmp(data, "off") == 0) { digitalWrite(led,LOW); // Turn the pin off } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #17 on: January 09, 2013, 03:08:52 pm » |
You're the one with the hardware. Does it work?
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #18 on: January 09, 2013, 03:13:39 pm » |
not working ,sent sms on to shield,led pin 13 on uno does not light ,
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #19 on: January 09, 2013, 03:17:57 pm » |
Change some of your code to look like this: Serial.print("data: ["); Serial.print(data); //shows the message Serial.println("]"); if(strcmp(data, "on") == 0) { Serial.println("Turning LED on"); digitalWrite(led,HIGH); } if(strcmp(data, "off") == 0) { Serial.println("Turning LED off"); digitalWrite(led,LOW); // Turn the pin off }
Show us the serial output.
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #20 on: January 09, 2013, 03:39:26 pm » |
not working,on the serial monitor AT commands seems to stop after the first check AT+CMGF=1 AT+CMGR AT+CMGD=1,4 Stops after ist check,before kept on checking int led = 13; int onModulePin = 9; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of SMS to send int count = 0;
int n_sms,x,sms_start; char data[256];
void switchModule(){ digitalWrite(onModulePin,HIGH); delay(2000); digitalWrite(onModulePin,LOW); }
void setup(){
Serial.begin(19200); // UART baud rate delay(2000); pinMode(led, OUTPUT); pinMode(onModulePin, OUTPUT); switchModule(); // switches the module ON
for (int i=0;i < 5;i++){ delay(5000); }
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
delay(1000); }
void loop(){
Serial.println("AT+CMGR"); //Reads the first SMS Serial.println("AT+CMGD=1,4");
Serial.flush(); for (x=0;x < 255;x++){ data[x]='\0'; } x=0; do{ while(Serial.available()==0); data[x]=Serial.read(); x++; if(data[x-1]==0x0D&&data[x-2]=='"'){ x=0; } } while(!(data[x-1]=='K'&&data[x-2]=='O'));
data[x-3]='\0'; //finish the string before the OK Serial.print("data: ["); Serial.print(data); //shows the message Serial.println("]"); if(strcmp(data, "on") == 0) { Serial.println("Turning LED on"); digitalWrite(led,HIGH); } if(strcmp(data, "off") == 0) { Serial.println("Turning LED off"); digitalWrite(led,LOW); // Turn the pin off
} }
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #21 on: January 09, 2013, 04:21:07 pm » |
after adding parts to the sketch,the serial output looks like this, with the original sketch it used to continuously check but now it seems to stop after a few checks, +CFUN: 1
+CPIN: READY
Call Ready AT+CMGF=1 AT+CMGL AT+CMGD=1,4
] AT+CMGL AT+CMGD=1,4
] AT+CMGL AT+CMGD=1,4
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #22 on: January 09, 2013, 05:29:31 pm » |
after adding parts to the sketch, "I changed my code, but I'm not going to show it to you." Did I paraphrase that correctly?
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #23 on: January 10, 2013, 03:17:22 am » |
when i send sms's it works perfectly,but i have problems reading sms's and activating outputs,for some reason the loop in the sketch stops after the first check when ever i try to read the serial data,
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #24 on: January 10, 2013, 05:16:04 am » |
when i send sms's it works perfectly,but i have problems reading sms's and activating outputs,for some reason the loop in the sketch stops after the first check when ever i try to read the serial data, And, yet, still no code.
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #25 on: January 10, 2013, 07:16:34 am » |
after hours of trying,i deleted some code and ended up with this,it seems to continuously check for new sms's but when i send the shield an sms it does not show up on the serial monitor and does not switch led on,maybe my delete command wrong; int led = 13; int onModulePin = 9; // the pin to switch on the module (without press on button)
int timesToSend = 1; // Numbers of SMS to send int count = 0;
int n_sms,x,sms_start; char data[256];
void switchModule(){ digitalWrite(onModulePin,HIGH); delay(2000); digitalWrite(onModulePin,LOW); }
void setup(){
Serial.begin(19200); // UART baud rate delay(2000); pinMode(led, OUTPUT); pinMode(onModulePin, OUTPUT); switchModule(); // switches the module ON
delay(5000);
Serial.println("AT+CMGF=1"); // sets the SMS mode to text
delay(1000); }
void loop(){
Serial.println("AT+CMGR"); //Reads the first SMS Serial.println("AT+CMGD=1,4");
while(Serial.available()==0);
Serial.print("data: ["); Serial.print(data); //shows the message Serial.println("]"); if(strcmp(data, "on") == 0) { Serial.println("Turning LED on"); digitalWrite(led,HIGH); } if(strcmp(data, "off") == 0) { Serial.println("Turning LED off"); digitalWrite(led,LOW); // Turn the pin off
} }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #26 on: January 10, 2013, 07:22:55 am » |
maybe my delete command wrong; One can help with coding without understanding which AT command does what. You should have functions that send exactly one AT command. The name of the function should clearly reflect what the AT command being sent does. If Serial.println("AT+CMGR"); //Reads the first SMS reads the message, and Serial.println("AT+CMGD=1,4"); deletes it, then, yes, you have a problem with the delete command. data no longer gets a value, because you no longer actually read anything. So, the fact that sending the Arduino a SMS causes nothing to happen is not really surprising.
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #27 on: January 10, 2013, 07:25:21 am » |
ok will modify
|
|
|
|
|
Logged
|
|
|
|
|
South Africa
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #28 on: January 10, 2013, 07:37:13 am » |
ok,left out the AT command for deleting sms's,the AT+CMGR=1 reads incoming sms's but nothings displayed on the serial monitor and no switching occurs,the AT+CMGR command keeps looping on serial monitor but not reading the new sms's
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35522
Seattle, WA USA
|
 |
« Reply #29 on: January 10, 2013, 07:40:51 am » |
"OK, I made some more code changes that I'm not going to show you..." Haven't we been down this path before?
We can NOT see what you are doing.
We've hired a psychic, but he's not due to start until the 12th of never. Until then, you have to help out.
|
|
|
|
|
Logged
|
|
|
|
|
|