Sending message to the extracted number - arduino

Please someone let me know why this code is not working. I want to extract message sender's number and then forward message to it using AT commands. It extracts the number of sender and stores it in a variable but why won't it send a message to that number?
#include <GSM.h>
GSM_SMS sms;
char RcvdMsg[200] = "";
int RcvdCheck = 0;
int RcvdConf = 0;
int index = 0;
int RcvdEnd = 0;
char MsgMob[15];
char MsgTxt[50];
int MsgLength = 0;
char number1[12] = "xxxxxxxxxx";
String number;
char inchar;
char outString[22];
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
Serial1.print("ATE0\r");
Serial1.print("AT\r");
Serial1.print("AT+CMGF=1\r");
Serial1.print("AT+CNMI=1,2,0,0,0\r");
delay(1000);
}
void loop()
{
recSms();
}
void recSms()
{
if(Serial1.available())
{
char data = Serial1.read();
if(data == '+'){RcvdCheck = 1;}
if((data == 'C') && (RcvdCheck == 1)){RcvdCheck = 2;}
if((data == 'M') && (RcvdCheck == 2)){RcvdCheck = 3;}
if((data == 'T') && (RcvdCheck == 3)){RcvdCheck = 4;}
if(RcvdCheck == 4){RcvdConf = 1; RcvdCheck = 0;}
if(RcvdConf == 1)
{
if(data == '\n'){RcvdEnd++;}
if(RcvdEnd == 3){RcvdEnd = 0;}
RcvdMsg[index] = data;
index++;
if(RcvdEnd == 2){RcvdConf = 0;MsgLength = index-2;index = 0;}
if(RcvdConf == 0)
{
Serial.print("Mobile Number is: ");
for(int x = 4;x < 17;x++)
{
number+=RcvdMsg[x];
MsgMob[x-4] = RcvdMsg[x];
}
Serial.print(number);
Serial.println();
Serial.print("Message Text: ");
for(int x = 46; x < MsgLength; x++)
{
MsgTxt[x-46] = RcvdMsg[x];
inchar=MsgTxt[x-46];
}
Serial.print(inchar);
Serial.println();
RcvdCheck = 0;
RcvdConf = 0;
index = 0;
RcvdEnd = 0;
MsgMob[15];
MsgTxt[50];
MsgLength = 0;
Serial.flush();
Serial1.flush();
if(inchar == '#')
{
sendInfo();
}
}
}
}
}
void sendInfo()
{
Serial1.print("AA");
delay(1000); //delay of 1
Serial1.println("AT");
delay(1000);
Serial1.write("AT+CMGF=1\r\n"); //set GSM to text mode
delay(1000);
Serial1.write("AT+CPMS=\"SM\"\r\n"); //Preferred SMS Message Storage
delay(1000);
Serial1.print("AT+CMGS=\"");
Serial1.print(number1);
Serial1.print("\"");
delay(1000);
Serial1.print("HI");
delay(1000);
Serial1.write(0x1A); // sends ctrl+z end of message
delay(1000);
Serial.println("sms sent ");
} //end sendInfo()

Okay so the problem seems to be with these lines:
Serial1.print("AT+CMGS=\"");
Serial1.print(number1);
Serial1.print("\"");
But if we write the lines written below, program works just fine!
Serial1.write("AT+CMGS=\"");
Serial1.print(number);
Serial1.write("\"\r");

Related

Rfid with Adafruit fingerprint together not working in Arduino Uno

