#include #include #include Adafruit_VC0706 cam = Adafruit_VC0706(&Serial1); // Please enter your sensitive data in the Secret tab or arduino_secrets.h // PIN Number const char PINNUMBER[] = ""; // cambiare pin della sim // APN data const char GPRS_APN[] = ""; // cambiare APN. "iliad" oppure "web.omnitel.it" per esempio const char GPRS_LOGIN[] = ""; const char GPRS_PASSWORD[] = ""; // initialize the library instance GSMClient client; GPRS gprs; GSM gsmAccess; GSMSSLClient clients; GSM_SMS sms; char remoteNumber[20]; // Holds the emitting number int32_t time = millis(); int32_t ritorno; char serverName[] = "www.tuodominio.it"; void setup() { while (!Serial1) ; delay(2000); Serial.begin(9600); Serial.println("SMS Messages Receiver"); // connection state boolean notConnected = true; ritorno = -1; Serial.println(F("Inizio..")); pinMode(10, OUTPUT); // change this to 53 on a mega digitalWrite(10, HIGH); bool connected = false; // After starting the modem with GSM.begin() // attach the shield to the GPRS network with the APN, login and password while (!connected) { if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { connected = true; } else { Serial.println("Not connected"); delay(1000); } } Serial.println("connecting..."); // Try to locate the camera if (cam.begin()) { Serial.println("Camera Found:"); } else { Serial.println("No camera found?"); return; } cam.setImageSize(VC0706_160x120); // small // You can read the size back from the camera (optional, but maybe useful?) uint8_t imgsize = cam.getImageSize(); Serial.print("Image size: "); if (imgsize == VC0706_640x480) Serial.println("640x480"); if (imgsize == VC0706_320x240) Serial.println("320x240"); if (imgsize == VC0706_160x120) Serial.println("160x120"); } void loop() { if (sms.available()) { Serial.println("Message received from:"); // Get remote number sms.remoteNumber(remoteNumber, 20); //Serial.println(remoteNumber); String numero = remoteNumber; Serial.println(numero); Serial.println("\nEND OF MESSAGE"); // inserire il proprio cellulare al posto di 335ZZZZZZ if (sms.peek() == 'f' && numero.indexOf("335ZZZZZZ") > 0) { Serial.flush(); client.flush(); client.stop(); ritorno = -1; Serial.println(""); Serial.println("Riscatto Medium"); cam.setImageSize(VC0706_320x240); ritorno = takefoto(); } // delete message from modem memory sms.flush(); Serial.println("MESSAGE DELETED"); } } int takefoto() { Serial.println("Snap in 3 secs..."); cam.reset(); // You can read the size back from the camera (optional, but maybe useful?) uint8_t imgsize = cam.getImageSize(); Serial.print("Image size: "); if (imgsize == VC0706_640x480) Serial.println("640x480"); if (imgsize == VC0706_320x240) Serial.println("320x240"); if (imgsize == VC0706_160x120) Serial.println("160x120"); delay(3000); if (! cam.takePicture()) Serial.println("Failed to snap!"); else Serial.println("Picture taken!"); Serial.println("Server connecting..."); // client.stop(); if (client.connect(serverName, 80)) { Serial.println("connected"); uint16_t jpglen = cam.frameLength(); Serial.print("Storing "); Serial.print(jpglen, DEC); Serial.print(" byte image."); uint32_t len = jpglen + 177; // 177 is the content without the image data client.println(F("POST /myarduino/upload.php HTTP/1.1")); client.println(F("Host: www.tuodominio.it:80")); client.println(F("Content-Type: multipart/form-data, boundary=UH3xBZZtzewr09oPP")); client.print(F("Content-Length: ")); client.println(len); client.println(); client.println(F("--UH3xBZZtzewr09oPP")); client.println(F("content-disposition: form-data; name=\"picture\"; filename=\"CAM.JPG\"")); client.println(F("Content-Type: image/jpeg")); client.println(F("Content-Transfer-Encoding: binary")); client.println(); pinMode(8, OUTPUT); // Read all the data up to # bytes! byte wCount = 0; // For counting # of writes while (jpglen > 0) { // read 32 bytes at a time; uint8_t *buffer; uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups! buffer = cam.readPicture(bytesToRead); //Scrittura client.write(buffer, bytesToRead); if (++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up Serial.print('.'); wCount = 0; } jpglen -= bytesToRead; } client.println(); client.println(F("--UH3xBZZtzewr09oPP--")); time = millis() - time; Serial.println("done!"); Serial.print(time); Serial.println(" ms elapsed"); // if the server's disconnected, stop the client: if (!client.connected()) { Serial.println(); Serial.println("disconnecting."); client.flush(); client.stop(); while (true); } } else { Serial.println("connection failed"); } return time; }