162_RaspberryPi_broken?

あーあ、RaspberryPi君壊しちゃった。。。

Docomoの充電器つなげたら使えるか?実験したら、

左奥のランプ2このうち1つが点灯しない。。。

LAN内でのMACアドレスも反応しない。。。

TV画面にもラズベリーが映らない。。。あーあ。。。

DSC_0077

悲しい。。。。

(様子みて買いなおそうか。。。。)

以上

 

161_RaspberryPi_Temp&humid_data_sending_to_SAKURAVPS

いや、、苦労したけどなんとか。。。。。

でも、、、

・humidデータは0.0のままなのでこれは故障かも?(デバイスの写真)

・RaspberryPi側も+3.3Vを接続するときたまにRinuxが立ち上がらない?(回路の写真)

ので自分の半田不良か?そもそも安い製品のリスク?か。。。

まあ、たまたまできたときなので、一応メモを残しておきましょう。

 

<coding>

#!/usr/bin/env python

# -*- coding: utf-8 -*-
# ドライバをimport
import mysql.connector
import datetime
import wiringpi
import os
import struct
from time import sleep
wiringpi.wiringPiSetup() #setup wiringpi
i2c = wiringpi.I2C() #get I2C
dev = i2c.setup(0x40) #setup I2C device
i2c.write(dev,0x02) #HDC1000 CONFIGURATION POINTER
i2c.write(dev,0x10) #send 1byte
i2c.write(dev,0x00) #send 1byte
sleep((6350.0 + 6500.0 +  500.0)/1000000.0)
dataAry = struct.unpack(“BBBB”,os.read(dev,4))
os.close(dev)
temp3 = (dataAry[0] << 8) | (dataAry[1])
hudi3 = (dataAry[2] << 8) | (dataAry[3])
temp3 = ((temp3 / 65535.0) * 165 – 40)
hudi3 = ((hudi3 / 65535.0 ) * 100)
print “Humidity %.2f %%” % hudi3
print “Temperature %.2f C” % temp3
# ドライバをimport
# import mysql.connector
if __name__ == ‘__main__’:
       # データベースに接続
        connect = mysql.connector.connect(user=’*****i’, password=’******6′, host=’****.****.****.****’, database=’2016*********or’, charset=’utf8′)
        cursor = connect.cursor()
        today = datetime.datetime.today()
        temp_fin=int(temp3)
        hudi_fin=int(hudi3)
        print “————“
        print today.strftime(“%Y-%m-%d %H:%M:%S”)
        print “Final_Humidity %.2f %%” % hudi_fin
        print “Final_Temperature %.2f C” % temp_fin
        print “————“
        ###############
        cmd = ‘insert into t_sensor (time_stamp,temp,humid,water_need,memo) values (“{}”,”{}”,”{}”,”{}”,”{}”)’.format(today.strftime(“%Y-%m-%d %H:%M:%S”),temp_fin, hudi_fin,”Real_Data”,”Real_Data”)
        print cmd
        print “————“
        cursor.execute(cmd)
        cursor.execute(‘DELETE FROM t_sensor ORDER BY Num ASC LIMIT 1’)
        # autocommitではないので、明示的にコミットする
        connect.commit()
        print “success!_20170129”
        # データベースから切断
        cursor.close()
        connect.close()

160_Data_Sending_to_Cumulocity (IoT)_from_PC_win10_itself___but_NG!

Python2をwindows10にインストールしてみます。
参考は、ここ。
http://www.python-izm.com/contents/introduction/install.shtml
(図1)

まず、ダウンロード。ここから
https://www.python.org/downloads/
(図2)

私は、「Python 2.7.13」にします。
(図3)

AllUserでインストール開始
(図4)
簡単、インストール中
(図5)

インストール完了
(図6)
環境変数を設定します。

