// Initiating the GSM module void initGSM(void) { sendATCommand(strlen(AT_Test),AT_Test); Delay(); sendATCommand(strlen(AT_ConfSMS),AT_ConfSMS); sendATCommand(strlen(AT_ConfJakob),AT_ConfJakob); //GET EEPROM FUnction to be created! }
/* This will tell ESP module to connect to the WiFi network. */ boolean RemoteHomeWifi::joinNetwork(String ssid, String password, String ip) { cleanSerialBuffer(); if (ip.length() == 0) { //enable dhcp sendATCommand(AT_ENABLE_DHCP, ANSWER_OK); } else { //disable dhcp and set ip sendATCommand(AT_DISABLE_DHCP, ANSWER_OK); printString(AT_SET_IP_ADDR); printStr(ip); printString(AT_QUOTATION_MARK); printString(CRLF); _ser.find(ANSWER_OK); } printString( AT_JOIN_AP_PARAMS); printStr(ssid); printString(AT_QUOTATION_MARKS_WITH_COMMA); printStr(password); printString(AT_QUOTATION_MARK); printCrLf(); _ser.setTimeout(19000); boolean ret = _ser.find(ANSWER_OK); setDefaultSerialTimeout(); delay(20); return ret; }
bool PHN_Sim::sendMessage(const char* receiverAddress, const char* messageText) { char command[300]; int index; // Set to text message mode if (!sendATCommand("AT+CMGF=1")) { return false; } // Write the message start command containing the receiver address // No further response happens, use writeATCommand instead of sendATCommand index = 0; index += strcpy_count(command+index, "AT+CMGS="); command[index++] = '"'; index += strcpy_count(command+index, receiverAddress); command[index++] = '"'; command[index++] = '\r'; command[index++] = '\n'; command[index++] = 0; if (!writeATCommand(command)) { return false; } // Wait until the > token is read indicating SIM is ready for the message readToken("\r\n> ", 100); // Write the text message, with end token. Message is echo'd back by the SIM. // Response includes '+CMGS: 70', where 70 is the index of the message // We are discarding this response here index = 0; index += strcpy_count(command+index, messageText); command[index++] = 0x1A; command[index++] = 0; return sendATCommand(command, 0, 0, SIM_ATCOMMAND_SENDTEXT_TIMEOUT); }
/** Collect information of the XBee connected to this board. To get this information use the separate commands such as getMyID() **/ void LithneClass::getMyInfo() { sendATCommand( atSH ); sendATCommand( atSL ); sendATCommand( atMY ); sendATCommand( atID); sendATCommand( atAI ); }
void PHN_Sim::reset() { //TODO: Does this preserve options such as volume? // Reset to factory defaults sendATCommand("AT&F"); // Turn on extended +CRING information sendATCommand("AT+CRC=1"); // Turn on the incoming call information readout sendATCommand("AT+CLIP=1"); // Automatically receive messages when SMS is received sendATCommand("AT+CNMI=3,1"); }
/** Returns the own 64-bit Serial Address of the XBee connected **/ XBeeAddress64 LithneClass::getMyAddress64( bool forceCheck ) { /* If the address is unknown, or if we force a recheck. */ if( myAddress64.getLsb() == UNKNOWN_64B || forceCheck ) { uint32_t msb = sendATCommand( atSH, 1000 ); //We want to wait for an answer uint32_t lsb = sendATCommand( atSL, 1000 ); //We want to wait for an answer myAddress64 = XBeeAddress64( msb, lsb ); // Serial.print("myadd is now: "); // Serial.println(myAddress64.getLsb()); } return myAddress64; }
// Turn Echo ON or OFF int MG2639_Cell::setEcho(uint8_t on) { int iRetVal; if (on) // Send the Echo on command sendATCommand(ENABLE_ECHO); else // Or send the echo off command sendATCommand(DISABLE_ECHO); // Max response for both echo on and off is 11. // (Depending on whether echo is already on or off) iRetVal = readWaitForResponse(RESPONSE_OK, COMMAND_RESPONSE_TIME); return iRetVal; }
bool PHN_Sim::isSimCardInserted() { char resp[20]; if (!sendATCommand("AT+CSMINS?", resp, sizeof(resp))) { return false; } return resp[2] == '1'; }
/* configureGPRS() - configures GPRS connection with login, password and some other parameters * * This function creates a GPRS connection with the carrier server to get access to the internet * * It modifies 'flag' if expected answer is not received after sending a command to GPRS module * * Returns '1' on success and '0' if error */ uint8_t WaspGPRS::configureGPRS() { char command[100]; char aux='"'; uint8_t answer=0; flag &= ~(GPRS_ERROR_CONF); sprintf(command,"%s0,%c%s%c,%c%s%c,%c%s%c,%c%s%c,%c%s%c",AT_GPRS_CONN_CFG,aux, AT_GPRS,aux,aux,AT_GPRS_APN,aux,aux,AT_GPRS_LOGIN,aux,aux,AT_GPRS_PASSW,aux,aux,AT_GPRS_IP,aux); answer=sendATCommand(command,AT_GPRS_CONN_CFG_R); switch(answer) { case 0 : flag |= GPRS_ERROR_CONF; return 0; break; case 2 : flag |= GPRS_ERROR_CONF; return 0; break; } if(!setConnectionTimer()) return 0; if(!setConnectionProfile()) return 0; if(!checkGPRS()) return 0; if(!setPattern(GPRS_PATTERN)) return 0; if(flag & GPRS_ERROR_CONF) return 0; return 1; }
bool PHN_Sim::setContact(int contactIndex, SimContact contact) { //AT+CPBW=([index]),"[address]",[type],"[name]" // Convert some things to a string array buffer char idxPart[6]; char typePart[6]; if (contactIndex == -1) { idxPart[0] = 0; } else { itoa(contactIndex+this->bookOffset, idxPart, 10); } itoa(contact.type, typePart, 10); // Generate a list of Strings to concatenate const int parts_count = 9; const char* parts[parts_count]; parts[0] = "AT+CPBW="; parts[1] = idxPart; parts[2] = ",\""; parts[3] = contact.number; parts[4] = "\","; parts[5] = typePart; parts[6] = ",\""; parts[7] = contact.text; parts[8] = "\""; // Concatenate into a single command and send char command[100]; command[0] = 0; for (int i = 0; i < parts_count; i++) { strcat(command, parts[i]); } return sendATCommand(command); }
/* Initial setup. */ void RemoteHomeWifi::setup() { nodeId = EEPROM.read(EEPROM_POSITION_NODE_ID); if (nodeId == 255) nodeId = 0; pinMode(ENABLE_PIN, OUTPUT); enable(); cleanVariablesAfterProcessing(); delay(1010); for (int i=0;i<3;i++) printString(AT_PLUS_MARK); delay(1010); sendATCommand(AT_CMD_RST, ANSWER_READY); pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); if (!waitToConnectToNetwork(50)) { connectedToWifi = false; becomeAdHocNetwork(); digitalWrite(LED, LOW); delay(1000); digitalWrite(LED, HIGH); delay(1000); digitalWrite(LED, LOW); } else { setSingleJoinNetwork(); connectedToWifi = true; digitalWrite(LED, LOW); } setDefaultSerialTimeout(); listenOnPort(); }
/* deleteSocket(socket) - deletes the socket specified by 'socket' * * This function deletes the socket specified by 'socket' * * It modifies 'flag' if expected answer is not received after sending a command to GPRS module * * Returns '1' on success and '0' if error */ uint8_t WaspGPRS::deleteSocket(uint8_t* socket) { char command[30]; long previous=0; uint8_t answer=0; uint8_t byteIN=0; uint8_t i=0; setInfoIncomingCall(); flag &= ~(GPRS_ERROR_DELETE); while(socket[i]!='\r') i++; switch(i) { case 1: sprintf(command,"%s%c",AT_GPRS_TCP_DEL,socket[0]); break; case 2: sprintf(command,"%s%c%c",AT_GPRS_TCP_DEL,socket[0],socket[1]); break; case 3: sprintf(command,"%s%c%c%c",AT_GPRS_TCP_DEL,socket[0],socket[1],socket[2]); break; } answer=sendATCommand(command,AT_GPRS_TCP_DEL_R); switch(answer) { case 0 : flag |= GPRS_ERROR_DELETE; break; case 2 : flag |= GPRS_ERROR_DELETE; break; } if(flag & GPRS_ERROR_DELETE) return 0; return 1; }
void XBeeInit(){ char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""}; int i = 0; int j; UART_Init(); while (RxFifo_Size()>0){ //flush FIFO UART_InChar(); } ID = 1; UART_OutString("x"); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); //SysTick_Wait10ms(110); //wait waitTime number of ms; sendATCommand("+++", 110, 0); //UART_InString(response, 5); //RIT128x96x4StringDraw(response, 10, 10 , 15); for (i=0;i<5;i++){ sendATCommand(commands[i], 20, 1); } SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); SysTick_Wait10ms(10); }
/** Returns the association status of the XBee **/ uint16_t LithneClass::getMyAssociationStatus( bool forceCheck ) { if( myAssStat == UNKNOWN_STATUS || forceCheck ) { //We request the association status and wait 1 second for a response myAssStat = sendATCommand( atAI, 1000 ) & 0xFFFF; } return myAssStat; }
/** Returns the 16-bit address of the own node **/ uint16_t LithneClass::getMyAddress16( bool forceCheck ) { if( myAddress16 == UNKNOWN_16B || forceCheck ) { //We request the 16-bit address and wait 1 second for a response myAddress16 = sendATCommand( atMY, 1000 ) & 0xFFFF; } return myAddress16; }
Date PHN_Sim::getDate() { Date date; char resp[40]; char* args[1]; if (sendATCommand("AT+CCLK?", resp, 40) && getSimTextArgs(resp, args, 1) == 1) { date = readDate(args[0]); } return date; }
/** Returns the PAN ID of the xbee network **/ uint16_t LithneClass::getMyPAN( bool forceCheck ) { if( myPANid == UNKNOWN_PAN_ID || forceCheck ) { //We request the PAN ID and wait 1 second for a respons myPANid = sendATCommand( atID, 1000 ) & 0xFFFF; } return myPANid; }
int PHN_Sim::getRegStatus() { char resp[50]; char *regArgs[2]; sendATCommand("AT+CREG?", resp, sizeof(resp)); if (getSimTextArgs(resp, regArgs, 2) == 2) { return atoi(regArgs[1]); } return 0; }
void PHN_Sim::sendDTMF(char character) { if (character) { char command[9]; memcpy(command, "AT+VTS=", 7); command[7] = character; command[8] = 0; sendATCommand(command, 0, 0, SIM_ATCOMMAND_DTFM_TIMEOUT); } }
/* This will establish the connection to the http server. For the programming, the transparent data mode needs to be used. If the parameter is true, then the programming mode is used. */ boolean RemoteHomeWifi::establishConnectionToServer(boolean progPort, const int ip, const int port) { cleanSerialBuffer(); _ser.setTimeout(10000); if (progPort) { sendATCommand(AT_SET_SERVER_DISABLE, "\n"); sendATCommand(AT_CMD_RST, ANSWER_READY); waitToConnectToNetwork(20); sendATCommand(AT_SET_SINGLE_CONNECTION, ANSWER_OK); sendATCommand(AT_SET_DATA_MODE, ANSWER_OK); printString(AT_CREATE_SINGLE_TCP_CONNECTION); } else { communicationChannelId = 1; printString(AT_CREATE_TCP_CONNECTION); } _ser.print(EEPROM.read(ip), DEC); for (int i=1;i<4;i++) { _ser.print('.'); _ser.print(EEPROM.read(ip+i), DEC); } printString(AT_QUOTATION_MARK); printString(AT_COMMA); char* portValue; portValue = readIntFromEEPROM(port); _ser.print(portValue); printCrLf(); if (_ser.find(ANSWER_OK)) { if (!progPort) { prepareDataToSend(outputString.length()); printStr(outputString); _ser.find(ANSWER_DATA_OK); setDefaultSerialTimeout(); closeConnection(); cleanSerialBuffer(); } else { sendATCommand(AT_SEND_DATA_SINGLECH, AT_STARTDATA); } setDefaultSerialTimeout(); return true; } else { setDefaultSerialTimeout(); return false; } }
void PHN_Sim::call(const char* address) { // Set up the command to execute int address_len = strlen(address); char cmd[30] = "ATD"; memcpy(cmd+3, address, min(address_len, 30-5)); cmd[address_len+3] = ';'; cmd[address_len+4] = 0; if (sendATCommand(cmd)) callStatus = SIM_CALL_STATUS_CALLING; }
float PHN_Sim::readBatteryLevel() { char resp[30]; char *args[3]; if (!sendATCommand("AT+CBC", resp, sizeof(resp))) { return 0.0F; } if (getSimTextArgs(resp, args, 3) != 3) { return 0.0; } return 0.01 * atoi(args[1]); }
int PHN_Sim::getContactCount() { // Response: +CPBS: "<storage>",<used>,<total> char resp[50]; if (!sendATCommand("AT+CPBS?", resp, sizeof(resp))) { return 0; } char* args[3]; if (getSimTextArgs(resp, args, 3) != 3) { return false; } return atoi(args[1]); }
int PHN_Sim::getMessageLimit() { // Response: +CPMS: <used_space>,<max_space> char resp[50]; if (!sendATCommand("AT+CPMS=\"SM\"", resp, sizeof(resp))) { return 0; } char* args[2]; if (getSimTextArgs(resp, args, 2) != 2) { return false; } return atoi(args[1]); }
/* setMode(uint8_t) - Sets GPRS Power Mode * * This function selects the active power mode among: ON, SLEEP/HIBERNATE and OFF * It does not close the serial port, only sends the proper command to GPRS module * * It modifies 'flag' if expected answer is not received after sending a command to GPRS module * * Returns '1' on success and '0' if error */ uint8_t WaspGPRS::setMode(uint8_t pwrMode) { _pwrMode=pwrMode; flag &= ~(GPRS_ERROR_POWER); uint8_t answer=0; switch(_pwrMode) { case GPRS_ON : pinMode(GPRS_PW, OUTPUT); digitalWrite(GPRS_PW, HIGH); delay(2500); digitalWrite(GPRS_PW, LOW); delay(500); answer=1; break; case GPRS_HIBERNATE : answer=sendATCommand(POWER_HIBERNATE,POWER_R); switch(answer) { case 0 : flag |= GPRS_ERROR_POWER; break; case 2 : flag |= GPRS_ERROR_POWER; break; } break; case GPRS_SLEEP : answer=sendATCommand(POWER_SLEEP,POWER_R); switch(answer) { case 0 : flag |= GPRS_ERROR_POWER; break; case 2 : flag |= GPRS_ERROR_POWER; break; } break; } return answer; }
bool PHN_Sim::enterPin(const char* pin) { // Build the enter pin command char command[50]; String commandStr; commandStr += "AT+CPIN="; commandStr += pin; commandStr.toCharArray(command, sizeof(command)); if (sendATCommand(command) && (getPinStatus() == SIM_PIN_STATUS_READY)) { return true; } return false; }
void XBeeInit(){ char * commands [] = {"ATDL66", "ATDH0", "ATMY6D", "ATAP1", "ATCN", ""}; int i = 0; int j; unsigned long i44 = 0; unsigned long j44 = 0; unsigned long delay = 110; // SysTick_Init(); UART_Init(); while (RxFifo_Size()>0){ //flush FIFO UART_InChar(); } ID = 1; UART_OutString("x"); // volatile unsigned long dummy = 0; for (i44 = 0; i44 < delay; i44++) for (j44 = 0; j44 < 150000; j44++); // dummy ++ ; //wait10ms(110); // Delay(5500000); //SysTick_Wait10ms(110); //wait waitTime number of ms; sendATCommand("+++", 110, 0); //UART_InString(response, 5); //RIT128x96x4StringDraw(response, 10, 10 , 15); for (i=0;i<5;i++){ sendATCommand(commands[i], 20, 1); } for (i44 = 0; i44 < delay; i44++) for (j44 = 0; j44 < 150000; j44++); // Delay(55000000); }
// initialize the XBee module void XBee_Init() { sendATCommand("X"); wait1ms(2980); sendATCommand("+++"); wait1ms(2980); sendATCommand("ATDL4F\r"); sendATCommand("ATDH0\r"); // Sets destination high address to 0 sendATCommand("ATMY4E\r"); // Sets my address to 78 sendATCommand("ATAP1\r"); // API mode 1 (sends/receive packets) sendATCommand("ATCN\r"); // Ends command mode }
int PHN_Sim::getPinStatus() { char resp[30]; if (sendATCommand("AT+CPIN?", resp, 30)) { // Read status if (!strcmp(resp, "READY")) { return SIM_PIN_STATUS_READY; } else if (!strcmp(resp, "SIM PIN")) { return SIM_PIN_STATUS_NEEDPIN; } else if (!strcmp(resp, "SIM PUK")) { return SIM_PIN_STATUS_NEEDPUK; } } return SIM_PIN_STATUS_ERROR; }
bool PHN_Sim::setContactBook(const char* bookName) { // Compose command to switch to a different contact book char command[40]; int bookLen = strlen(bookName); memcpy(command, "AT+CPBS=\"", 9); memcpy(command+9, bookName, bookLen); command[bookLen+9] = '\"'; command[bookLen+10] = 0; if (!sendATCommand(command)) { return false; } // Next, request the information about this book (ranges) char resp[50]; if (!sendATCommand("AT+CPBR=?", resp, sizeof(resp))) { return false; } char* args[3]; if (getSimTextArgs(resp, args, 3) != 3) { return false; } // Verify that the ranges are correct, and parse them char* recordRange = args[0]; char* recordMid = strchr(recordRange, '-'); if (recordMid == NULL) { return false; } recordRange[strlen(recordRange)-1] = 0; recordMid[0] = 0; bookOffset = atoi(recordRange+1); bookSize = atoi(recordMid+1) - bookOffset + 1; bookNameLength = atoi(args[1]); bookAddressLength = atoi(args[2]); return true; }