I am trying to create an ATM module using Arduino. Im using a RFID reader to scan the card and Adafruit Fingerprint Module for fingerprint verification. The issue is both work but not together. Here is my code:
#include <Key.h>
#include <Keypad.h>
#include <Adafruit_Fingerprint.h>
#include <SD.h>
#include <SPI.h>
#include<SoftwareSerial.h>
SoftwareSerial mySerial(0, 1);
SoftwareSerial mySerials(2, 3);
int read_count = 0, tag_count = 0;
int j = 0, k = 0; // Variabvles to iterate in for loops
char data_temp, RFID_data[12], data_store[12];
boolean disp_control;
char filename[4], fileText[30], names[10];
int atm[5];
uint8_t n, num, p;
char key;
int p1, p2, p3, p4, z;
char fid;
File myFile;
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerials);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypads = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
finger.begin(57600);
mySerial.begin(9600);
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
Serial.println("Please Place Your Card");
}
void RecieveData()
{
if (mySerial.available() > 0)
{
data_temp = mySerial.read();
RFID_data[read_count] = data_temp;
read_count++;
}
}
void ReadData()
{
if (read_count == 12) {
disp_control = true;
for (j = 0; j < 12; j++) {
data_store[j] = RFID_data[j];
}
int x = 0;
for (int i = 9; i < 12; i++) {
filename[x] = data_store[i];
x++;
}
filename[3] = '.';
filename[4] = 't';
filename[5] = 'x';
filename[6] = 't';
filename[7] = '\0';
myFile = SD.open(filename, FILE_READ);
if (myFile) {
// read from the file until there's nothing else in it:
while (myFile.available()) {
for (int i = 0; i < 20; i++) {
fileText[i] = myFile.read();
}
int a, n = 0;
for (int i = 0; i < 4; i++) {
atm[a] = fileText[i];
a++;
}
for (int i = 5; fileText[i] != '\0'; i++) {
names[n] = fileText[i];
n++;
}
fid = fileText[4];
validate();
myFile.close();
}
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
read_count = 0;
tag_count++;
}
}
void validate() {
Serial.print("Hello ");
Serial.print(names);
Serial.println();
Serial.println();
Serial.println();
pin();
}
void pin() {
Serial.println("Please Enter Your ATM PIN");
p1 = keypads.getKey();
while (p1 == NO_KEY) {
p1 = keypads.getKey(); //UPDATE VALUE
}
Serial.print(p1 - 48);
p2 = keypads.getKey();
while (p2 == NO_KEY) {
p2 = keypads.getKey(); //UPDATE VALUE
}
Serial.print(p2 - 48);
p3 = keypads.getKey(); //UPDATE VALUE
while (p3 == NO_KEY) {
p3 = keypads.getKey(); //UPDATE VALUE
}
Serial.print(p3 - 48);
p4 = keypads.getKey(); //UPDATE VALUE
while (p4 == NO_KEY) {
p4 = keypads.getKey(); //UPDATE VALUE
}
Serial.print(p4 - 48);
Serial.println();
if ((p1 == fileText[0]) && (p2 == fileText[1]) && (p3 == fileText[2]) && (p4 == fileText[3])) {
Serial.println("Please verify Fingerprint");
}
else {
Serial.println("Invalid. Buzzer!!!!");
}
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
// found a match!
/*z = finger.fingerID;
if ((fid - 48) == z) {
Serial.println("Success");
}
else {
Serial.println("Fail");
}*/
}
void loop() {
RecieveData();
ReadData();
getFingerprintIDez();
delay(50);
}
If I initialize in this format, then fingerprint works:
mySerial.begin(9600);
finger.begin(57600);
Serial.begin(9600);
And if i do it this way, then RFID works:
finger.begin(57600);
mySerial.begin(9600);
Serial.begin(9600);
I want both of them to work i.e; I first Scan the Card, then verify pin and then it checks the validity of the fingerprint. But the issue is only one of them works at a time. If RFID works, then fingerprint doesn't even blink and if Fingerprint works, RFID doesn't read.
I'm new to this and I don't know where I am going wrong.

Storing the value read previously until new pulse

I'm currently doing a project on an Arduino Uno. The project is based on receiving an IR Signal from an IR Remote and then based on the signal received, perform other operations.
The problem is that the signal gets reset every time. I want to store the value received from the IR Remote and then resets it if detects another pulse.
Here is my code :
int brojac = 0;
int pinData = 10;
unsigned long lengthHeader;
unsigned long bit;
int byteValue;
int vrime = 1000 ;
int storeValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(pinData, INPUT);
}
void loop() {
lengthHeader = pulseIn(pinData, LOW);
if (lengthHeader > 1500)
{
for (int i = 1; i <= 32; i++) {
bit = pulseIn(pinData, HIGH);
if (i > 16 && i <= 24)
if (bit > 1000)
byteValue = byteValue + (1 << (i - 17));
}
}
Serial.print("byteValue = ");
Serial.println(byteValue);
if(byteValue == 66){
digitalWrite(11,HIGH);
}
else{
digitalWrite(11,LOW);
}
delay(vrime);
byteValue = 0;
delay(250);
}
I got the answer by storing the value in a variable until a new variable is detected.
int pinData = 10;
int led = 11;
unsigned long lengthHeader;
unsigned long bit;
int byteValue;
int storeValue = 0;
int previousValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(pinData, INPUT);
pinMode(led, LOW);
}
void loop() {
lengthHeader = pulseIn(pinData, LOW);
if (lengthHeader > 1500)
{
for (int i = 1; i <= 32; i++) {
bit = pulseIn(pinData, HIGH);
if (i > 16 && i <= 24)
if (bit > 1000)
byteValue = byteValue + (1 << (i - 17));
}
}
Serial.print("byteValue = ");
Serial.println(byteValue);
**storeValue = byteValue;
if (storeValue != 0){
previousValue = storeValue;
}
Serial.print("Previous value = ");
Serial.println(previousValue);**
byteValue = 0;
delay(500);
}

