Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sending data over GPRS

Status
Not open for further replies.

mousefish

Newbie level 4
Newbie level 4
Joined
Jan 17, 2008
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,329
send data with gprs at commands

Hi,
I am using dspic30 PIC controller and would like to interface it with a GPRS module to send and receive data to a server via http protocol. I am able to connect to the server via AT commands. I want to ask how will i be able to send and receive data after connection to server. I am coding in C. Any help is appreciated. Thanks.
 

1gtm.h

Which GPRS module you are using>?
Does your GPRS module have TCP/IP STACK inbuilt? if yes then use TCP CLient server for data transfer
 

    mousefish

    Points: 2
    Helpful Answer Positive Rating
how to send data over gprs

mousefish said:
Hi,
I am using dspic30 PIC controller and would like to interface it with a GPRS module to send and receive data to a server via http protocol. I am able to connect to the server via AT commands. I want to ask how will i be able to send and receive data after connection to server. I am coding in C. Any help is appreciated. Thanks.

Greetings,

What phone are you going to use? can you post your schematic and code?
For send/receive (both) you need code PIC and server. I'm starting a similar project and my choice for the server side is the php. The php-server side act as a form, and the phone-AT gonna be the client. Gonna?, is not yet implemented, is just an idea.

Keep in touch
 

pic sending data over gsm

I'm also trying to send data to the host by GPRS with PIC16F877A. But I can't connect my module GSM to the host. First of all, i'm using hyper terminal on my computer to connect it with server. Can you show me how did you connect your module(or phone) with the server?

Thanks!
 

sending data by gprs

Hi all,

I am also looking to work on the same thing using pIC16f877a and SIM300C GSM Modem. What i want to do is remote reporting of sensor data through gprs to a website (php or whatever).

Lets make a sticky topic to finsh all the problems regarding data transmission between microcontroller and pc through gprs. will anyone experienced help us..?
 

gprs data exchange at command

Hi cuongbkedu,

for mi, i am using the IWOW TR800 module that has a bulit in TCP / IP stack. It also has built in AT commands to help connect to server using TCP protocols.

For mi, i used these commands to set up a TCP connection, after which i set the module to run in data mode so that all data sent to the module is sent to the server too.

If you are running a HTTP server, you will need to adhere to HTTP protocols like using GET, POST method. Run a search for HTTP protocols for examples.

On the server side, servlets or CGI scripts can be used to receive data, depending on the level of access to the server you are using.

Hope this helps a little.
 

microcontroller sending data over the internet

Ok dear,

I have used SIM300C module with hyperterminal on one pc and used tcp terminal on other which is connected to internet. I have used at commands of gprs to send the data from modem to other pc on it ip address and results were ok , data was receiving ok.
If some one need details upto this point plz ask.,

Now my next step is to make a generator telemetry system based on PIC micro and SIM300C. I am looking forward to have opinion from you people on architechutre of this system.

What i have in my mind.

I will develpe a pc side server software in vb which will listen all the generators data through tcpip port and store the data in respective databasiss. while the client side application will be able to see the specified generator data through this data base.

Please put forward your views that what should be the way to achive maximum performance of the system.

On pc side i am awear of VB6 only. If some one interested to work on this project with me , can pm me.

Regards
 

char ctrlz

Dear Dani,
this thread sound interesting for me could you gimme a little bit more info about the applications? What is the price for the module?

I'm developing a geomonitoring automatic instrumentation that should have a IP connectivity then may be this module should be used to do this task.
What I think is open the GPRS/GSM connection and then use the HTTP protocol to exchange data with the module. At now I'm using a simple GPRS/GSM modem to do all the task and I'm using a custom protocol to exchange data between the base station (with a program coded in VB) and the remote plant (wich is equipped with a embedded PC running WinXP, the software on the remote module is also written with VB).

Tnx
F.F. a.k.a. Powermos
 

send data to server using gprs

"I have used SIM300C module with hyperterminal on one pc and used tcp terminal on other which is connected to internet. I have used at commands of gprs to send the data from modem to other pc on it ip address and results were ok , data was receiving ok. "

