Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #90 on: October 29, 2012, 08:30:36 am » |
been playing with the last part of the code, for now it looks like: if(Serial1.available() >0) // If a character comes in from the cellular module... { inchar=Serial1.read(); if (inchar=='@') // Control char, if sms does start with anything else nothing happens and the sms is deleted { delay(10); inchar=Serial1.read(); if (inchar=='a') { delay(10); inchar=Serial1.read(); if (inchar=='0') { digitalWrite(rele1, LOW); // If 0 after a then turn relay1 off Serial.println("Relay1 Off"); Tempflag = 0; // Set tempflag to 0 to avoid multiple engine ready text's } else if (inchar=='1') { digitalWrite(rele1, HIGH); // If 1 after a then turn relay1 on Serial.println("Relay1 On"); Tempflag = 1; // Set tempflag to 1 to enable engine ready text } } Serial1.println("AT+CMGD=1,4"); // Delete all SMS } } with this i can turn relay1 on and off
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 336
Posts: 36476
Seattle, WA USA
|
 |
« Reply #91 on: October 29, 2012, 08:36:56 am » |
if(Serial1.available() >0) { inchar=Serial1.read(); if (inchar=='@') { delay(10); inchar=Serial1.read(); if (inchar=='a') { delay(10); inchar=Serial1.read(); So, if there is one byte available to read, keep your fingers crossed that the next 2 arrive in the allotted time. Waste that time if the characters arrive faster than that. There are better ways.
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #92 on: October 29, 2012, 09:53:52 am » |
trouble for my mind is to figure why first part work and the rest don't
im sure i have screwed up the {'s and }'s some way that prevents the code from doing stuff when i send a text with anything other than @a1 or @a0
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #93 on: October 29, 2012, 09:57:18 am » |
i added an section that should turn the same relay on just with a text containing @b1 or @b0.. it does not work.. and sure i have done it wrong some how if(Serial1.available() >0) // If a character comes in from the cellular module... { inchar=Serial1.read(); if (inchar=='@') // Control char, if sms does start with anything else nothing happens and the sms is deleted { delay(10); inchar=Serial1.read(); if (inchar=='a') { delay(10); inchar=Serial1.read(); if (inchar=='0') { digitalWrite(rele1, LOW); // If 0 after a then turn relay1 off Serial.println("Relay1 Off"); Tempflag = 0; // Set tempflag to 0 to avoid multiple engine ready text's } else if (inchar=='1') { digitalWrite(rele1, HIGH); // If 1 after a then turn relay1 on Serial.println("Relay1 On"); Tempflag = 1; // Set tempflag to 1 to enable engine ready text } } delay(10); inchar=Serial1.read(); if (inchar=='b') { delay(10); inchar=Serial1.read(); if (inchar=='0') { digitalWrite(rele1, LOW); // If 0 after a then turn relay1 off Serial.println("Relay1 Off"); Tempflag = 0; // Set tempflag to 0 to avoid multiple engine ready text's } else if (inchar=='1') { digitalWrite(rele1, HIGH); // If 1 after a then turn relay1 on Serial.println("Relay1 On"); Tempflag = 1; // Set tempflag to 1 to enable engine ready text } } Serial1.println("AT+CMGD=1,4"); // Delete all SMS } }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 336
Posts: 36476
Seattle, WA USA
|
 |
« Reply #94 on: October 29, 2012, 09:57:26 am » |
im sure i have screwed up the {'s and }'s some way You need to use the Tools + Auto Format menu item to fix your indenting. that prevents the code from doing stuff when i send a text with anything other than @a1 or @a0 You didn't post any code to deal with other than @a0 or @a1.
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #95 on: October 29, 2012, 10:12:19 am » |
im sure i have screwed up the {'s and }'s some way You need to use the Tools + Auto Format menu item to fix your indenting. that prevents the code from doing stuff when i send a text with anything other than @a1 or @a0 You didn't post any code to deal with other than @a0 or @a1. i just did on my last post
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #96 on: October 29, 2012, 10:27:52 am » |
so i wanted to give Tools + Auto Format a try... i took the first part of the complete sketch down until void loop... it says to many right parentheses... i have looked over it many times and cant find any problems: /* TDGino Engine Preheater Control Sketch to control a Webasto BBW46 engine preheater and to send sms status messages
Created 2012 by Bo Herrmannsen
This code is in the public domain. The TDGino will need a extra input at pin 7, you will need 2 resistors and a optocoupler for this
*/ #include <GSM.h> #include <OneWire.h> #include <DallasTemperature.h>
GSM gsm;
// Set pin numbers: const int powergsm = 77; const int ctsgsm = 39; const int rtsgsm = 29; const int dcdgsm = 27; const int dtrgsm = 28; const int reset = 35; const int ring = 34; const int ld1 = 25; const int ld2 = 26; const int stato = 76; const int rele1 = 36; const int rele2 = 37; const int sda = 20; const int scl = 21; const int in1 = 84; const int in2 = 83; const int in3 = 7; const int stddtmf = 14; const int q1dtmf = 72; const int q2dtmf = 73; const int q3dtmf = 74; const int q4dtmf = 75; const int puls = 62; const int sonda = 63;
#define ONE_WIRE_BUS sonda // Data wire is plugged into port 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress insideThermometer = { 0x28, 0xF3, 0x19, 0x33, 0x03, 0x00, 0x00, 0x9E }; // Array to hold address for inside thermometer DeviceAddress outsideThermometer = { 0x28, 0xA0, 0x34, 0xC3, 0x03, 0x00, 0x00, 0x8C }; // Array to hold address for outside thermometer float tempC=0;
int Flame; // Status of pin connected to flame sensor (So we can detect if there is a flame or not) int FlameState; // Status of the flame sensor int Fan; // Status of pin connected to fan sensor (So we know when the fan is turned on by the heater) int FanState; // Status of the fan sensor int Heat; // Status of pin connected to heater(circulation pump) sensor (So we know if the heater is on - might seem odd but sometimes the heater stops early due to low fuel etc) int HeatState; // Status of the heater sensor int Oldtemp; // Temp since last flag int Oldtemp1; int Tempflag; // Trigger variable (if temp has raised by X degrees) char phone_num[20]; // Array for the phone number string char string[160]; // Array for the sms, max 160 char's char inchar; int temperature1; int temperature2;
void setup()
{ // set the digital pin as output: pinMode(powergsm, OUTPUT); pinMode(rtsgsm, OUTPUT); pinMode(dtrgsm, OUTPUT); pinMode(reset, OUTPUT); pinMode(ld1, OUTPUT); pinMode(ld2, OUTPUT); pinMode(rele1, OUTPUT); pinMode(rele2, OUTPUT); pinMode(sda, OUTPUT); pinMode(scl, OUTPUT); digitalWrite(rele1, LOW); // Set relay state to avoid false heater start on power up digitalWrite(rele2, LOW); // set the digital pin as input: pinMode(ctsgsm, INPUT); pinMode(dcdgsm, INPUT); pinMode(ring, INPUT); pinMode(stato, INPUT); pinMode(in1, INPUT); // Flame on/off pinMode(in2, INPUT); // Heater on/off pinMode(in3, INPUT); // Cabin fan on/off pinMode(stddtmf, INPUT); pinMode(q1dtmf, INPUT); pinMode(q2dtmf, INPUT); pinMode(q3dtmf, INPUT); pinMode(q4dtmf, INPUT); pinMode(puls, INPUT); // Button on board, not used so far pinMode(sonda, INPUT); // DS18B20 one wire bus digitalWrite(ld1, HIGH); // Light up LED1 to tell we are starting up Serial.begin(9600); // Start serial port at 9600 bps Serial.println("System startup"); // Write on the serial/usb port that we are powering up gsm.TurnOn(115200); // Power the GSM module on Serial.println("GSM Module are powered up"); // Write on the serial/usb port that GSM Module are powered up gsm.InitParam(PARAM_SET_1); // Configure the module Serial.println("GSM Module are Configured"); // Write on the serial/usb port that GSM Module are configured gsm.Echo(1); // Enable AT echo Serial.println("AT+CMGF=1"); // Set sms mode to text delay(30000); Serial.println("AT+CNMI=3,3,0,0"); // Set module to send SMS data to serial out upon receipt delay(200); delay(200); sensors.setResolution(insideThermometer, 12); // Set the resolution to 12 bit sensors.setResolution(outsideThermometer, 12); Serial.println("Temp. Sensors set to 12 Bit"); FlameState = digitalRead(in1); // Read the initial states HeatState = digitalRead(in2); FanState = digitalRead(in3); Tempflag = 0; digitalWrite(ld2, HIGH); // Light up LED2 to tell we are ready }
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #97 on: October 29, 2012, 10:40:56 am » |
i have looked over it many times and cant find any problems: I've looked over it just once, and can't see a "loop".
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #98 on: October 29, 2012, 10:44:32 am » |
on the main loop it says to many right curly braces but again i checked them twice and it also add up... also most part of the code works, just not the last 2 sections that checks incoming text. this is how i want my final code to be: void loop()
{ sensors.requestTemperatures(); temperature1 = sensors.getTempC(insideThermometer); // Read temp and store it in variable temperature2 = sensors.getTempC(outsideThermometer); int response=0;
Flame = digitalRead(in1); // Read value of flamesensor pin and store it in Flame Heat = digitalRead(in2); // Read value of fan sensor pin and store it in Fan Fan = digitalRead(in3); // Read value of flame sensor pin and store it in Flame
// ******************************************************** Send Temp SMS Section Start ****************************************************** if(digitalRead(in2) == 0 && temperature1 > 50) // If heater is on and coolant temp is above then send text. This is to let user know engine is now above "cold start" temp and ready. Here its set to 50 degree C { if (Tempflag = 1) { sprintf(string,"Bil klar"); // Engine Ready Text Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response); Tempflag = 0; // Tempflag set to 0 to avoid endless text's } } // ******************************************************** Send Temp SMS Section End ****************************************************** // ******************************************************** Flame Sensor Section Start ******************************************************
if (Flame != FlameState ) // The state has changed! { if (Flame == LOW) { sprintf(string,"Flame On"); Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response);
} else { sprintf(string,"Flame Off"); Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response); } FlameState = Flame; // Save the new state in our variable } // ******************************************************** Flame Sensor Section End ********************************************************
// ******************************************************** Fan Sensor Section Start ******************************************************** if (Fan != FanState ) // The state has changed! { if (Fan == LOW) { sprintf(string,"Fan On"); Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response);
} else { sprintf(string,"Fan Off"); Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response); } FanState = Fan; // Save the new state in our variable } // ******************************************************** Fan Sensor Section End *********************************************************** // ******************************************************** Heater Sensor Section Start ******************************************************
if (Heat != HeatState ) // The state has changed! { if (Heat == LOW) { sprintf(string,"Heater On"); Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response);
} else { sprintf(string,"Heater Off"); Serial.println(string); response=gsm.SendSMS("+45*********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response); } HeatState = Heat; // Save the new state in our variable } // ******************************************************** Heater Sensor Section End ********************************************************
rest of code in next post
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #99 on: October 29, 2012, 10:44:53 am » |
// ********************************************************Incoming SMS Section Start ********************************************************
if(Serial1.available() >0) // If a character comes in from the cellular module... { inchar=Serial1.read(); if (inchar=='@') // Control char, if sms does start with anything else nothing happens and the sms is deleted { delay(10); inchar=Serial1.read(); if (inchar=='a') { delay(10); inchar=Serial1.read(); if (inchar=='0') { digitalWrite(rele1, LOW); // If 0 after a then turn relay1 off Serial.println("Relay1 Off"); Tempflag = 0; // Set tempflag to 0 to avoid multiple engine ready text's } else if (inchar=='1') { digitalWrite(rele1, HIGH); // If 1 after a then turn relay1 on Serial.println("Relay1 On"); Tempflag = 1; // Set tempflag to 1 to enable engine ready text } } delay(10); inchar=Serial1.read(); if (inchar=='b') { inchar=Serial1.read(); if (inchar=='0') { digitalWrite(rele2, LOW); // If 0 after b then turn relay2 off Serial.println("Relay2 Off"); } else if (inchar=='1') { digitalWrite(rele2, HIGH); // If 1 after a then turn relay2 on Serial.println("Relay2 On"); } } delay(10); inchar=Serial1.read(); if (inchar=='t') { inchar=Serial1.read(); if (inchar=='0') // If 0 after t then send text with cabin temp { int temperature1dec=temperature1; int temperature1uni=(temperature1*100)-(temperature1dec*100); sprintf(string,"Kabinetemperatur %d.%d Grader",temperature1dec,temperature1uni); Serial.println(string); response=gsm.SendSMS("+45********",string); // +********** insert your telephone number Serial.print("response "); Serial.println(response); } else if (inchar=='1') // If 1 after t then send text with coolant temp { int temperature2dec=temperature2; int temperature2uni=(temperature2*100)-(temperature2dec*100); sprintf(string,"Kølertemperatur %d.%d Grader",temperature2dec,temperature2uni); Serial.println(string); response=gsm.SendSMS("+45********",string); //+********** insert your telephone number Serial.print("response "); Serial.println(response); } } Serial1.println("AT+CMGD=1,4"); // Delete all SMS } } }
// ********************************************************Incoming SMS Section End ********************************************************
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #100 on: October 29, 2012, 10:46:08 am » |
i have looked over it many times and cant find any problems: I've looked over it just once, and can't see a "loop". it was on purpose... i wanted to check everything before the main void/loop first and then the loop itself
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Tesla Member
Karma: 100
Posts: 6787
-
|
 |
« Reply #101 on: October 29, 2012, 10:53:21 am » |
I have looked over it many times and cant find any problems:
The parenthesis and braces look correct to me. Maybe the formatter is confused by the fact you have your code in column one and your comments about a thousand miles to the right.
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #102 on: October 29, 2012, 10:59:32 am » |
hmm.. did not think about that... on my big screen everything fits
but the main part is also that part of the main loop works and 2 sections do not
the last 2 sections with @b0 and @b1 and @t0 and t@1 are the most important ones... the one with engine ready can be left out.. think i will just make do with the status that cabin fan is on and then just wait another 15 mins after that before i go to the car
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #103 on: October 29, 2012, 11:42:08 am » |
got it... to many inchar=Serial1.read();
this caused it to only work for the first section...
give me a few to go it over and then i would very much take suggestions for cleaning up the code
|
|
|
|
|
Logged
|
|
|
|
|
Odense, Denmark
Offline
Full Member
Karma: 0
Posts: 171
|
 |
« Reply #104 on: October 29, 2012, 11:58:55 am » |
so now the sketch look like in this pastebin: http://pastebin.com/bR4hnRQrwhat i would like suggestions on first are ways to consume less power while still be able to have the same control... i know there are ways to make the code different but i wanted it as simple and understandable as i could...
|
|
|
|
|
Logged
|
|
|
|
|
|