Esempio n. 1
0
int WiFiCmdRobot::WiFiSendPicture (int16_t n)
{
  int ret=SUCCESS;
  int16_t nbytes; 
  uint8_t buf[PAYLOAD_SIZE];
  char filename[12+1];
 
  Serial.print("n: ");
  Serial.println(n);
  
  // Open the file
  sprintf(filename, "PICT%02d.jpg", n);
  if (!FilePicture.open(&root, filename, O_READ)) return FILE_OPEN_ERROR;  

  Serial.print("Open file: ");
  Serial.println(filename);

  // read from the file until there's nothing else in it:
  while ((nbytes = FilePicture.read(buf, sizeof(buf))) > 0 && ret == SUCCESS) {
       for (unsigned int idx = 0; idx<nbytes;idx++)
       {
           tcpClient.print(buf[idx]);
       }
 
  }// while
  
  //Close file
  if (!FilePicture.close()) return FILE_CLOSE_ERROR;  
  
  return SUCCESS;
}
Esempio n. 2
0
int WiFiCmdRobot::ReplyOK ()
{
    int ret=SUCCESS; 
    
    if (cmd[0] == CMD_PICTURE)
    { 
          Serial.println("cmd[0] == CMD_PICTURE");
          if (tcpClient.isConnected()) Serial.println("tcpClient.isConnected");
          else Serial.println("tcpClient.is not Connected");
          tcpClient.println("HTTP/1.1 200 OK");
          tcpClient.println("Content-Type: application/octet-stream");
          tcpClient.println("Server: ChipkitEDH/0.1");                                             
          tcpClient.println();

          ret= WiFiSendPicture (resp[0]);
          
          if (ret != SUCCESS){  Serial.print("WiFiSendPicture error"); Serial.print(ret);}
    }
    else                                           
    {                               
          tcpClient.println("HTTP/1.1 200 OK");
          for(int i=0; i<resp_len; i++)
          {
              tcpClient.print("Field ");
              tcpClient.print(String(i));
              tcpClient.print(":");
              tcpClient.print(String((int)resp[i]));
              tcpClient.println(";");
         }
         tcpClient.println("Content-Type: text/html");
         tcpClient.println("Server: ChipkitEDH/0.1");                                             
         tcpClient.println();
    }
    
    return ret;    
}