Dani,

Could you post AT commands for your setup.

Thanks,
KSP
 

send data via gprs from pc

Hi Dani,

I am doing the same kind of project. I wanted to communicate b/w remote server and microcontroller using GPRS modem through at commands. I am using the motorola's C168 mobile to as GPRS modem. Can you please sen me the program/commands you have used to send the data to tcp server using at commands? my mail id is bikramjeet.waraich@gmail.com

Thanks in anticipation.

Warm Regards
Bikramjeet
 

exchange data using gprs

For imformation on sending data between GSM module & server via GPRS, see my post to a similar question at:
 

sending host for gprs

#include "D:\Adnan\GeneratorTM\C Source\1GTM.h"
#include "EXT_EE.c"
#include <float.h>
#include <stdlib.h>
#include <string.h>
#define CR 0x0D

#define c1E pin_e0
#define c2E pin_e1
#define DDin PIN_E2

void checkTime(void);
int1 resetModem(void);
int waitResponse(unsigned int16);
int sendData(void);
void getDataStr(void);
void reConnect(void);
void getWarSettings(void);
void setWarSettings(void);
void checkCommand();
void storeData_ExtE();
int1 modemResponding(void);
void hardResetModem();
void softResetModem();
void sendPING();
void readFreq();

int1 timeUpdatedFlg=0,warFlg=0, nMeFlg = 0, gprsCFLG = 0,tSyncFlg = 0,timeoutFlg=0,sendFlg=0,pingFlg=0;
char buf[240];
char sOK[] = {"OK"};
char sER[] = {"ERROR"};
char sCON[] = {"CONNECT OK"};
char sSen[] = {"SEND OK"};
char Servertime[] = {"01/01/01,12/00/00+00\0"};
Char CTime[]={"01/01/01,12/00/00+00\0"};
Char sACon[] = {"ALREADY CONNECT"};
Char nMe[] = {"88888888888888\0"}; //00923014217397
char dtstr[200]={"$D,"};
char IP[] = {"117.102.61.106\0"};
unsigned long dData = 0;
unsigned long aData[16],LWarLevel[16],HWarLevel[16];
unsigned long dWar,aWarL,aWarH,dWarEnabled=0,aWarEnabledL=0,aWarEnabledH=0;
int8 Index , RESFLG = 1, gprsConnected = 0,resetTries=0,pingTries=0,NforPINg=0; //Index variable for GSM response string
unsigned long Timeout = 1500,ExtE_Pointer,freq=0;

//void checkResponse(char*); //17 time interrupt = 1 min = 3.4sec * 17 = 57.8 >> +-2.2sec


/*#int_RTCC
void RTCC_isr(void)
{
aTS++;

}
*/
#INT_RDA
void RDA_isr(void)
{
INT C[2];

// disable_interrupts(INT_RDA);
Index = 0;
if(timeoutFlg==0 || TIMEOUT>31000){
timeout = 1500;
}

if(resFlg==0){
do
{
if (kbhit())
{
buf[index] = fgetc(GSM);
index++;
}
delay_ms(1);
TIMEOUT--;


}while(TIMEOUT > 0 && TIMEOUT < 31000 && index<220);


BUF[INDEX]='\0';
resflg = 1;

if(buf[2]=='+' && buf[3]=='C' && buf[4]=='P' && buf[5]=='B' && buf[6]=='R'){

if(strLen(buf)>20){
nME[0] = buf[12];//0
nME[1] = buf[13];//0
nME[2] = buf[14];//9
nME[3] = buf[15];//2
nME[4] = buf[16];//3
nME[5] = buf[17];//0
nME[6] = buf[18];//1
nME[7] = buf[19];//4
nME[8] = buf[20];//2
nME[9] = buf[21];//1
nME[10] = buf[22];//7
nME[11] = buf[23];//3
nME[12] = buf[24];//9
nME[13] = buf[25];//7
nME[14] = '\0';
nMeFlg = 1;
}else{
nMeFlg = 0;
}


}else if(buf[0]=='$' && buf[1] == 'R' && buf[2] == '1'){
ServerTime[0] = buf[4];ServerTime[1] = buf[5];ServerTime[2] = buf[6];
ServerTime[3] = buf[7];ServerTime[4] = buf[8];ServerTime[5] = buf[9];
ServerTime[6] = buf[10];ServerTime[7] = buf[11];ServerTime[8] = buf[12];

ServerTime[9] = buf[13];ServerTime[10] = buf[14];ServerTime[11] = buf[15];
ServerTime[12] = buf[16];ServerTime[13] = buf[17];ServerTime[14] = buf[18];
ServerTime[15] = buf[19];ServerTime[16] = buf[20];ServerTime[17] = buf[21];
serverTime[18] = buf[22];servertime[19] = buf[23];serverTime[20]='\0';
gprsCFlg = 1;
}else if(buf[0]=='$' && buf[1] == 'R' && buf[2] == '0'){
gprsCFlg = 0;
}

}
if (kbhit())
{
c[0] = fgetc(GSM);
}

//enable_interrupts(INT_RDA);
}


