Added /API/RADIO which allows JSON Posting of radio information
这个提交包含在:
父节点
c22b5585c9
当前提交
1fccf90cef
共有 2 个文件被更改,包括 75 次插入 和 0 次删除
|
|
@ -306,4 +306,29 @@ class API extends CI_Controller {
|
||||||
// Return the arguments
|
// Return the arguments
|
||||||
return $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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
50
application/models/cat.php
普通文件
50
application/models/cat.php
普通文件
|
|
@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
正在加载…
在新工单中引用