LoginSignup
1
1

More than 5 years have passed since last update.

ThingSpeak / python > データアップロード実装例 / プロットしてみた

Last updated at Posted at 2016-01-09

ThingSpeakへのデータアップロードのpython実装例。

httplibとurllibを使用している。

2011年4月にはすでに存在しているサービスのようだ。

やってみた

動作環境
Raspberry Pi2 + raspbian

pythonターミナルで上記の例をやってみた。
(API KEYは以下のものからすでに変更済み)

pi@raspberrypi ~ $ python
Python 2.7.9 (default, Mar  8 2015, 00:52:26) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib, urllib
>>> params = urllib.urlencode({'field1': 12, 'field2': 11, 'key':'BD6xM4sZEyT8'})
>>> print params
field2=11&field1=12&key=BX8D6M4U0GZE5KT8
>>> headers = {"Content-type": "application/x-www-form-urlencoded","Accept":  
...     "text/plain"}
>>> conn = httplib.HTTPConnection("api.thingspeak.com:80")
>>> conn.request("POST", "/update", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
200 OK
>>> conn.close()
>>> params = urllib.urlencode({'field1': 3, 'field2': 2, 'key':'BD6xM4sZEyT8'})
>>> conn = httplib.HTTPConnection("api.thingspeak.com:80")
>>> conn.request("POST", "/update", params, headers)
>>> response = conn.getresponse()
>>> conn.close()
>>> 

下記のようにプロットされた。
https://thingspeak.com/channels/77614

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1