Added /API/RADIO which allows JSON Posting of radio information

pull/106/merge
Peter Goodhall 2012-04-07 17:36:38 +01:00
rodzic c22b5585c9
commit 1fccf90cef
2 zmienionych plików z 75 dodań i 0 usunięć

Wyświetl plik

@ -306,4 +306,29 @@ class API extends CI_Controller {
// Return the arguments
return $arguments;
}
/* ENDPOINT for Rig Control */
function radio() {
header('Content-type: application/json');
//$json = '{"radio":"FT-950","frequency":14075,"mode":"SSB","timestamp":"2012/04/07 16:47"}';
$this->load->model('cat');
//var_dump(file_get_contents("php://input"), true);
// Decode JSON and store
$obj = json_decode(file_get_contents("php://input"), true);
// Store Result to Database
$this->cat->update($obj);
// Return Message
$arr = array('status' => 'success');
echo json_encode($arr);
}
}

Wyświetl plik

@ -0,0 +1,50 @@
<?php
class Cat extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function update($result) {
$this->db->where('radio', $result['radio']);
$query = $this->db->get('cat');
if ($query->num_rows() > 0)
{
// Update the record
foreach ($query->result() as $row)
{
$radio_id = $row->id;
$data = array(
'frequency' => $result['frequency'],
'mode' => $result['mode']
);
$this->db->where('id', $radio_id);
$this->db->update('cat', $data);
}
} else {
// Add a new record
$data = array(
'radio' => $result['radio'],
'frequency' => $result['frequency'],
'mode' => $result['mode']
);
$this->db->insert('cat', $data);
}
}
function status() {
}
}
?>