|
59 | 59 | #define ROAMING "+CREG: 0,5" |
60 | 60 | #define BEARER_OPEN "+SAPBR: 1,1" |
61 | 61 |
|
| 62 | +// FTP |
| 63 | +const char AT_FTPCID[] PROGMEM = "AT+FTPCID=1\r\n"; |
| 64 | +const char AT_FTPSERV[] PROGMEM = "AT+FTPSERV=\"%s\"\r\n"; |
| 65 | +const char AT_FTPUN[] PROGMEM = "AT+FTPUN=\"%s\"\r\n"; |
| 66 | +const char AT_FTPPW[] PROGMEM = "AT+FTPPW=\"%s\"\r\n"; |
| 67 | +const char AT_FTPPUTNAME[] PROGMEM = "AT+FTPPUTNAME=\"%s\"\r\n"; |
| 68 | +const char AT_FTPPUTPATH[] PROGMEM = "AT+FTPPUTPATH=\"%s\"\r\n"; |
| 69 | +const char AT_FTPPUT1[] PROGMEM = "AT+FTPPUT=1\r\n"; |
| 70 | +const char AT_FTPPUT2[] PROGMEM = "AT+FTPPUT=2,%d\r\n"; |
| 71 | +const char AT_FTPPUT20[] PROGMEM = "AT+FTPPUT=2,0\r\n"; |
| 72 | + |
| 73 | +const char OK_1[] PROGMEM = "OK\r\n"; |
| 74 | +const char AT_FTPPUT1_RESP[] PROGMEM = "1,1"; |
| 75 | +const char AT_FTPPUT2_RESP[] PROGMEM = "+FTPPUT: 2"; |
| 76 | +const char AT_FTPPUT20_RESP[] PROGMEM = "1,0"; |
| 77 | + |
62 | 78 | Result HTTP::configureBearer(const char *apn){ |
63 | 79 |
|
64 | 80 | Result result = SUCCESS; |
@@ -176,47 +192,86 @@ Result HTTP::putBegin(const char *fileName, |
176 | 192 | Result result; |
177 | 193 |
|
178 | 194 | char buffer[64]; |
| 195 | + char resp[12]; |
179 | 196 |
|
180 | | - sendCmdAndWaitForResp("AT+FTPCID=1\r\n", OK, 2000); |
181 | | - |
182 | | - sprintf(buffer, "AT+FTPSERV=\"%s\"\r\n", server); |
183 | | - sendCmdAndWaitForResp(buffer, OK, 2000); |
| 197 | + strcpy_P(buffer, AT_FTPCID); |
| 198 | + strcpy_P(resp, OK_1); |
| 199 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 200 | + return ERROR_FTPCID; |
| 201 | + } |
184 | 202 |
|
185 | | - //sendCmdAndWaitForResp("AT+FTPPORT=21\r\n", OK, 2000); |
186 | | - //sendCmdAndWaitForResp("AT+FTPSSL=2\r\n", OK, 2000); |
| 203 | + sprintf_P(buffer, AT_FTPSERV, server); |
| 204 | + strcpy_P(resp, OK_1); |
| 205 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 206 | + return ERROR_FTPSERV; |
| 207 | + } |
187 | 208 |
|
188 | | - sprintf(buffer, "AT+FTPUN=\"%s\"\r\n", usr); |
189 | | - sendCmdAndWaitForResp(buffer, OK, 20000); |
| 209 | + sprintf_P(buffer, AT_FTPUN, usr); |
| 210 | + strcpy_P(resp, OK_1); |
| 211 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 212 | + return ERROR_FTPUN; |
| 213 | + } |
190 | 214 |
|
191 | | - sprintf(buffer, "AT+FTPPW=\"%s\"\r\n", pass); |
192 | | - sendCmdAndWaitForResp(buffer, OK, 20000); |
| 215 | + sprintf_P(buffer, AT_FTPPW, pass); |
| 216 | + strcpy_P(resp, OK_1); |
| 217 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 218 | + return ERROR_FTPPW; |
| 219 | + } |
193 | 220 |
|
194 | | - sprintf(buffer, "AT+FTPPUTNAME=\"%s\"\r\n", fileName); |
195 | | - sendCmdAndWaitForResp(buffer, OK, 20000); |
| 221 | + sprintf_P(buffer, AT_FTPPUTNAME, fileName); |
| 222 | + strcpy_P(resp, OK_1); |
| 223 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 224 | + return ERROR_FTPPUTNAME; |
| 225 | + } |
196 | 226 |
|
197 | | - sprintf(buffer, "AT+FTPPUTPATH=\"%s\"\r\n", path); |
198 | | - sendCmdAndWaitForResp(buffer, OK, 20000); |
199 | | - sendCmdAndWaitForResp("AT+FTPPUT=1\r\n", "1,1", 20000); |
| 227 | + sprintf_P(buffer, AT_FTPPUTPATH, path); |
| 228 | + strcpy_P(resp, OK_1); |
| 229 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 230 | + return ERROR_FTPPUTPATH; |
| 231 | + } |
| 232 | + |
| 233 | + strcpy_P(buffer, AT_FTPPUT1); |
| 234 | + strcpy_P(resp, AT_FTPPUT1_RESP); |
| 235 | + if(sendCmdAndWaitForResp(buffer, resp, 20000) == FALSE){ |
| 236 | + return ERROR_FTPPUT1; |
| 237 | + } |
200 | 238 |
|
201 | 239 | return result; |
202 | 240 | } |
203 | 241 |
|
204 | 242 | Result HTTP::putWrite(const char *data, unsigned int size){ |
205 | 243 | Result result; |
206 | 244 |
|
207 | | - char ftpUpload[32]; |
208 | | - sprintf(ftpUpload, "AT+FTPPUT=2,%d\r\n", size); |
209 | | - sendCmdAndWaitForResp(ftpUpload, "+FTPPUT: 2", 20000); |
| 245 | + char buffer[32]; |
| 246 | + char resp[32]; |
| 247 | + |
| 248 | + sprintf_P(buffer, AT_FTPPUT2, size); |
| 249 | + strcpy_P(resp, AT_FTPPUT2_RESP); |
| 250 | + if(sendCmdAndWaitForResp(buffer, resp, 2000) == FALSE){ |
| 251 | + return ERROR_FTPPUT2; |
| 252 | + } |
| 253 | + else { |
| 254 | + write(data, size); |
| 255 | + |
| 256 | + strcpy_P(resp, AT_FTPPUT1_RESP); |
| 257 | + waitForResp(resp, 2000); |
| 258 | + } |
210 | 259 |
|
211 | | - write(data, size); |
212 | | - waitForResp("1,1", 20000); |
213 | 260 | return result; |
214 | 261 | } |
215 | 262 |
|
216 | 263 | Result HTTP::putEnd(){ |
217 | 264 | Result result; |
218 | 265 | serialSIM800.flush(); |
219 | | - sendCmdAndWaitForResp("AT+FTPPUT=2,0\r\n", "1,0", 20000); |
| 266 | + |
| 267 | + char buffer[32]; |
| 268 | + char resp[12]; |
| 269 | + |
| 270 | + strcpy_P(buffer, AT_FTPPUT20); |
| 271 | + strcpy_P(resp, AT_FTPPUT20_RESP); |
| 272 | + if(sendCmdAndWaitForResp(AT_FTPPUT20, AT_FTPPUT20_RESP, 2000) == FALSE){ |
| 273 | + return ERROR_FTPPUT20; |
| 274 | + } |
220 | 275 | return result; |
221 | 276 | } |
222 | 277 |
|
|
0 commit comments