環境変数ダイアログが表示されます。
システム環境変数の Path を選択して、[編集] ボタンをクリックします。
変数値の末尾に “;C:\Python27” (Python 2.7 をインストールしたフォルダ) を追記します。
今度は、システム環境変数の [新規] ボタンをクリックします。
変数名に PYTHONPATH を、変数名に “C:\Python27\Lib\site-packages” を指定します。
(Python 2.7 をインストールしたフォルダにある Lib\site-packages フォルダ)
[OK] ボタンをクリックして、環境変数ダイアログに戻ります。
これで一応OKかな?
(図7)
では、ここからCumulocityに登録できるか?をやってみます。
コマンドは、下記
(#1)
curl -v -u yoshihara20161226:Aa123456
-H ‘Accept: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’
-H ‘Content-type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’
-X POST
-d ‘{“c8y_IsDevice”:{},”name”:”Device2017/01/28_win10″}’
https://iot05.cumulocity.com/inventory/managedObjects
はい、NG!!!
curlコマンドが使えません、と。そりゃそうだ!
ではインストールしましょう。
ここ参考。
https://www.ipentec.com/document/document.aspx?page=software-install-curl-for-windows
(図8)
今回は、Win64 x86_64 7zipを選びます。
(図9)
同じように、環境設定で、PATH設定もしちゃう!
C:\Users\h1729\Desktop\curl_7_52_1_openssl_nghttp2_x64
OKかな?
(図10)
再度、Createコマンドを投げてみる!
curl -v -u yoshihara20161226:Aa123456 -H ‘Accept: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8;ver=0.9’-H ‘Content-type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ -X POST -d ‘{“c8y_IsDevice”:{},”name”:”Win10_itself_2017/01/29″}’  https://iot05.cumulocity.com/inventory/managedObjects
うーーーん、エラーだにゃーーー!
ちと、今日は風邪ひいて喉が痛いので休憩。。また今度トライ。。。
(図11)
以上

159_Data_Sending_to_Cumulocity (IoT)_from_PC_HyperV(win10)

長いな目だけど、要は自宅PC(win10)上のHyperVで動いているLinux(CentOS6.8)から、前例とおなじようにCumulocityへデータを継続的に送れるか?やってみます。

(図1)まずCentOSへ入ります。

コマンドカーソルを表示して。。。

(図2)コマンドは同じ。まずDeviceのCreateから。

(#1)
curl -v -u yoshihara20161226:Aa123456 \
   -H ‘Accept: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ \
   -H ‘Content-type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ \
   -X POST \
   -d ‘{“c8y_IsDevice”:{},”name”:”Device2017/01/28_win10″}‘ \
   https://iot05.cumulocity.com/inventory/managedObjects

(図3)返信あり。ConnectedとかCreatedが見えればOK、、、ぽい。

(図4)Cumulocityにはいってみると、「Device2017/01/28_win10」が見えます。当たり前だけど。。

 

(図5)さあ、単品でデータを送信してみる、、と。今度のIDは「33581」。ここだけ修正して、、、と。

(#2)
curl -v -u yoshihara20161226:Aa123456 \
  -H ‘Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ \
  -H ‘Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ \
  -X POST \
  -d ‘{“c8y_TemperatureMeasurement”:{“T”:{“value”:30,”unit”:”C”}},”time”:”2017-01-28T00:00:00.123+02:00″,”source”:{“id”:”33581“},”type”:”c8y_PTCMeasurement”}’ \
  https://iot05.cumulocity.com/measurement/measurements/

さて、反応は。。。。。OKかな???

画面では、Measurementタブができているので、明日あたりデータ見えるかな??

では、Python+crontabで連続定期的ダミーデータ送信、、、にトライ。

同様に、これでいくね!!

cmd1 = “curl -v -u yoshihara20161226:A******6
cmd2 = “-H ‘Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ “
cmd3 = “-H ‘Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ “
cmd4 = “-X POST “
cmd5 = “-d ‘{\”c8y_TemperatureMeasurement\”:{\”T\”:{\”value\”:”
cmd6 = str(temp) + “”
cmd7 = “,\”unit\”:\”C\”}},\”time\”:\””
cmd8 = str(dt_iso) +””
cmd9 = “\”,\”source\”:{\”id\”:\”33581\”},\”type\”:\”c8y_PTCMeasurement\”}’ “
cmd10 = “https://iot05.cumulocity.com/measurement/measurements/”
os.system(cmd1+cmd2+cmd3+cmd4+cmd5+cmd6+cmd7+cmd8+cmd9+cmd10)

crontabも設定しました。

*/1 * * * * python 20170128_to_cum_win10_1

さあ、様子みましょう!!

 

以上

 

 

 

 

158_data_sending_to_Cumulocity (IoT)2_crontab

IoTチームのために、何かお役にたてば、、とブログだけ。。
まず、Python2の復習。
エスケープシーケンスを使うのでメモ掲載、
改行とか。表は下記参考に。
(figure1)
 
で、さて、まずは、Deviceの登録をします。
マニュアルによると、「Create」から。。。。。
Linuxでのコマンドは。下記。
ID、Passをそのまま載せているけど悪さしないでね>見ている人
デバイス名は「HelloWorldDevice2017/01/24にとりあえず。
==================
(#1)
curl -v -u yoshihara20161226:A******6 \
   -H ‘Accept: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ \
   -H ‘Content-type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ \
   -X POST \
   -d ‘{“c8y_IsDevice”:{},”name”:”HelloWorldDevice2017/01/24“}’ \
   https://iot05.cumulocity.com/inventory/managedObjects
さて、入ってみましょう! 
https://iot05.cumulocity.com/
 
右上メニューからDeveice Managementをクリック
(figure 2)
connectionができれば、簡単に「dvice登録」されました!
ALLDeveicesをみると、、「HelloWorldDevice2017/01/24が登録されてます。
で、デバイスをクリックすると、、
デバイスのInfo画面がでます。。。
右下に下がって、そこにデバイスIDが割振りされます。
これを使って、RESTで送ると、飲み込んでくれる仕組みです。
 
さて、次にwebでdeviceのIDを「デバイスID」に設定して、
pythonファイルを作成します。。。。
==================
ID=31124  <====これが私のデバイスのID!!! 
==================
#!/usr/bin/python
# coding: UTF-8
import os
import random # モジュールのインポート
from datetime import datetime
temp=random.randint(0, 100)
#dt=datetime.now()
dt_iso=datetime.now().isoformat()
print “————————-\\”
print temp
print dt_iso
print “————————-\\”
print “curl -v -u yoshihara20161226:A******6 “
print “-H ‘Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ “
print “-H ‘Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ “
print “-X POST “
print “-d ‘{\”c8y_TemperatureMeasurement\”:{\”T\”:{\”value\”:”
print str(temp)+ “”
print “,\”unit\”:\”C\”}},\”time\”:\””
print str(dt_iso) +””
print “\”,\”source\”:{\”id\”:\”31124\”},\”type\”:\”c8y_PTCMeasurement\”}’ “
print “https://iot05.cumulocity.com/measurement/measurements/”
print “————————–\\”
cmd1 = “curl -v -u yoshihara20161226:A******6 “
cmd2 = “-H ‘Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ “
cmd3 = “-H ‘Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ “
cmd4 = “-X POST “
cmd5 = “-d ‘{\”c8y_TemperatureMeasurement\”:{\”T\”:{\”value\”:”
cmd6 = str(temp) + “”
cmd7 = “,\”unit\”:\”C\”}},\”time\”:\””
cmd8 = str(dt_iso) +””
cmd9 = “\”,\”source\”:{\”id\”:\”31124\”},\”type\”:\”c8y_PTCMeasurement\”}’ “
cmd10 = “https://iot05.cumulocity.com/measurement/measurements/”
os.system(cmd1+cmd2+cmd3+cmd4+cmd5+cmd6+cmd7+cmd8+cmd9+cmd10)
 
コマンドファイルができたら、送ってみます!!Pythonで実行!!
==================
pi@raspberrypi-20161228:~ $ python 20170124_pytocum1
==================
下記、表示結果のPrint。うまく行ってるみたいね!!!
————————-\
96
2017-01-24T21:43:49.023410
————————-\
curl -v -u yoshihara20161226:Aa123456
-H ‘Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’
-H ‘Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’
-X POST
-d ‘{“c8y_TemperatureMeasurement”:{“T”:{“value”:
96
,”unit”:”C”}},”time”:”
2017-01-24T21:43:49.023410
“,”source”:{“id”:”31124″},”type”:”c8y_PTCMeasurement”}’
https://iot05.cumulocity.com/measurement/measurements/
————————–\
* Hostname was NOT found in DNS cache
*   Trying 52.28.26.32…
* Connected to iot05.cumulocity.com (52.28.26.32) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
* subject: C=DE; ST=Nordrhein-Westfalen; L=Duesseldorf; O=Cumulocity GmbH; CN=*.cumulocity.com
* start date: 2016-08-01 09:55:38 GMT
* expire date: 2017-08-05 10:35:38 GMT
* subjectAltName: iot05.cumulocity.com matched
* issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority – G2
* SSL certificate verify ok.
* Server auth using Basic with user ‘yoshihara20161226’
> POST /measurement/measurements/ HTTP/1.1
> Authorization: Basic eW9zaGloYXJhMjAxNjEyMjY6QWExMjM0NTY=
> User-Agent: curl/7.38.0
> Host: iot05.cumulocity.com
> Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9
> Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9
> Content-Length: 148
>
* upload completely sent off: 148 out of 148 bytes
< HTTP/1.1 201 Created
* Server nginx is not blacklisted
< Server: nginx
< Date: Tue, 24 Jan 2017 12:43:50 GMT
< Content-Type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: https://iot05.cumulocity.com/measurement/measurements/31108
< Strict-Transport-Security: max-age=31536000; includeSubDomains
<
* Connection #0 to host iot05.cumulocity.com left intact
{“time”:”2017-01-24T21:43:49.023Z”,”id”:”31108″,”self”:”https://iot05.cumulocity.com/measurement/measurements/31108″,”source”:{“id”:”30909″,”self”:”https://iot05.cumulocity.com/inventory/managedObjects/30909″},”type”:”c8y_PTCMeasurement”,”c8y_TemperatureMeasurement”:{“T”:{“unit”:”C”,”value”:96}}}
 
最後に、周期的やらせるため、crontabを設定。
あとは様子見。。。。。
==================
*/1 * * * * sudo python 20170124_pytocum1
==================
うまく出てますね!!!
ボイスSOデリバリIoTチームがんばれ!応援してます。。。。
発表会終わったら飲もう!!!
以上

157_data_sending_to_Cumulocity (IoT)

Cumulocityのドキュメントに従ってこの手順通りでやってみる。
参考Webはここ。
https://cumulocity.com/guides/rest/introduction/
私の設定情報は下記。そのまま掲載。
—————-
設定情報
—————-
https://iot05.cumulocity.com
Username : yoshihara20161226
Password : A******
System ID:***** (←★これはcumulocity見て確認需重要!!★)
Name :RaspPi BCM2709 0000000075b****f
Model:RaspPi BCM2709
Serial number:0000000075b****f
Revision :a02082
Type:c8y_Serial
Id:linux-0000000075b****f
Firmware version :mhf
—————-
さて、まずVNCで接続して、、、、RaspberryPi君!ようこそ!
(図1)
Cumulocityにも接続します。自分のOD、Passで!
(図2)
DevicemanagementでAll devicesを選択。一覧表示。
(図3)
DeveieResistrationは特にやらなくとも、RaspberryPiを一度接続したら勝手に認識したなあ。。。ここは別途要確認。。
これは、あえてシリアル番号入れて登録した画面。
(図4)
少し時間たつと、勝手にRaspberryPiの情報を送受した??別途要確認。。。
(図5)
ここから、、、
(#1 send)DeviceCreateをする。コマンドは、下記。Linuxでcurlコマンドで。cumulocityへ投げつける。
$ curl -v -u yoshihara20161226:A****** \
>    -H ‘Accept: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ \
>    -H ‘Content-type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9’ \
>    -X POST \
>    -d ‘{“c8y_IsDevice”:{},”name”:”HelloWorldDevice”}’ \
>    https://iot05.cumulocity.com/inventory/managedObjects
(#1 results)
すると、下記のresponceが返ってくる。中ほどの”HTTP/1.1 201 Created”があれば多分コマンドはうまく行ったはず。。。。
(図6)
* Hostname was NOT found in DNS cache
*   Trying 52.28.26.32…
* Connected to iot05.cumulocity.com (52.28.26.32) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* Server certificate:
*   subject: C=DE; ST=Nordrhein-Westfalen; L=Duesseldorf; O=Cumulocity GmbH; CN=*.cumulocity.com
*   start date: 2016-08-01 09:55:38 GMT
*   expire date: 2017-08-05 10:35:38 GMT
*   subjectAltName: iot05.cumulocity.com matched
*   issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.; OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate Authority – G2
*   SSL certificate verify ok.
* Server auth using Basic with user ‘yoshihara20161226’
> POST /inventory/managedObjects HTTP/1.1
> Authorization: Basic eW9zaGloYXJhMjAxNjEyMjY6QWExMjM0NTY=
> User-Agent: curl/7.38.0
> Host: iot05.cumulocity.com
> Accept: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9
> Content-type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9
> Content-Length: 45
>
* upload completely sent off: 45 out of 45 bytes
< HTTP/1.1 201 Created
* Server nginx is not blacklisted
< Server: nginx
< Date: Tue, 17 Jan 2017 13:23:11 GMT
< Content-Type: application/vnd.com.nsn.cumulocity.managedObject+json; charset=UTF-8; ver=0.9
< Transfer-Encoding: chunked
< Connection: keep-alive
< Location: https://iot05.cumulocity.com/inventory/managedObjects/30506
< Strict-Transport-Security: max-age=31536000; includeSubDomains
<
* Connection #0 to host iot05.cumulocity.com left intact
{“assetParents”:{“references”:[],”self”:”https://iot05.cumulocity.com/inventory/managedObjects/30506/assetParents”},”childAssets”:{“references”:[],”self”:”https://iot05.cumulocity.com/inventory/managedObjects/30506/childAssets”},”childDevices”:{“references”:[],”self”:”https://iot05.cumulocity.com/inventory/managedObjects/30506/childDevices”},”creationTime”:”2017-01-17T14:23:11.768+01:00″,”deviceParents”:{“references”:[],”self”:”https://iot05.cumulocity.com/inventory/managedObjects/30506/deviceParents”},”id”:”30506″,”lastUpdated”:”2017-01-17T14:23:11.768+01:00″,”name”:”HelloWorldDevice”,”owner”:”yoshihara20161226″,”self”:”https://iot05.cumulocity.com/inventory/managedObjects/30506″,”c8y_IsDevice”:{}}
(#2  data send)次に、データ送信。curlコマンドで自分の”ID””Pass””(#1)でのResponceでのid”を変えてあげて下記コマンドを送信。
curl -v -u yoshihara20161226:A****** \
-H ‘Accept: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ \
-H ‘Content-type: application/vnd.com.nsn.cumulocity.measurement+json; charset=UTF-8; ver=0.9’ \
-X POST \
-d ‘{“c8y_TemperatureMeasurement”:{“T”:{“value”:30.00,”unit”:”C”}},”time”:”2017-01-22T13:00:00.123+02:00″,”source”:{“id”:”*****”},”type”:”c8y_PTCMeasurement”}’ \
https://iot05.cumulocity.com/measurement/measurements/
(#2  data send Results)おなじように、中ほどの”HTTP/1.1 201 Created”があれば多分コマンドはうまく行ったはず。。。。
(図7)
(図8)
(図9)
Cockpitmニューからも見れます。
数日したほうがデータ推移が見れるかも。。
まあまだ、あいまい部分多いけど。。。。とりあえず。
以上。

156_API-test_on_sakuravps

############
今回は、livedoorで天気予報のAPIを学ぶ,,,です。
Postmanの使い方を学んでいるうちに、出くわしたのがこのWebだったので、
せっかくなのでそのままブログ。。。。
############
2017/01/15
cumulocity postman API check
postmanの使い方とAPIを学ぶ、今回は

を参考に。
ーーーーーーー
まず、Postmanを使ってみる
ーーーーーーー
PostmanはGoogle Chromeのアドオン、WEBアプリ。
まずは以下からダウンロードしてインストール。
http://www.getpostman.com/
起動するとURLを入力する場所にURLを入力、
今回は習ってlivedoor 天気情報を取得、「データフォーマットはJSON形式」との事。
livedoorのAPIの仕様は下記
http://weather.livedoor.com/weather_hacks/webservice
http://weather.livedoor.com/forecast/rss/primary_area.xml
  JSONデータをリクエストする際のベースとなるURLは以下。
http://weather.livedoor.com/forecast/webservice/json/v1
このURLに下の表のパラメータを加え、実際にリクエスト。
この情報を元に、早速Postmanに入れてみる。
(図1)
Capture_2017_01_15_17_32_21_920
では、Sendボタンを押してみる。
(図2)
Capture_2017_01_15_17_33_16_547
200 OKでパラメータが返ってくるかと問題なし、のようです。
形式はJSONとの事。
(図3)
Capture_2017_01_15_17_35_55_536
あとはこの情報を元に自身のサイトに表示できるようにします。

今回は参考に習ってPHPで。
/var/www/html/
の配下に
API-test
フォルダを作成して、
20170115_tenki_simple.php
を作成します。
(図4)

Capture_2017_01_15_17_40_38_357
中身は非常に簡単(マネさせてもらった)で、
指定した地域の今日の天気とアイコンを表示するのみ。
——————
<?php
$tmp_url = “http://weather.livedoor.com/forecast/webservice/json/v1?city=130010”;
$json = file_get_contents($tmp_url,true) or die(“Failed to get json”);
$json = mb_convert_encoding($json, ‘UTF8’, ‘ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN’);
$obj = json_decode($json);
$img_url = $obj->forecasts[0]->image->url;
$date = $obj->forecasts[0]->date;
$title = $obj->forecasts[0]->image->title;
$img_url1 = $obj->forecasts[1]->image->url;
$date1 = $obj->forecasts[1]->date;
$title1 = $obj->forecasts[1]->image->title;
?>
<h2>東京都の天気</h2>
<h4>(2017/01/15作成)</h4>
<div>
<p> TODAY : <?php echo $date;?></p>
<p> <?php echo “<img src='”.$img_url.”‘>”; ?> <?php echo $title; ?></p>
<p> copyright <a href=”http://weather.livedoor.com/”>livedoor 天気情報</a>'</p>
<p> TOMMOROW : <?php echo $date1;?></p>
<p> <?php echo “<img src='”.$img_url1.”‘>”; ?> <?php echo $title1; ?></p>
<p> copyright <a href=”http://weather.livedoor.com/”>livedoor 天気情報</a>'</p>
</div>
——————
(図5)
Capture_2017_01_15_20_33_01_185
なんとか出ました!
以上!

155_RasPi_random_py_to_sql

あーーーあ、GNDと+V.V前後間違えて差し込んでしまった!!(反省。。。)

壊れたと思う、、、RaspberryPi君がチップ挿すと立ち上がらない。。。。多分短絡してるのかと。。。。あーーーーーーあ。。。

img_1160

img_1159img_1158

なので、、、、RasberryPi君からrandom数値をsakuravpsへ飛ばすのとどめます。。(悲)

ーーーーーーーーーーーーーーー

mysql-connector-pythonインストール方法
reference to
http://qiita.com/cjeecsiy/items/2fca0d674bcdedb235ad
$ git clone https://github.com/mysql/mysql-connector-python.git
$ cd mysql-connector-python
$ python ./setup.py build
$ sudo python ./setup.py install

$ python
>>> import mysql.connector as msc
>>> msc.__version__
‘2.1.3’

=================================
python 20170111_pytosql_rd1
=================================
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ドライバをimport
import mysql.connector
import random

if __name__ == ‘__main__’:
# データベースに接続

# localhost access ok!!!!!
# connect = mysql.connector.connect(user=’****’, password=’****’, host=’localhost’, database=’20161229_se***r’, charset=’utf8′)

# connect OK!!!! and select OK!!!!!
connect = mysql.connector.connect(user=’raspai’, password=’A******6′, host=’160.16.***.187′, database=’20161129_s****r’, charset=’utf8′)
cursor = connect.cursor()

# insert
# cursor.execute(‘insert into t_sensor values(20170107,100,100,”test_Raspberry”,”test_success_on_2017/01/06″‘)

# success!!
# cursor.execute(‘insert into t_sensor (time_stamp,temp,humid,water_need,memo) values (%s, %s, %s, %s, %s)’, (‘2017-01-07′,’50’,’50’,’test_from_RaspberryPi3′,’test_success_on_2017/01/06′))

temp1=random.randint(1,40)
humid1=random.randint(1,100)

cursor.execute(‘insert into t_sensor (time_stamp,temp,humid,water_need,memo) values (now(), %s, %s, %s, %s)’, (temp1,humid1,’test_random’,’from_rasp_pi_success!2017/01/11′))
# autocommitではないので、明示的にコミットする
connect.commit()

print(“insert success!”)
# データベースから切断
cursor.close()
connect.close()
=================================
crontab -e
=================================

50 * * * * sudo 20170111_pytosql_rd1
What is going on??——>OK!!!!!!

154_RasPi_温度湿度測定のセンサ焦がしたかも?(失敗?)

いよいよ、センサに接続。。。。。

img_1154

 

でも焦げ臭いにおいが。。。

img_1155

センサ焦がしてしまったかも。。。。あーあ。。。

一応ブログ。。。

======
reference to the URL

Code Python2 is below

-rw-r–r– 1 pi pi 653 1月 9 14:30 20170109_tmp1.py
-rw-r–r– 1 pi pi 658 1月 9 15:38 20170109_tmp2.py

(測定ファイルのPythonファイルは、20170109_tmp1.pyもしくは20170109_tmp2.py)

===============
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import wiringpi
import os
import struct
from time import sleep
wiringpi.wiringPiSetup() #setup wiringpi
i2c = wiringpi.I2C() #get I2C
dev = i2c.setup(0x40) #setup I2C device
i2c.write(dev,0x02) #HDC1000 CONFIGURATION POINTER
i2c.write(dev,0x10) #send 1byte
i2c.write(dev,0x00) #send 1byte
sleep((6350.0 + 6500.0 + 500.0)/1000000.0)
dataAry = struct.unpack(“BBBB”,os.read(dev,4))
os.close(dev)
temp = (dataAry[0] << 8) | (dataAry[1])
hudi = (dataAry[2] << 8) | (dataAry[3])
temp = ((temp / 65535.0) * 165 – 40)
hudi = ((hudi / 65535.0 ) * 100)
print “Humidity %.2f %%” % hudi
print “Temperature %.2f C” % temp
===============

But error occors and says
ImportError: No module named wiringpi

Then I need to install wiringgpi
reference to

WiringPi2 for Pythonをインストールする

WiringPi2のインストール

$ sudo pip install wiringpi2

message was
Successfully installed wiringpi2 wiringpi
Cleaning up…

OK!

wiringPiSetupを使うにはroot権限が必要なので、sudo pythonとしなければならない。

then

$ sudo python 20170109_tmp1.py

============

うーーーん、仕切り直し!!!

下記を参考に、
referenece to the URL
http://qiita.com/satorukun/items/0d8457df566975195f97

センサーモジュール接続

センサーモジュール設定手順
SPI有効
$ sudo raspi-config
「9 Advanced Options」 → 「A5 SPI」 → 「SPI enable」
I2C有効
$ sudo raspi-config
「9 Advanced Options」 → 「A6 SPI」 → 「I2C enable」
I2Cモジュール設定
I2Cモジュール読み込み設定
$ sudo vi /etc/modules
snd-bcm2835
i2c-dev
I2Cライブラリインストール
$ sudo apt-get install libi2c-dev
gitインストール
$ sudo apt-get install git-core
アップデート
$ sudo apt-get update
$ sudo apt-get upgrade
WiringPiインストール
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build
ライブラリパス設定
ライブラリパス追加設定
$ sudo vi /etc/ld.so.conf
$ sudo ldconfig

include /etc/ld.so.conf.d/*.conf
/usr/local/lib

センサーモジュールアドレス確認
$ sudo i2cdetect -y 1

img_1157

$ sudo python 20170109_tmp1.py

img_1156

OK!!!

うーーん、でも。

センサは、sudo Python。。。で動くけど

MySQLは(#では)動かない、、$なら動くけど。。

パスの設定か?インストールのミスか。。。。

もうひ一息なのになあ。。。。

 

以上

 

[153] (2017/01/08)153_RasPi_温度湿度測定の準備_はんだ付け

はんだ付けしました。下手ですが、うまく動けばよいか、と。。

1.まず準備一覧(下図)

img_1152

 

2.はんだ付けしたあと、3、4がくっついている??心配。。。(下図)

img_1149

 

3.なんとか、はんだの山はつながってないかな???大丈夫かも。。。。(下図)

img_1150

 

こんなセッティングでやりました。くまお曰く「それだけのためにこんなに準備したのー?」。

まあ、その通りだけど用意周到、準備万端でないと。。。それでも失敗リスクはつきもの。

(下図)

img_1151

さあ、いよいよ配線して、読み取りできるか?!(次回)

以上!