iot前台开发环境:请求示例

参考链接:http://www.cnblogs.com/keatkeat/category/872790.html

编辑-》update保存

 

一、typescipt

import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import { RequestOptions } from '@angular/http';

import 'rxjs/add/operator/toPromise';

@Injectable()
export class SubnetService {
constructor(private http: Http) {}

getDatas(): Promise<any> {
return this.http.get("/devices")
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}

getData(): Promise<any> {
return this.http.get("/devices/")
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}

update(id, data): Promise<any>{
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.post("/devices/"+ id +"/update", JSON.stringify(data),options)
.toPromise()
.then(response => response.json())
.catch(this.handleError);
}

delete(id): Promise<any> {
return this.http.delete("/devices/"+ id)
.toPromise()
.then(response => response)
.catch(this.handleError);
}

private handleError(error: any): Promise<any> {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}

二、java代码

package com.inspur.iot.iot_hub.controller;

import com.inspur.iot.iot_hub.entity.DmDevicetype;
import com.inspur.iot.iot_hub.service.DeviceService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping(value="/devices") // 通过这里配置使下面的映射都在/devices下,可去除
public class DeviceTypeController {
@Autowired
DeviceService deviceServer;
@ApiOperation(value="获取设备类型列表", notes="")
@RequestMapping(value={""}, method= RequestMethod.GET)
public List<DmDevicetype> getDeviceList() {
List<DmDevicetype> devices = deviceServer.getDevice();
return devices;
}
@ApiOperation(value="查询设备类型", notes="")
@ApiImplicitParam(name = "device", value = "设备查询", required = true, dataType = "Device")
@RequestMapping(value="/code", method=RequestMethod.GET)
public List<DmDevicetype> getDevicesByCode(@PathVariable String code) {
List<DmDevicetype> devices = deviceServer.getDeviceByCode(code);
return devices;
}

@ApiOperation(value="创建设备类型", notes="")
@ApiImplicitParam(name = "device", value = "设备详细实体device", required = true, dataType = "Device")
@RequestMapping(value="", method=RequestMethod.POST)
public DmDevicetype createDevice(@RequestBody DmDevicetype device) {
deviceServer.create(device);
return device;
}

@ApiOperation(value="获取设备详细信息", notes="根据url的id来获取设备详细信息")
@ApiImplicitParam(name = "id", value = "设备ID", required = true, dataType = "String")
@RequestMapping(value="/{id}/detail", method=RequestMethod.GET)
public DmDevicetype getDevice(@PathVariable String id) {
return deviceServer.queryDevice(id);
}

@ApiOperation(value="更新设备详细信息", notes="根据url的id来指定更新对象,并根据传过来的device信息来更新用户详细信息")

@RequestMapping(value="/{id}/update", method=RequestMethod.POST)
public DmDevicetype updateDevice(@PathVariable String id, @RequestBody DmDevicetype device){
deviceServer.updateDevice(id,device);
return device;
}

@ApiOperation(value="删除设备", notes="根据url的id来指定删除对象")
@ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
public String deleteDevice(@PathVariable String id) {
deviceServer.deleteDevice(id);
return "success";
}

}

文档 一步步搭建物联网系统 HTTP vs CoAP 现有的这个版本是HTTP版,目前的CoAP版正在开发中,欢迎加入。 https://github.com/phodal/iot-coap Minimum Internet of Things A Minimum IOT with arduino and raspberry pi. 一个最小的物联网系统设计方案及源码 android/ 一个最小的Android程序实例 rest/ PHP Laravel Framework to create RESTful API python/ 简单的pyhon示例 hardware/ 硬件串口通信收集 -/ arduino Arduino板 doc/ 文档 简介ppt nginx配置 系统框架图 dashboard/ 基于ruby框架dashing的dashboard 简要的初始化代码说明 代码中因为有两个子模块,即Android与REST,Android是一个简单的Android程序示例,REST作为子模块的原因是考虑到后期会用更简单的源码来替换。但是laravel作为一个运行环境,还是很理想的。 先clone git clone git@github.com:phodal/iot.git iot or git clone https://github.com/phodal/iot.git iot 子模块 git submodule init git submodule update 系统框架图 测试 1.将arduino/BareMinimum.ino 烧录到开发板上 2.执行get.py (ps:如果用的是Windows系统 需要将get.py中的 /dev/ttyACM0 改为 COM*.) sudo python python/get.py 3.打开 http://localhost/athome/create 创建一个数据。打开 http://localhost/athome/1/edit 编辑状态 4.测试网址: b.phodal.com 如何在Android手机上测试 1.下载安装 Stay at Home 交流 QQ群:348100589 中文文档 一个最小的物联网系统设计方案及源码 最小物联网系统(一)——系统组成 最小物联网系统(二)——RESTful 最小物联网系统(三)——创建RESTful 最小物联网系统(四)——详解Laravel的RESTful 最小物联网系统(五)——Laravel RESTful模板化 最小物联网系统(六)——Ajax打造可视化 最小物联网系统(七)——与服务器通讯 最小物联网系统(八)——与单片机通讯 最小物联网系统(九)——Android客户端 最小物联网系统设计——给Laravel添加测试 最小物联网系统——Dashboard License © 2014 Phodal Huang. This code is distributed under the MIT license. 标签:物联网
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值