Skip to content

Commit 07fa8ab

Browse files
committed
Add main functions to handle ftp actions
1 parent 85180b7 commit 07fa8ab

4 files changed

Lines changed: 78 additions & 4 deletions

File tree

Http.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ Result HTTP::connect() {
108108
}
109109
}
110110

111-
if (sendCmdAndWaitForResp(HTTP_INIT, OK, 2000) == FALSE)
112-
result = ERROR_HTTP_INIT;
111+
//if (sendCmdAndWaitForResp(HTTP_INIT, OK, 2000) == FALSE)
112+
// result = ERROR_HTTP_INIT;
113113

114114
return result;
115115
}
@@ -168,6 +168,58 @@ Result HTTP::get(const char *uri, char *response) {
168168
return result;
169169
}
170170

171+
Result HTTP::putBegin(const char *fileName,
172+
const char *server,
173+
const char *usr,
174+
const char *pass,
175+
const char *path){
176+
Result result;
177+
178+
char buffer[64];
179+
180+
sendCmdAndWaitForResp("AT+FTPCID=1\r\n", OK, 2000);
181+
182+
sprintf(buffer, "AT+FTPSERV=\"%s\"\r\n", server);
183+
sendCmdAndWaitForResp(buffer, OK, 2000);
184+
185+
//sendCmdAndWaitForResp("AT+FTPPORT=21\r\n", OK, 2000);
186+
//sendCmdAndWaitForResp("AT+FTPSSL=2\r\n", OK, 2000);
187+
188+
sprintf(buffer, "AT+FTPUN=\"%s\"\r\n", usr);
189+
sendCmdAndWaitForResp(buffer, OK, 20000);
190+
191+
sprintf(buffer, "AT+FTPPW=\"%s\"\r\n", pass);
192+
sendCmdAndWaitForResp(buffer, OK, 20000);
193+
194+
sprintf(buffer, "AT+FTPPUTNAME=\"%s\"\r\n", fileName);
195+
sendCmdAndWaitForResp(buffer, OK, 20000);
196+
197+
sprintf(buffer, "AT+FTPPUTPATH=\"%s\"\r\n", path);
198+
sendCmdAndWaitForResp(buffer, OK, 20000);
199+
sendCmdAndWaitForResp("AT+FTPPUT=1\r\n", "1,1", 20000);
200+
201+
return result;
202+
}
203+
204+
Result HTTP::putWrite(const char *data, unsigned int size){
205+
Result result;
206+
207+
char ftpUpload[32];
208+
sprintf(ftpUpload, "AT+FTPPUT=2,%d\r\n", size);
209+
sendCmdAndWaitForResp(ftpUpload, "+FTPPUT: 2", 20000);
210+
211+
write(data, size);
212+
waitForResp("1,1", 20000);
213+
return result;
214+
}
215+
216+
Result HTTP::putEnd(){
217+
Result result;
218+
serialSIM800.flush();
219+
sendCmdAndWaitForResp("AT+FTPPUT=2,0\r\n", "1,0", 20000);
220+
return result;
221+
}
222+
171223
void HTTP::sleep(bool force){
172224
if (force){
173225
sendCmdAndWaitForResp(SLEEP_MODE_1, OK, 2000);

Http.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class HTTP : public SIM800 {
6464
Result disconnect();
6565
Result get(const char *uri, char *response);
6666
Result post(const char *uri, const char *body, char *response);
67+
Result putBegin(const char *fileName,
68+
const char *server,
69+
const char *usr,
70+
const char *pass,
71+
const char *path = "/");
72+
Result putWrite(const char *data, unsigned int size);
73+
Result putEnd();
6774
void sleep(bool force = FALSE);
6875
void wakeUp();
6976
unsigned int readVoltage();

Sim800.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void SIM800::sendCmd(const char* cmd)
8888
serialSIM800.listen();
8989
serialSIM800.flush();
9090
delay(500);
91-
serialSIM800.write(cmd);
91+
write(cmd);
9292
serialSIM800.flush();
9393
}
9494

@@ -151,4 +151,16 @@ void SIM800::serialDebug(void)
151151
void SIM800::purgeSerial()
152152
{
153153
while (serialSIM800.available()) serialSIM800.read();
154+
}
155+
156+
void SIM800::write(const char* data)
157+
{
158+
serialSIM800.listen();
159+
serialSIM800.write(data);
160+
}
161+
162+
void SIM800::write(const char* data, unsigned int size)
163+
{
164+
serialSIM800.listen();
165+
serialSIM800.write(data, size);
154166
}

Sim800.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ class SIM800
121121

122122
void purgeSerial();
123123

124-
private:
124+
void write(const char* data);
125+
void write(const char* data, unsigned int size);
126+
127+
protected:
125128

126129
SoftwareSerial serialSIM800;
127130
bool debugMode;

0 commit comments

Comments
 (0)