From 1fccf90cef73f3c7a627c9b03d3973a3cdf7ef4c Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sat, 7 Apr 2012 17:36:38 +0100 Subject: [PATCH] Added /API/RADIO which allows JSON Posting of radio information --- application/controllers/api.php | 25 +++++++++++++++++ application/models/cat.php | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 application/models/cat.php diff --git a/application/controllers/api.php b/application/controllers/api.php index 659b83e4..3cdc4618 100644 --- a/application/controllers/api.php +++ b/application/controllers/api.php @@ -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); + + } } diff --git a/application/models/cat.php b/application/models/cat.php new file mode 100644 index 00000000..e661b9d4 --- /dev/null +++ b/application/models/cat.php @@ -0,0 +1,50 @@ +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() { + + } + + } +?> \ No newline at end of file