DataMark 云便签 API
JSON 操作 DataMark 数据项
地址:http://dm.trtos.com/php/json.php
Post 添加数据
{"action":"add","id":"y9JM9Rd","content": [{"name": "项目1","value": "5555"},{"name": "项目2","value": "1234"}]}
返回
{"action":"add","status":"succeed"}
Post 删除所有数据
{"action":"del","id":"y9JM9Rd"}
返回
{"action":"del","status":"succeed"}
Post 获取分配ID
{"action":"getid"}
返回
{"action":"getid","id":"y9JM9Rd"}
Post 获取记录(必要参数id,可选参数name,value)
{"action":"get","id":"y9JM9Rd"}
{"action":"get","id":"y9JM9Rd","name":"项目1"}
{"action":"get","id":"y9JM9Rd","name":"项目1","value":"5555"}
返回
[{"Name":"Name1","Value":"xiaowu"},{"Name":"Name2","Value":"Xiaotian"}]
上传背景图代码 可用于监控
#!usr/bin/python
# image.py
# -*- coding=utf-8 -*-
from poster.encode import multipart_encode
import urllib2
import sys
from urllib2 import Request, urlopen, URLError, HTTPError
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
register_openers()
f=open("4UTmPcpw.jpg", "rb")
datagen, headers = multipart_encode({"myFile": f})
request = urllib2.Request("http://trtos.com/web/datamark/upload.php", datagen, headers)
try:
response = urllib2.urlopen(request)
print response.read()
except URLError,e:
print e.reason
print e.code
修改数据标签 指定选项内容
这种方式比较简单 直接通过浏览器访问方式操作
eg:设置名和值 http://dm.trtos.com/web/datamark/update.php?id=5oOeooHz&index=149717&name=使用率&value=99%
eg:设置名 http://dm.trtos.com/web/datamark/update.php?id=5oOeooHz&index=149717&name=使用率
eg:获取名和值 http://dm.trtos.com/web/datamark/update.php?id=5oOeooHz&index=149717
下例 是使用python 上传 ip地址
import requests
import datetime
import socket
def get_host_ip():
"""
查询本机ip地址
:return: ip
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
ip="0.0.0.0"
ip=get_host_ip()
date=datetime.datetime.now()
response = requests.get('http://dm.trtos.com/web/datamark/update.php?id=5oOeooHz&index=149717&name=树莓派IP&value='+ip+":"+str(date))
print(response.text)
共享变量
设置值 http://www.trtos.com/php/value.php?name=my_value&value=123456
读取值 http://www.trtos.com/php/value.php?name=my_value