void main()
{

setup_adc( ADC_CLOCK_INTERNAL );
setup_adc_ports (RA0_ANALOG);
set_adc_channel(0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0 (RTCC_DIV_2|RTCC_EXT_L_TO_H);
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_8);
init_ext_eeprom();
enable_interrupts(INT_RTCC);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
set_Tris_C(0b10101101);
set_rtcc(0);
delay_ms(200);

getWarSettings();


fprintf(PGM,"START........\r");
DELAY_MS(1000);
resFlg = 0;

WHILE(GPRSCONNECTED == 0){
resetModem();
DELAY_MS(1000);
IF(!GPRSCONNECTED)
fprintf(PGM,"GPRS CONNECION FAILD !!\r");
}


fprintf(PGM,"GPRS CONNECTED OK $$\r");


delay_ms(1000);

// TODO: USER CODE!!
while(1){

getDataStr();
if(resFlg==1)
{
checkCommand();
fprintf(PGM,"STR = %S\r",BUF);
resFLG = 0;
}
if(WarFlg==1 || sendFlg == 1){

timeUpdatedFlg=0;
fprintf(GSM,"AT+CCLK?\r");
waitResponse(2000);
if(resFlg==1)
{
checkCommand();
resFLG = 0;
}
if(timeUpdatedFlg==1){
if(pingFlg==0){
storeData_EXTE();
}else{
pingFlg=0;
}

if(sendData()==0){
fprintf(PGM,"D-: Data Send Error..Modem Reconnecting Now\r");
reConnect();
if(gprsConnected !=1 || gprsCflg !=1){
fprintf(PGM,"D-: Modem Reconnect Error..Rest Modem\r");
resetModem();
}
}
}else if(ModemResponding()==0){
hardResetModem();
}

}
}


}//main()

int1 modemResponding(){
CHAR ctrlZ = 26;

fprintf(GSM,"AT\r");
waitResponse(1000);
fprintf(GSM,"+++%c",ctrlZ);
waitResponse(2000);
fprintf(GSM,"AT\r");
resFlg=0;
if(waitResponse(1000)==1){
return 1;
}else{
return 0;
}

}

void hardResetModem(){

fprintf(PGM,"D-: Modem Hard Reset Required...\r");

}

/*void checkTime(){ // ats = 17 equal to one minute, this method set the hours and minutes

if (aTS>15){
aTS = 0;
aTM ++;

if(aTM>59){
aTM = 0;
aTH++;
}
if(gRunningFLG==1){ // if generator running
rTM ++;
if(rTM>59){
rTM = 0;
rTH++;
}
}
}
}//checkTime()
*/

