Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SENDING READED FILES TO SERVER USING API HTTP
- boolean readSend(char* fn) {
- TinyGsmClient client;
- boolean readedData = false;
- boolean requested = false;
- boolean statusReply = false;
- byte savedReply = 0;
- String dt = "";
- byte ci = 0; // cursor
- byte authReply ;
- // Read sdcard
- File myFile = SD.open(fn,FILE_READ);
- if(!myFile) {
- return;
- }
- // While files are available
- while(myFile.available()){
- dt = myFile.readStringUntil('\n');
- readedData = true;
- }
- // debug readed local file
- Serial.print(dt);
- // send it to server
- if(client.connect(server,80)) {
- client.print("GET /feed/api2.php?K=");
- client.print(myKey);
- client.print("&");
- client.print(dt);
- client.print(" HTTP/1.0\r\n\r\n");
- client.print("Host: ");
- client.println(server);
- client.print("User-Agent: Arduino-agrieye\n");
- client.println("Connection: close");
- //client.println("Content-Type: text/html");
- client.println();
- requested = true;
- } else {
- myFile.close();
- client.stop();
- return false;
- }
- // check the feedback
- if(requested) {
- Serial.print("Requested2\n");
- boolean fin = false;
- unsigned long timeoutRead = millis();
- while(client.connected() && millis() - timeoutRead < 70000) {
- while(client.available() > 0) {
- char inChar = client.read();
- Serial.print(inChar);
- // find the # two times
- if(inChar == '#') {
- ci++;
- }
- if((ci == 2) && (fin == false)) {
- // read value using String
- String ar = client.readStringUntil('\n');
- String sr = client.readStringUntil('\n');
- Serial.print("ar: ");
- Serial.println(ar);
- Serial.print("sr: ");
- Serial.println(sr);
- // convert the value into number
- authReply = ar.toInt();
- savedReply = sr.toInt();
- statusReply = true;
- fin = true;
- }
- }
- }
- // close client
- client.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement