Browse files

prep for webcam upload.

  • Loading branch information...
1 parent d7783ce commit 69b03d8e6d339e69cd1a7e1833c6c03505a9c1ce Zach Hoeken committed Apr 16, 2013
Showing with 150 additions and 4 deletions.
  1. +11 −4 ROADMAP
  2. +128 −0 controllers/apiv1.php
  3. +1 −0 controllers/bot.php
  4. +3 −0 install/first_boot.sh
  5. +7 −0 views/job/file.php
View
15 ROADMAP
@@ -1,6 +1,5 @@
v0.3 Release - Ongoing
-* WEB - add source info for jobs added by url.
* WEB - multi-job prints (eg: .zip file w/ manifest)
* pull in all files from thingiverse.com/thing:####
@@ -12,8 +11,14 @@ v0.3 Release - Ongoing
* timelapse interval should be calculated to last an exact time... 10 seconds or so.
* to save on space required to hold a ton of images, continuously overwrite the same file. then just show that to the user.
* what interval? 1 minute?
-* WEB - show latest webcam image for each bot on the site.
+ * keep all images from webcam on error jobs - forensic viewing of failed jobs.
+ * automatically delete after 1 day.
+ * synchronize temp readings + picture - then synchronize images w/ temperatures on bot view page
+ * send status updates during download.
+* WEB - when downloading file to slice, status should be "downloading"
+* WEB - change homepage to show live shots from currently printing bots.
+* WEB - show latest webcam image for each bot on its view page.
v0.3 CHANGELOG
@@ -32,6 +37,7 @@ v0.3 CHANGELOG
* WEB - update queue stats page to reflect job_clock times
* WEB - added leaderboard to stats page.
* WEB - update time displays to include more digits (eg: 1.2 hours vs 1 hour)
+* WEB - add source info for jobs added by url.
* BUMBLEBEE - allow pausing and unpausing based on api status change.
@@ -54,13 +60,14 @@ v0.4 Release
------------------------------------------------------------------------------------
+OMG BOTQUEUE:
+
+
Long term wants:
* WEB - filament spool info (it keeps track of how big each machine spool is/when a new one is installed and appoximates how much is left based on volume info in gcode)
* WEB / BUMBLEBEE - a way to pre-slice jobs AKA "on-deck" functionality
-* WEB - user-specific job ids that increment for user only.
-* when downloading file to slice, status should be "downloading"
* API - Websockets server
* define events to pass to clients
View
128 controllers/apiv1.php
@@ -67,6 +67,7 @@ public function endpoint()
'registerbot', //ok
'updatebot', //ok
'updateslicejob', //ok
+ 'webcamupdate', //ok
);
if (in_array($c, $calls))
{
@@ -536,6 +537,91 @@ public function api_updatejobprogress()
return $job->getAPIData();
}
+
+ public function api_webcamupdate()
+ {
+ $job = new Job($this->args('job_id'));
+ if (!$job->isHydrated())
+ throw new Exception("Job does not exist.");
+
+ $bot = $job->getBot();
+ if (!$bot->isHydrated())
+ throw new Exception("Bot does not exist.");
+
+ if (!$bot->isMine())
+ throw new Exception("This is not your bot.");
+
+ if (!$job->getQueue()->isMine())
+ throw new Exception("This job is not in your queue.");
+
+ //did we get temperatures?
+ $temps = JSON::decode($this->args('temperatures'));
+ if ($temps != NULL)
+ {
+ $jobtemps = JSON::decode($job->get('temperature_data'));
+ if ($jobtemps == NULL)
+ {
+ $jobtemps = array();
+ $jobtemps[time()] = $temps;
+ }
+ else
+ {
+ $index = time();
+ $jobtemps->$index = $temps;
+ }
+ $job->set('temperature_data', JSON::encode($jobtemps));
+ $bot->set('temperature_data', $this->args('temperatures'));
+ }
+
+ if (!empty($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name']))
+ {
+ //upload our file to S3
+ $file = $_FILES['file'];
+ if ($file['error'] != 0)
+ {
+ if($file['size'] == 0 && $file['error'] == 0)
+ $file['error'] = 5;
+
+ $upload_errors = array(
+ UPLOAD_ERR_OK => "No errors.",
+ UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
+ UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
+ UPLOAD_ERR_PARTIAL => "Partial upload.",
+ UPLOAD_ERR_NO_FILE => "No file.",
+ UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
+ UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
+ UPLOAD_ERR_EXTENSION => "File upload stopped by extension.",
+ UPLOAD_ERR_EMPTY => "File is empty." // add this to avoid an offset
+ );
+
+ throw new Exception("File upload failed: " . $upload_errors[$file['error']]);
+ }
+
+ //does it match?
+ if (!preg_match("/\.jpg$/i", $file['name']))
+ throw new Exception("The file must end in .jpg");
+
+ //is it a real image?
+ $size = getimagesize($file['tmp_name']);
+ if (!$size[0] || !$size[1])
+ throw new Exception("The file is not a valid image.");
+
+ //okay, we're good.. do it.
+ move_uploaded_file($file['tmp_name'], WEB_DIR . $bot->get('webcam_hash') . ".jpg");
+ }
+ else
+ throw new Exception("No file uploaded.");
+
+ //update our job info.
+ $job->set('progress', (float)$this->args('progress'));
+ $job->save();
+
+ //update our bot info
+ $bot->set('last_seen', date("Y-m-d H:i:s"));
+ $bot->save();
+
+ return $job->getAPIData();
+ }
public function api_jobinfo()
{
@@ -671,6 +757,48 @@ public function api_updatebot()
return $bot->getAPIData();
}
+ public function api_updatebot()
+ {
+ if (!$this->args('bot_id'))
+ throw new Exception("You must provide the 'bot_id' parameter.");
+
+ $bot = new Bot($this->args('bot_id'));
+ if (!$bot->isHydrated())
+ throw new Exception("Bot does not exist.");
+
+ if (!$bot->isMine())
+ throw new Exception("This bot is not yours.");
+
+ //if (!$this->args('manufacturer'))
+ // throw new Exception('Bot manufacturer is a required parameter.');
+ //if (!$this->args('model'))
+ // throw new Exception('Bot model is a required parameter.');
+
+ if ($this->args('name'))
+ $bot->set('name', $this->args('name'));
+ if ($this->args('name'))
+ $bot->set('identifier', $this->args('identifier'));
+ if ($this->args('manufacturer'))
+ $bot->set('manufacturer', $this->args('manufacturer'));
+ if ($this->args('model'))
+ $bot->set('model', $this->args('model'));
+ if ($this->args('electronics'))
+ $bot->set('electronics', $this->args('electronics'));
+ if ($this->args('firmware'))
+ $bot->set('firmware', $this->args('firmware'));
+ if ($this->args('extruder'))
+ $bot->set('extruder', $this->args('extruder'));
+ if ($this->args('status'))
+ $bot->set('status', $this->args('status'));
+ if ($this->args('error_text'))
+ $bot->set('error_text', $this->args('error_text'));
+ $bot->save();
+
+ Activity::log("updated the bot " . $bot->getLink() . " via the API.");
+
+ return $bot->getAPIData();
+ }
+
public function api_updateslicejob()
{
if (!$this->args('job_id'))
View
1 controllers/bot.php
@@ -71,6 +71,7 @@ public function register()
$bot->set('firmware', $form->data('firmware'));
$bot->set('extruder', $form->data('extruder'));
$bot->set('status', 'offline');
+ $bot->set('webcam_hash', sha1(mt_rand()));
$bot->save();
Activity::log("registered the bot " . $bot->getLink() . ".");
View
3 install/first_boot.sh
@@ -20,6 +20,9 @@ sudo apt-get install git apache2 php5-mysql php-pear build-essential libpcre3-de
sudo pecl install oauth
+sudo apt-get install libcurl3 php5-dev libcurl4-gnutls-dev libmagic-dev
+sudo pecl install pecl_http
+
sudo pear channel-discover pear.amazonwebservices.com
sudo pear channel-discover guzzlephp.org/pear
sudo pear channel-discover pear.symfony.com
View
7 views/job/file.php
@@ -10,6 +10,13 @@
<th>Download URL:</th>
<td><a href="<?=$file->getRealUrl()?>"><?=$file->getName()?></a></td>
</tr>
+ <? if ($file->get('source_url')): ?>
+ <? $data = parse_url($file->get('source_url')) ?>
+ <tr>
+ <th>Source:</th>
+ <td><a href="<?=http_build_url($file->get('source_url'))?>"><?=$data['host']?></a></td>
+ </tr>
+ <? endif ?>
<tr>
<th>Creator:</th>
<td><?=$creator->getLink()?></td>

0 comments on commit 69b03d8

Please sign in to comment.