void reconnect(void){
CHAR C=34,ctrlZ = 26;
int resp=-1;
gprsconnected = 0;
gprsCflg = 0;
fprintf(GSM,"AT+CIPSTART=%Ctcp%C,%C%S%C,%C1001%C\r",c,c,c,ip,c,c,c);
RESFLG=0;
resp = waitresponse(30000);
if(resp!=5){ //not already connected then
if(resp==3 || resp==0 ){
fprintf(GSM,"AT+CIPSEND\r\n");
RESFLG=0;
waitResponse(1000);
if(nMEflG==1){
fprintf(GSM,"$REGISTER:%S*%C",nME,ctrlZ);
RESFLG=0;
if(waitResponse(2000)==4){
RESFLG=0;
waitResponse(6000);
if(gprsCFlg == 1){
gprsConnected = 1;
fprintf(GSM,"AT+CCLK=%C%S%C\r",c,ServerTime,c);
tSyncFlg=1;
resFlg=0;
waitResponse(2000);
}
}
}
}
}else{
gprsConnected = 1;
gprsCflg=1;
}
}


int1 resetModem(void){
CHAR C=34,ctrlZ = 26;
GPRSCONNECTED=0;
gprsCflg = 0;

if(resetTries>5){
resetTries = 0;
if(ModemResponding()==0){
hardResetModem();
}
}
resFlg=0;
fprintf(GSM,"ATE0\r");
waitResponse(1000);
fprintf(PGM,"ATE0 = %S\r",BUF);
fprintf(GSM,"+++%c",ctrlZ);
waitResponse(1000);
fprintf(PGM,"+++Z = %S\r",BUF);
fprintf(GSM,"AT+CIPSHUT\r");
waitResponse(3000);
fprintf(PGM,"CIPSHUT = %S\r",BUF);
fprintf(GSM,"AT\r");
waitResponse(1000);
fprintf(PGM,"AT = %S\r",BUF);
fprintf(GSM,"ATD 1;\r");
RESFLG=0;
waitResponse(10000);
fprintf(PGM,"ATD = %S\r",BUF);
RESFLG = 1;
fprintf(GSM,"ATh\r");
waitResponse(1000);
fprintf(PGM,"ATH = %S\r",BUF);
fprintf(GSM,"AT\r");
waitResponse(1000);
fprintf(PGM,"AT = %S\r",BUF);
RESFLG = 1;
fprintf(GSM,"ATE0\r");
waitResponse(2000);
fprintf(PGM,"ATE = %S\r",BUF);
fprintf(GSM,"AT+CPBR=1\r");
RESFLG=0;
waitResponse(2000);
fprintf(PGM,"CPBR = %S\r",BUF);
if(NmeFlg==0){
fprintf(PGM,"Error: Owner number not found\r");
return 0;

}

fprintf(GSM,"AT\r");
resFlg=0;
if(waitResponse(1000)==1){
fprintf(GSM,"AT+CGDCONT=1,%CIP%C,%CINTERNET%C\r",c,c,c,c);
RESFLG=0;
if(waitResponse(3000)==1){
fprintf(PGM,"D+: CGDCONT OK\r");
fprintf(GSM,"AT+CSTT=%CINTERNET%C,%CTelenor%C,%CTelenor%C\r",c,c,c,c,c,c);
RESFLG=0;
if(waitResponse(3000)==1){
fprintf(PGM,"D+: CSTT OK\r");
fprintf(GSM,"AT+CIICR\r");
RESFLG=0;
if(waitResponse(10000)==1){
fprintf(PGM,"D+: CIICR OK\r");
fprintf(GSM,"AT+CIFSR\r");
RESFLG=0;
if(waitResponse(3000)!=2){
fprintf(PGM,"D+: CIFSR OK\r");
fprintf(GSM,"AT+CIPSTART=%Ctcp%C,%C%S%C,%C1001%C\r",c,c,c,ip,c,c,c);
RESFLG=0;
if(waitResponse(20000)==3){
fprintf(PGM,"D+: CIPSTARTED CONNECTION OK\r");
fprintf(GSM,"AT+CIPSEND\r");
RESFLG=0;
waitResponse(1000);
if(nMEflG==1){
fprintf(GSM,"$REGISTER:%S*%C",nME,ctrlZ);
RESFLG=0;
if(waitResponse(2000)==4){
RESFLG=0;
waitResponse(5000);
if(gprsCFlg == 1){
gprsConnected = 1;
fprintf(GSM,"AT+CCLK=%C%S%C\r",c,ServerTime,c);
tSyncFlg=1;
resFlg=0;
waitResponse(2000);
fprintf(PGM,"D+: TIME SYCHRONIZED:1\r");
}
}else{
fprintf(GSM,"$REGISTER:%S*%C",nME,ctrlZ);
RESFLG=0;
if(waitResponse(2000)==4){
RESFLG=0;
waitResponse(5000);
if(gprsCFlg == 1){
gprsConnected = 1;
fprintf(GSM,"AT+CCLK=%C%S%C\r",c,ServerTime,c);
tSyncFlg=1;
resFlg=0;
waitResponse(2000);
fprintf(PGM,"D+: TIME SYCHRONIZED:2\r");
}
}else{
fprintf(GSM,"$REGISTER:%S*%C",nME,ctrlZ);
RESFLG=0;
if(waitResponse(2000)==4){
RESFLG=0;
waitResponse(5000);
if(gprsCFlg == 1){
gprsConnected = 1;
fprintf(GSM,"AT+CCLK=%C%S%C\r",c,ServerTime,c);
tSyncFlg=1;
resFlg=0;
waitResponse(2000);
fprintf(PGM,"D+: TIME SYCHRONIZED:3\r");
}
}else{
fprintf(GSM,"$REGISTER:%S*%C",nME,ctrlZ);
RESFLG=0;
if(waitResponse(2000)==4){
RESFLG=0;
waitResponse(5000);
if(gprsCFlg == 1){
gprsConnected = 1;
fprintf(GSM,"AT+CCLK=%C%S%C\r",c,ServerTime,c);
tSyncFlg=1;
resFlg=0;
waitResponse(2000);
fprintf(PGM,"D+: TIME SYCHRONIZED:4\r");
}
}else{
gprsConnected = 0;
}
}
}
}
}
}
}
}
}
}
}

if (gprsconnected==1){
return 1;
}else{
resetTries++;
return 0;
}
}