Arduino - cannot get buzzer to buzz

I've hooked up a buzzer to pin 13 & ground on my Arduino.
The "Blink" example works fine and the buzzer sounds every second off and on as expected.
However, when I try to do the same buzz with my code, I can't get it to buzz upon a specific event. This is a homegrown security system - when the door is opened, I want the Arduino to check a PHP page which returns "armed" if the system has been armed.
Everything else seems to work except the buzzer part.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xD3, 0x6C };
char serverName[] = "mysite.com";
String currentLine = "";
String armed = "No";
int nFrontWindow = 0;
int sFrontWindow = 1;
int kitchenWindow = 2;
int bedroomWindow = 3;
int frontDoor = 4;
int val0 = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int threshold0 = 20;
int threshold1 = 20;
int threshold2 = 20;
int threshold3 = 20;
int threshold4 = 20;
int breach0 = 0;
int breach1 = 0;
int breach2 = 0;
int breach3 = 0;
int breach4 = 0;
int alarm0 = 0;
int alarm1 = 0;
int alarm2 = 0;
int alarm3 = 0;
int alarm4 = 0;
EthernetClient client;
void setup() {
pinMode(13, OUTPUT);
// initialize serial communications at 9600 bps:
Serial.begin(9600);
if(Ethernet.begin(mac) == 0) { // start ethernet using mac & IP address
Serial.println("Failed to configure Ethernet using DHCP");
while(true) // no point in carrying on, so stay in endless loop:
;
}
delay(1000); // give the Ethernet shield a second to initialize
}
void loop() {
// read the analog in values:
val0 = analogRead(nFrontWindow);
val1 = analogRead(sFrontWindow);
val2 = analogRead(kitchenWindow);
val3 = analogRead(bedroomWindow);
val4 = analogRead(frontDoor);
// print the analog in values:
if (val0 > threshold0)
{
Serial.print("nFrontWindow: ");
Serial.print(val0);
Serial.print("\n");
if (alarm0)
{
if (breach0 < 10)
breach0++;
}
else
{
if (breach0 > 9)
{
alarm0 = 1;
send_alert(0);
}
else
breach0++;
}
}
else
{
if (alarm0)
{
if (breach0 > 0)
breach0--;
else
{
alarm0 = 0;
send_alert(10);
}
}
else
{
if (breach0 > 0)
breach0--;
}
}
if (val1 > threshold1)
{
Serial.print("sFrontWindow: ");
Serial.print(val1);
Serial.print("\n");
if (alarm1)
{
if (breach1 < 10)
breach1++;
}
else
{
if (breach1 > 9)
{
alarm1 = 1;
send_alert(1);
}
else
breach1++;
}
}
else
{
if (alarm1)
{
if (breach1 > 0)
breach1--;
else
{
alarm1 = 0;
send_alert(11);
}
}
else
{
if (breach1 > 0)
breach1--;
}
}
if (val2 > threshold2)
{
Serial.print("kitchenWindow: ");
Serial.print(val2);
Serial.print("\n");
if (alarm2)
{
if (breach2 < 10)
breach2++;
}
else
{
if (breach2 > 9)
{
alarm2 = 1;
send_alert(2);
}
else
breach2++;
}
}
else
{
if (alarm2)
{
if (breach2 > 0)
breach2--;
else
{
alarm2 = 0;
send_alert(12);
}
}
else
{
if (breach2 > 0)
breach2--;
}
}
if (val3 > threshold3)
{
Serial.print("bedroomWindow: ");
Serial.print(val3);
Serial.print("\n");
if (alarm3)
{
if (breach3 < 10)
breach3++;
}
else
{
if (breach3 > 9)
{
alarm3 = 1;
send_alert(3);
}
else
breach3++;
}
}
else
{
if (alarm3)
{
if (breach3 > 0)
breach3--;
else
{
alarm3 = 0;
send_alert(13);
}
}
else
{
if (breach3 > 0)
breach3--;
}
}
if (val4 > threshold4)
{
Serial.print("frontDoor: ");
Serial.print(val4);
Serial.print("\n");
if (alarm4)
{
if (breach4 < 10)
breach4++;
}
else
{
if (breach4 > 9)
{
alarm4 = 1;
send_alert(4);
}
else
breach4++;
}
}
else
{
if (alarm4)
{
if (breach4 > 0)
breach4--;
else
{
alarm4 = 0;
send_alert(14);
}
}
else
{
if (breach4 > 0)
breach4--;
}
}
delay(100);
}
void send_alert(int pin)
{
if (client.connect(serverName, 80)>0) {
client.flush();
Serial.print("\nconnected... ");
String link = "GET [PHP FILE GOES HERE]";
link += pin;
link += " HTTP/1.1";
Serial.print("Sending alert code: ");
Serial.print(pin);
Serial.print("\n\n");
client.println(link);
client.println("Host: mysite.com");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
delay(3000);
} else {
Serial.println("connection failed");
//handle this
}
Serial.print("Server response:\n");
Serial.print("----------------\n");
while(client.available()){
char c = client.read();
Serial.print(c);
currentLine += c;
if (c == '\n') {
currentLine = "";
}
if (currentLine.endsWith("armed"))
{
if (pin == 4 || pin == 3 || pin == 2 || pin == 1 || pin == 0)
{
Serial.print("\nBZZZZZZZZZZ\n");
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
}
}
Serial.print("\n----------------\n");
//else
// Serial.println("result not found");
client.stop();
client.flush();
}
I think your problem is that pin 13 is used by the Ethernet Shield. So are pin 10, 11, and 12. So use a pin other then them.
I think you problem is that you aren't generating a square wave to make sound the buzzer.
Since you are using Arduino you can just use tone() and noTone() functions, well explained in Arduino site.

Arduino mega crashes while reading somewhat large .txt from SD

I have an Arduino mega with an SD Shield and a GSM shield. I'm trying to send one sms to 200 numbers from a text file on the SD card, but the Arduino reboots every time I try to send to over 100 numbers. It doesn't crash when I try to send to 70 numbers. I only read one number at a time so I don't understand the problem. I'm pretty new to Arduino programming.
Please help me this is for a tournament. Here's the code:
#include <avr/pgmspace.h>
#include <SPI.h>
#include <SD.h>
#include <GSM.h>
#define PINNUMBER ""
GSM gsmAccess;
GSM_SMS sms;
// GSM
boolean notConnected;
//char input;
//byte input2;
//char txtContent[200];
byte i = 1;
byte f = 0;
boolean sendit;
//char senderNumber[11];
const String stopp PROGMEM = "Stopp";
//SD
char numbers[11];
//char nmbr;
int l = 0;
//Optimizing
const char q PROGMEM = '\xe5'; // å
const char w PROGMEM = '\xe4'; // ä
const char e PROGMEM = '\xf6'; // ö
const char r PROGMEM = '\xc5'; // Å
const char t PROGMEM = '\xc4'; // Ä
const char y PROGMEM = '\xd6'; // Ö
void setup() {
// txtContent[0] = '\0';
i = 0;
pinMode(53, OUTPUT);
Serial.begin(115200);
// Serial.begin(4800);
Serial.println(F("Connecting to GSM..."));
notConnected = true;
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
}
else {
Serial.println(F("Not Connected"));
delay(1000);
}
}
Serial.println(F("GSM Ready"));
if (!SD.begin(4)) {
Serial.println(F("Error with SD card"));
return;
}
Serial.println(F("SD Ready"));
delay(1000);
Serial.println(F("Write your sms and end it with * and press Send"));
Serial.flush();
}
void loop() {
char txtContent[300];
if (Serial.available() > 0 && !sendit) {
byte input2;
input2 = (int)Serial.read();
txtContent[i] = (char)input2;
if (txtContent[i] == '{') {
txtContent[i] = q;
}
else if (txtContent[i] == '}') {
txtContent[i] = w;
}
else if (txtContent[i] == '|') {
txtContent[i] = e;
}
else if (txtContent[i] == '[') {
txtContent[i] = r;
}
else if (txtContent[i] == ']') {
txtContent[i] = t;
}
else if (txtContent[i] == ';') {
txtContent[i] = y;
}
i++;
if (input2 == '*') {
// Remove the * from text.
for (int j = 0; j < sizeof(txtContent); j++) {
if (txtContent[j] == '*') {
txtContent[j] = '\0';
//Serial.println(txtContent);
}
}
sendit = true;
Serial.flush();
}
else {
sendit = false;
Serial.flush();
}
}
else if (sendit && txtContent[0] != '\0') {
int txtCount = 0;
// else if(sendit){
Serial.println(F("Sending please wait..."));
// Serial.flush();
File myFile;
myFile = SD.open("numbers.txt");
char input;
if (myFile) {
// if (myFile.available()) {
while(myFile.available()){
input = (char)myFile.read();
if (input == ',') {
sms.beginSMS(numbers);
sms.print(txtContent);
// sms.beginSMS("0704941025");
// sms.print("yo");
delay(30);
sms.endSMS();
delay(30);
Serial.println(numbers);
Serial.flush();
// Serial.flush();
for (int j = 0; j < sizeof(numbers); j++) {
if (numbers[i] != '\0') {
numbers[j] = '\0';
}
}
f = 0;
}
else {
numbers[f] = input;
f++;
}
}
myFile.close();
Serial.println(F("All texts have been sent."));
Serial.flush();
} else {
Serial.println(F("error opening numbers.txt"));
}
for (int j = 0; j < sizeof(txtContent); j++) { // Clear text
txtContent[j] = '\0';
}
i = 0;
sendit = false;
}
else {
// delay(1000);
if (sms.available()) {
char senderNumber[11];
sms.remoteNumber(senderNumber, 11);
if (sms.peek() == 'S') {
Serial.print(F("Detta nummer har skickat Stopp: "));
Serial.println(senderNumber);
}
sms.flush();
Serial.flush();
// sendit = false;
}
}
}
Arduino is a strange ground for me but if that is anything like C, then i risk saying sizeof(numbers) will likely return 44, because you're asking for the size of an array in bytes, this probably means your for loop will iterate up to numbers[43] when numbers[] length is 11. Consider this instead:
for (int j = 0; j < sizeof(numbers)/sizeof(numbers[0]); j++) {
Same goes for all the other times you check for the size of an array in this code.
Also, do double check your textfile to ensure its really written in your expected format: 11 numbers then a comma, with no exception. You should maybe try to figure out if f went past 11 digits before hitting a comma and "Fail gracefully" with an error message.

Initializer-string for array of chars is too long error on Arduino

I am trying to run a code below on Arduino but when I verify the code, it shows,
'Initializer-string for array of chars is too long'.
Although I have read previous questions regarding similar issues, I couldn't know where to begin in the code I am trying now. Yes,,, I am very new to C++ world,,, If you can give me a clue to teach myself or a direct answer, it would be amazingly appreciated.
Best,
/**** SET YOUR MAC ADDRESS HERE ****/
char mac[13] = "74-E5-43-BE-42-10";
/***********************************/
#define LED 13
#define BLUESMIRFON 2
#define FACTORYRESETBAUD 57600
#define DEFAULTBAUD 115200
char str[3];
char passkey[5] = "0000";
boolean success = false;
int failOuts[10] = {3,4,5,6,7,8,9,10,11,12};
void setup()
{
//Initialize pins
pinMode(LED, OUTPUT);
pinMode(BLUESMIRFON, OUTPUT);
for (int i=0; i<10; i++) {
pinMode(failOuts[i], OUTPUT);
}
// First reset to factory defaults
while (!success) {
RunBlueSmirfSetup(true);
}
success = false;
// Then set up with the correct mac address
RunBlueSmirfSetup(false);
}
void loop() {
if(success) {
digitalWrite(LED,LOW);
delay(1000);
digitalWrite(LED,HIGH);
delay(1000);
}
}
void RunBlueSmirfSetup(boolean factoryReset) {
//Initialize serial ports
if (factoryReset) {
Serial.begin(FACTORYRESETBAUD);
} else {
Serial.begin(DEFAULTBAUD);
}
digitalWrite(BLUESMIRFON, LOW);
delay(2000);
digitalWrite(BLUESMIRFON, HIGH);
delay(2000); //Wait for BlueSMIRF to turn on
Serial.print('$'); //Send command to put BlueSMIRF into programming mode
Serial.print('$');
Serial.print('$');
delay(100);
Serial.flush();
//Reset the module
if (factoryReset) {
Serial.print('S');
Serial.print('F');
Serial.print(',');
Serial.print('1');
Serial.print('\r');
while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
success = true;
} else {
success = false;
digitalWrite(failOuts[0],HIGH);
}
delay(100);
Serial.flush();
} else {
//Set the baudrate
Serial.print('S');
Serial.print('U');
Serial.print(',');
Serial.print('5');
Serial.print('7');
Serial.print('\r');
while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
success = true;
} else {
success = false;
digitalWrite(failOuts[1],HIGH);
}
delay(100);
Serial.flush();
//Set the remote MAC address
Serial.print('S');
Serial.print('R');
Serial.print(',');
for(int i = 0; i < 12; i++) {
Serial.print(mac[i]);
}
Serial.print('\r');
while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
success = true;
} else {
success = false;
digitalWrite(failOuts[2],HIGH);
}
delay(100);
Serial.flush();
//Set the passkey
Serial.print('S');
Serial.print('P');
Serial.print(',');
for(int i = 0; i < 4; i++) {
Serial.print(passkey[i]);
}
Serial.print('\r');
while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
success = true;
} else {
success = false;
digitalWrite(failOuts[3],HIGH);
}
delay(100);
Serial.flush();
//Set the BlueSMiRF mode
Serial.print('S');
Serial.print('M');
Serial.print(',');
Serial.print('3');
Serial.print('\r');
while(Serial.available() < 3);
str[0] = (char)Serial.read();
str[1] = (char)Serial.read();
str[2] = (char)Serial.read();
if(str[0] == 'A' && str[1] == 'O' && str[2] == 'K') {
success = true;
} else {
success = false;
digitalWrite(failOuts[4],HIGH);
}
delay(100);
Serial.flush();
delay(100);
//Exit command mode
}
Serial.print('-');
Serial.print('-');
Serial.print('-');
Serial.print('\r');
//delay(100);
//Serial.flush();
//delay(100);
//Serial.end();
//digitalWrite(BLUESMIRFON, LOW);
}
CleanProgramBlueSMiRF CleanProgramBlueSMiRF
It would help if you copied the exact error message including the line number.
I assume it is failing on:
char mac[13] = "74-E5-43-BE-42-10";
since it has 17 chars between the quotes and you allocated 13.

Resources