-
Notifications
You must be signed in to change notification settings - Fork 27
/
inetGSM.cpp
109 lines (84 loc) · 2.8 KB
/
inetGSM.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "inetGSM.h"
int InetGSM::httpGET(const char* server, int port, const char* path, char* result, int resultlength)
{
int length_write;
//Status = ATTACHED.
if(gsm.getStatus()!=GSM::ATTACHED)
return 0;
if(!gsm.connectTCP(server, port))
return 0;
gsm.write((const uint8_t*)"GET ", 4);
gsm.write((const uint8_t*)path, strlen(path));
gsm.write((const uint8_t*)" HTTP/1.0\nHost: ", 16);
gsm.write((const uint8_t*)server, strlen(server));
gsm.write((const uint8_t*)"\n\n",2);
int res= gsm.read(result, resultlength);
gsm.disconnectTCP();
return res;
}
int InetGSM::httpPOST(const char* server, int port, const char* path, const char* parameters, char* result, int resultlength)
{
char itoaBuffer[8];
int num_char;
if (!gsm.connectTCP(server, port))
return 0;
strcpy(_buffer,"POST ");
strcat(_buffer,path);
strcat(_buffer," HTTP/1.0\nHost: ");
strcat(_buffer,server);
// strcat(_buffer,"\n\rUser-Agent: Mozilla/4.0\n\rContent-Length: ");
strcat(_buffer,"\nContent-Length: ");
itoa(strlen(parameters),itoaBuffer,10);
strcat(_buffer,itoaBuffer);
strcat(_buffer,"\n\n");
strcat(_buffer,parameters);
strcat(_buffer,"\n\n");
gsm.write((const uint8_t*)_buffer, strlen(_buffer));
// int res= gsm.read(result, resultlength);
gsm.disconnectTCP();
//return res;
return 1;
}
int InetGSM::tweet(const char* token, const char* msg)
{
// gsm.httpPOST("arduino-tweet.appspot.com",80,"/update", "token=15514242-eWYAlMwjRQfrhnZxQiOfDXUpaYwjbSvMl1Nm5Qyg&status=Spam", buffer, 200);
char shortbuf[200];
strcpy(shortbuf,"token=");
strcat(shortbuf,token);
strcat(shortbuf,"&status=");
strcat(shortbuf, msg);
httpPOST("arduino-tweet.appspot.com",80,"/update",shortbuf, shortbuf, BUFFERSIZE);
}
int InetGSM::openmail(char* server, char* loginbase64, char* passbase64, char* from, char* to, char* subj)
{
if (!gsm.connectTCP(server, 25))
return 0;
delay(1000);
gsm.read(_buffer, BUFFERSIZE);
gsm.write("HELO\n");
delay(500);
gsm.read(_buffer, BUFFERSIZE);
gsm.write("AUTH LOGIN\n");
delay(500);
gsm.read(_buffer, BUFFERSIZE);
gsm.write(loginbase64);gsm.write("\n");
delay(500);
gsm.read(_buffer, BUFFERSIZE);
gsm.write(passbase64);gsm.write("\n");
delay(500);
gsm.read(_buffer, BUFFERSIZE);
gsm.write("MAIL FROM: ");gsm.write(from);gsm.write("\n");
delay(500);
gsm.read(_buffer, BUFFERSIZE);
gsm.write("RCPT TO: ");gsm.write(to);gsm.write("\n");
delay(500);
gsm.read(_buffer, BUFFERSIZE);
gsm.write("Subject: ");gsm.write(subj);gsm.write("\n\n");
return 1;
}
int InetGSM::closemail()
{
gsm.write("\n.\n");
gsm.disconnectTCP();
return 1;
}