int waitResponse(unsigned int16 t){
int16 i=0,J=0;
int r;
TIMEOUT = T;
timeoutFlg = 1;
FOR(J=0;J<T;J++){
I=0;
while(i<1000 && TIMEOUT>0){
// delay_US(1);
i++;
}
}

r = 0 ;
if(Strstr(Buf,sAcon)>0){
r = 5;
}else if(STRstr(BUF,sSen)>0){
r = 4;
}else if(STRstr(BUF,SCON)>0){
r = 3;
}else if(STRstr(BUF,SER)>0){
r = 2;
}else if(STRstr(BUF,SOK)>0){
r = 1;
}

if(resFlg == 1 && r>0 ){
return r;
}else{
return 0;
}

}

int sendData(){
CHAR ctrlZ = 26;
fprintf(GSM,"AT\r");
waitResponse(1000);
fprintf(GSM,"AT+CIPSEND\r");
RESFLG=0;
waitResponse(1000); // no error.
fprintf(GSM,"%s",dtstr);
waitResponse(200);
RESFLG=0;
fprintf(GSM,"%c",ctrlZ);
fprintf(GSM,"%c",ctrlZ);
fprintf(GSM,"%c",ctrlZ);
if(waitResponse(5000)==4){
resflg = 1;
fprintf(GSM,"AT\r");
waitResponse(1000);
sendFlg = 0;
return 1;
}
return 0;
}

void storeData_ExtE(){

// timeUpdateFlg=0;
unsigned long addr=0,eAddr=0;
unsigned int sAddr=0,i=0;
fprintf(PGM,"%s\r",dtstr);
fprintf(PGM,"len = %ld\r",strLen(dtstr));
if(EXTE_Pointer < 230){
sAddr = 0b10100000;
addr = EXTE_Pointer * 140;
}else if(EXTE_Pointer < 460){
sAddr = 0b10100010;
addr = (EXTE_Pointer-230)* 140;
}else if(EXTE_Pointer < 690){
sAddr = 0b10100100;
addr = (EXTE_Pointer-460)* 140;
}else if(EXTE_Pointer < 920){
sAddr = 0b10100110;
addr = (EXTE_Pointer-690)* 140;
}else{
sAddr = 0b10100000;
EXTE_Pointer = 0;
addr = 0;
}
for(eAddr=addr;eAddr<addr+140;eAddr++)
{
write_ext_EEprom(eAddr,sAddr,dtStr);
delay_ms(5);
i++;
}
EXTE_Pointer++;
write_eeprom(254,make8(ExtE_Pointer,0));
write_eeprom(255,make8(ExtE_Pointer,1));
fprintf(PGM,"EXTE_Pointer = %lu\r",Exte_Pointer);
warFlg=0;

}

