Charles Dejardin
/
xbeerx
Wireless data sending
Fork of xberx by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* LIBRARIES */ 00002 #include "mbed.h" 00003 #include "C12832.h" 00004 #include "string.h" 00005 /*--------------------*/ 00006 00007 /*OUTPUT AND INPUT CONFIGURATION*/ 00008 Serial xbee1(p9, p10); //pin declaration for the xbee module on the board 00009 Serial cinterion(p13,p14); //pin declaration for the cinterion module on the board 00010 DigitalOut myled(LED1); //pin declaration for the blinking LED on the board 00011 DigitalOut myled2 (LED2); 00012 DigitalOut myled3 (LED3); 00013 DigitalOut myled4 (LED4); 00014 C12832 lcd(p5, p7, p6, p8, p11); //pin declaration for the LCD screen on the board 00015 /*--------------------------*/ 00016 00017 /*FUNCTION PROTOTYPE*/ 00018 float decryption (float sens2, char sens); 00019 /*----------------------*/ 00020 00021 /*VARIABLES DEFINITION*/ 00022 char X; //definition of a character 00023 char temp,volt,current,lumi; //definition of four variables matching the 4 differents type of data that the board receive 00024 float temp2, current2,volt2, lumi2; // which are temperature, voltage, current, and luminosity 00025 char NumTel[] = "07404054906"; //Mobile number to which the values will be sent 00026 char inchar,inchar1,inchar2,inchar3,inchar4,inchar5; // variables used for the SMS 00027 /*-----------------------------------------*/ 00028 00029 00030 /*------------*/ 00031 /*MAIN PROGRAM*/ 00032 /*------------*/ 00033 00034 00035 void FlushGSM(void) { char char1 = 0; while (cinterion.readable()) { char1 = cinterion.getc(); } return; } //function that clean out the reception buffer of the SIM card 00036 00037 00038 //----CALLBACK FUNCTIONS----// 00039 //This one will interrupt the program when the cinterion will be receiving a SMS// 00040 void callback2() 00041 { 00042 inchar = cinterion.getc(); // I am copying several value to be sure that this is the right command 00043 inchar1 = cinterion.getc(); 00044 inchar2 = cinterion.getc(); 00045 inchar3 = cinterion.getc(); 00046 inchar4 = cinterion.getc(); 00047 inchar5 = cinterion.getc(); 00048 if ((inchar == 0x0D)&&(inchar1 == 0x0A)&&(inchar2 == '+')&&(inchar3 == 'C')&&(inchar4 == 'M')&& (inchar5 == 'T')) // if the incoming command is "+CMTI", a new SMS has been received 00049 { 00050 myled4=1; 00051 cinterion.printf("AT+CMGD=1"); //AT command to delete the last SMS, to never be out of space 00052 cinterion.putc(0x0D); //"enter" 00053 wait(1); 00054 FlushGSM(); //clear the reception buffer 00055 wait(0.5); 00056 cinterion.printf("AT+CMGF=1"); //Text mode activated for the SMS 00057 cinterion.putc(0x0D); //"enter" 00058 wait(1); 00059 myled2=1; 00060 cinterion.printf("AT+CMGS=%s", NumTel); //AT command to send a SMS to the mobile number set 00061 cinterion.putc(0x0D); //"enter" 00062 wait(1) ; 00063 cinterion.printf("Temperature: %.2f, Current: %.2f,Voltage: %.2f, Luminosity: %.2f" , temp2, current2, volt2, lumi2); //the results are send by SMS 00064 cinterion.putc(0x1A); //ASCII code for Ctrl+Z 00065 wait(5); //there are a lot of delays, to be sure that the command are sent 00066 myled2=0; 00067 FlushGSM(); //clear the reception buffer 00068 myled4=0; 00069 00070 } 00071 } 00072 00073 00074 00075 //This one will interrupt the program when the xbee will be receiving data// 00076 void callback() 00077 { 00078 X = xbee1.getc(); //the values received are put into the X variable 00079 if (X == 0xEE) //if X equals the start bit 00080 { myled = 1; 00081 temp = xbee1.getc(); //the next value that the xbee receive is the temperature, then the current, the voltage and finally the luminosity 00082 current = xbee1.getc(); 00083 volt = xbee1.getc(); 00084 lumi = xbee1.getc(); 00085 00086 temp2 = decryption(temp2, temp); //decryption of the values received 00087 current2 = decryption(current2, current); 00088 volt2 = decryption (volt2, volt) ; 00089 lumi2 = decryption(lumi2, lumi); 00090 } 00091 00092 if (X == 0xFF) //if X equals the final bit 00093 { 00094 myled = 0; //LED is off when the string stops 00095 lcd.cls(); 00096 lcd.locate(0,0); 00097 lcd.printf("Temperature: %.2f, Current: %.2f,Voltage: %.2f, Luminosity: %.2f" , temp2, current2, volt2, lumi2); //the board monitor the results on the LCD Screen 00098 xbee1.printf("Temperature : %f , Current : %f , Voltage : %f , Luminosity : %f " , temp2, current2, volt2, lumi2); //the board sends the results to the PC thanks to the xbee 00099 } 00100 } 00101 00102 00103 00104 float decryption(float sens2, char sens) // decryption function 00105 { 00106 sens >>=2; //shift bit to the right 00107 sens2 = (float)sens/50 ; //division 00108 return sens2; 00109 } 00110 00111 00112 00113 //----MAIN FUNCTION----// 00114 int main() 00115 { 00116 cinterion.printf("AT+CNMI=1,1,0,0,1"); //configure the cinterion board to be warned when a new SMS is received 00117 cinterion.putc(0x0D); // ASCII code for the "enter" key 00118 FlushGSM(); // clear the reception buffer 00119 00120 while (1) //Neverending loop 00121 { 00122 xbee1.attach(&callback); //call of the xbee callback function 00123 cinterion.attach(&callback2); //call of the cinterion callback function 00124 wait(1); 00125 } 00126 } 00127 00128 00129 00130
Generated on Fri Jul 29 2022 01:21:12 by 1.7.2