void getDataStr(){
unsigned int16 aData[16],cDwar=0,cAWarl=0,cAWarh=0,j=0;
unsigned int32 atemp;
int8 i,pins,genStatus = 5;
char astarik[3]={"*\0"};
char comma[3]={",\0"};
char tString[6];
dtstr[0]='$';
dtstr[1]='D';
dtstr[2]=',';
dtstr[3]='\0';
strcat(dtStr,nMe);
strcat(dtStr,comma);
readFreq();
if (Freq > 25){
genStatus = 0; //generator running
}else{
genStatus = 1;
}
itoa(genStatus,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);

warFlg = 0;
output_low(c1e);
output_high(c2e);
dData=0;
delay_us(100);

for(pins=0;pins<16;pins++){
output_d(pins);
delay_us(25);
if(input(dDin)){
bit_set(dData,pins);
}else{
bit_clear(dData,pins);
}

// fprintf(PGM,"d[%d] = %d\r",pins,input(dDin));
}
itoa(dData,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);

output_low(c2e);
output_high(c1e);
delay_ms(1);

for(pins=0;pins<16;pins++){
output_d(pins);
atemp=0;
for(j=1;j<=1000;j++){
delay_us(50);
atemp += read_adc();
}
aData[pins] = atemp/1000;

itoa(aData[pins],10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);

// fprintf(PGM,"a[%d] = %ld\r",pins,adata[pins]);
}


// fprintf(PGM,"war checking---\r");
for(i=0;i<16;i++){
if(bit_test(dWarEnabled,i)){
if(bit_test(dData,i) == 0){ // condition normally open/high
bit_set(cdwar,i);
// fprintf(pgm,"dwarning = %d\r",i);
}
}
}

for(i=0;i<16;i++){
if(bit_test(aWarEnabledL,i)){
if(aData<= LwarLevel){
bit_set(cAWarL,i);
// fprintf(PGM,"aLwarning = %d\r",i);
}
}
if(bit_test(aWarEnabledH,i)){
if(aData>= hwarLevel){
bit_set(cAWarH,i);
// fprintf(PGM,"aHwarning = %d\r",i);
}
}
}

if((dwar != cDwar)||(aWarL != cAwarL)||(aWarH != cAwarH)){
warFlg=1;
dWar = cDwar;
aWarL = cAwarL;
aWarH = cAwarH;
itoa(cdWar,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
itoa(caWarL,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
itoa(caWarH,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
readFreq();
itoa(Freq,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
strcat(dtStr,Astarik);
fprintf(PGM,"State Change or warning is there...\r%s\r",dtstr);
}else{
fprintf(PGM,"No warning is there....\r");
warFlg=0;
cDwar=0;
cAwarL=0;
CAwarH=0;
itoa(cdWar,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
itoa(caWarL,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
itoa(caWarH,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
readFreq();
itoa(Freq,10,tString);
strcat(dtStr,tString);
strcat(dtStr,comma);
strcat(dtStr,Astarik);
nforPing++;
if (nforPing > 6){
nforPing = 0;
sendPING();
sendFlg=1;
}
}


}

void setWarSettings(void){
unsigned int8 EEaddr=0;
char term[3], *ptr;
int i=0;
long val=0;
strcpy(term,",;");
ptr = strtok(buf,term);
ptr = strtok(0, term);

if(ptr!=0){

dwarEnabled = atol(ptr);
fprintf(PGM,"dwar = %ld\r",dwarEnabled);
ptr = strtok(0, term);

while(ptr!=0 && *ptr!=42){

i = atoi(ptr);
fputs(ptr,PGM);
ptr = strtok(0, term);
val = atol(ptr);
if(val>0){
bit_set(awarEnabledL,i);
LwarLevel = val;
fprintf(PGM,"L %d=%ld\r",i,val);
}else{
bit_clear(awarEnabledL,i);
LwarLevel = val;
fprintf(PGM,"L %d=%ld\r",i,val);
}
ptr = strtok(0, term);
val = atol(ptr);
if(val>0){
bit_set(awarEnabledH,i);
HwarLevel = val;
fprintf(PGM,"H %d=%ld\r",i,val);
}else{
bit_clear(awarEnabledH,i);
HwarLevel = val;
fprintf(PGM,"H %d=%ld\r",i,val);
}

ptr = strtok(0, term);
}
}
EEaddr = 0;
write_eeprom(EEaddr,make8(dwarEnabled,0));
write_eeprom(EEaddr+1,make8(dwarEnabled,1));
delay_ms(5);
EEaddr+=2;
write_eeprom(EEaddr,make8(awarEnabledL,0));
write_eeprom(EEaddr+1,make8(awarEnabledL,1));

delay_ms(5);
EEaddr+=2;
write_eeprom(EEaddr,make8(awarEnabledH,0));
write_eeprom(EEaddr+1,make8(awarEnabledH,1));
for(i = 0;i<16;i++){
delay_ms(5);
EEaddr+=2;
write_eeprom(EEaddr,make8(LwarLevel,0));
write_eeprom(EEaddr+1,make8(LwarLevel,1));
}
for(i = 0;i<16;i++){
delay_ms(5);
EEaddr+=2;
write_eeprom(EEaddr,make8(HwarLevel,0));
write_eeprom(EEaddr+1,make8(HwarLevel,1));
}
fprintf(pgm,"New warning settings have been programmed.\r");
}

void checkCommand(){


if(buf[0]=='$' && buf[1] == 'W' && buf[2] == 'S'){
setWarSettings();
}else if(buf[2]=='+' && buf[3]=='C' && buf[4]=='C' && buf[5]=='L' && buf[6]=='K'){

Ctime[0] = buf[10];Ctime[10] = buf[20];
Ctime[1] = buf[11];Ctime[11] = buf[21];
Ctime[2] = buf[12];Ctime[12] = buf[22];
Ctime[3] = buf[13];Ctime[13] = buf[23];
Ctime[4] = buf[14];Ctime[14] = buf[24];
Ctime[5] = buf[15];Ctime[15] = buf[25];
Ctime[6] = buf[16];Ctime[16] = buf[26];
Ctime[7] = buf[17];Ctime[17] = buf[27];
Ctime[8] = buf[18];Ctime[18] = buf[28];
Ctime[9] = buf[19];Ctime[19] = buf[29];
Ctime[20] = '\0';
strcat(dtStr,Ctime);
timeUpdatedFlg=1;
}else if(buf[0]=='$' && buf[1] == 'Q' && buf[2] == '-' && buf[3] == '1'){
sendFlg=1;
}else if(buf[0]=='$' && buf[1] == 'Q' && buf[2] == '-' && buf[3] == '2'){
sendFlg=1;
}else if(buf[0]=='$' && buf[1] == 'Q' && buf[2] == '-' && buf[3] == '3'){
sendFlg=1;
}

}


void getWarSettings(){//setting from eeprom.
int EEaddr=0,i;

dWarEnabled = make16(read_eeprom(EEaddr+1),read_eeprom(EEaddr));
fprintf(PGM,"ee1 = %lu\r",dwarEnabled);
EEaddr+=2;
aWarEnabledL = make16(read_eeprom(EEaddr+1),read_eeprom(EEaddr));
fprintf(PGM,"ee2 = %lu\r",awarEnabledL);
EEaddr+=2;
aWarEnabledH = make16(read_eeprom(EEaddr+1),read_eeprom(EEaddr));
fprintf(PGM,"ee3 = %lu\r",awarEnabledH);
for(i=0;i<16;i++){
EEaddr+=2;
LWarLevel = make16(read_eeprom(EEaddr+1),read_eeprom(EEaddr));
fprintf(PGM,"Lee[%d] = %lu\r",i,LwarLevel);
}
for(i=0;i<16;i++){
EEaddr+=2;
HWarLevel = make16(read_eeprom(EEaddr+1),read_eeprom(EEaddr));
fprintf(PGM,"Hee[%d] = %lu\r",i,HwarLevel);
}
EEaddr = 254;
ExtE_Pointer = make16(read_eeprom(EEaddr+1),read_eeprom(EEaddr));
fprintf(PGM,"Exte_pointer = %lu\r",ExtE_Pointer);
if(ExtE_Pointer > 1000){
ExtE_Pointer = 0;
write_eeprom(EEaddr,make8(ExtE_Pointer,0));
write_eeprom(EEaddr+1,make8(ExtE_Pointer,1));
}


}

///////////////////////////////

void sendPING(){
CHAR ctrlZ = 26;
int res=0;
dtstr[0]='$';
dtstr[1]='P';
dtstr[2]='I';
dtstr[3]='N';
dtstr[4]='G';
dtstr[5]='*';
dtstr[6]='\0';
PINGFlg=1;
/* resFlg = 0;
fprintf(GSM,"AT\r");
waitResponse(1000);
fprintf(GSM,"AT+CIPSEND\r");
RESFLG=0;
waitResponse(1000); // no error.
fprintf(GSM,"%s",dtstr);
waitResponse(200);
RESFLG=0;
fprintf(GSM,"%c",ctrlZ);
res = waitResponse(5000);
fprintf(PGM,"d: PINGSEND = %s\r",buf);
if(res !=4 && pingTries<4){
pingTries++;
resflg = 0;
fprintf(GSM,"AT\r");
waitResponse(1000);
}else if(res==4){
fprintf(PGM,"D+: PING Sent OK.\r");
pingtries = 0;
resflg=0;
fprintf(GSM,"AT\r");
//waitResponse(10000);
}else{
sendFlg=1;
}

resFlg = 0;
*/
}

void readFreq(){
long i=0;
SET_TIMER1(0);
for(i=1;i<1000;i++){
delay_ms(1);
}
freq = GET_TIMER1();
//fPRINTF(PGM,"F = %LD\r",freq);

}
 

hi dani,

i need to send the data thru GPRS modem (Simcom 300DZ) from hyperterminal (PC1) to tcp/ip terminal (PC2) as u have done successfully previously.Please will u tell me how to do?

The code u posted is 100% working or any bugs to be found bcoz i compiled the code and found 0 errors,have to test with the hardware...please help me.
 

I have tested the code and it was working ok. But i couldnot deploy it in the field. Their might be a requirnement of modem reset in certian cases and also processor reset through watchdog. Otherwise the code was working perfect.

dani
 

thx dani,

so wat all the changes i have to do inorder to use code with hardware to transfer data thru gprs & how to transfer data from hyperterminal (PC1) to tcp/ip terminal (PC2).Thanks once again.
 

Re: sending data by gprs

dani said:
Hi all,

I am also looking to work on the same thing using pIC16f877a and SIM300C GSM Modem. What i want to do is remote reporting of sensor data through gprs to a website (php or whatever).

Lets make a sticky topic to finsh all the problems regarding data transmission between microcontroller and pc through gprs. will anyone experienced help us..?
HI all,
I m new here . I am doing the same project need 2 send gps data through GPRS using ATmega128 and sim548z module.here are my questions-
1. how do i verify the data as it is coming on server or not?.I am using PHP-mysql scripting at server side . i m thinking 2 use my PC as server.IS IT POSSIBLE?if it is then how?
2. how will i parse the data frm module 2 gprs?if any idea for codes plz help.
3. how will i initialize the UART 2 receive gps string and parse it over 2 gprs?


I hope u will find some soon.
THANKS
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top