yidlhu / blockchaindemo

9 stars 10 forks source link

How to create your own Node-Red enviroment in Bluemix

The intent of this guide in this section primary focus on the client environment to create Node-Red to connect to the IoT Websocket services in order to get the data from the device.

Before your start this guide in this section, assume you completed some pre-condition, which include: 1) User already have Bluemix account, space, and already in some organization 2) User already have some knowledge about node-red and already knew how to use it

If you are not satisfied the pre-condition, please following the guide in the invitation letter to have your own Bluemix account.

1. Click the 'menu' icon on the top left, and select the 'Dashboard' option to move your page to the 'Dashboard'

screen shot 2017-08-02 at 11 13 14 am

2. Click the 'Create App' button in the 'All Apps' section in order to create your node-red app

screen shot 2017-08-02 at 11 14 47 am

3. In the search box type 'node-red' to speed up to seek the 'Node-RED Starter', then click the item

screen shot 2017-08-02 at 11 16 38 am

4. Input App Name, give an unique name. As my example, I used 'myownnode' as my unique name, then click the 'Create' button

The node-red starter template default to binding Node-RED app and Cloudant DB. The initial process will take some time, since the Bluemix need to initial the environment and grant the database service authority.

screen shot 2017-08-02 at 11 21 04 am screen shot 2017-08-02 at 11 21 05 am

5. Click the 'Visit App URL' link to launch your Node-RED when it was ready. It will show you some configuration step on the page.

screen shot 2017-08-02 at 11 25 36 am

1) On the first page, just click 'Next' Button, to move the next page.

screen shot 2017-08-02 at 11 27 50 am

2) The second page required your security strategy and ask you to provide the name/password to access the app, just choose the 'Allow anyone to access the editor' option in order to simplified the step.

screen shot 2017-08-02 at 11 28 33 am

3) Leave the the third page and just click the 'Next' Button, not choose any option from the page.

screen shot 2017-08-02 at 11 31 03 am

4) Click the 'Finish' Button to complete the initialization process and waiting for your Node-RED getting started.

screen shot 2017-08-02 at 11 33 21 am

6. Click 'Go to your Node-RED flow editor' button and move to the flow editor page and start to config your flow

screen shot 2017-08-02 at 11 33 50 am

1) Drag 'Websocket' node from the 'Input' section.

screen shot 2017-08-02 at 11 36 36 am

2) Double Click the 'Websocket' node, it will open the configuration page.

screen shot 2017-08-02 at 11 39 11 am

3) 'Type' Options => 'Connect to', click 'Edit' button right behind 'URL'.

screen shot 2017-08-02 at 11 39 11 am

4) 'URL' input box value is 'ws://sensoriot.mybluemix.net/ws/iot', select 'Send/Recieve Payload' options, then click 'Update' button, it will move to the previous page, then you can input the nick name for node or leave it as empty. Then, click 'Done' button to finish the configuration.(I input the nick name 'iot-device' for this node in my sample)

screen shot 2017-08-05 at 3 10 32 pm screen shot 2017-08-02 at 11 39 42 am

5) From function section drag 'json' node in order to format the incoming data from string to json

screen shot 2017-08-02 at 11 41 09 am

6) Drag the 'Debug' node from output section, it will be renamed to 'msg.payload' automatiically, and connect 'iot-device' node, 'json' node, and 'msg.payload' node by drag from entry point to the other. Like the sample I provided below.

screen shot 2017-08-02 at 11 41 45 am

7) Drag another 'Websocket' node from output section, double click to edit.

screen shot 2017-08-02 at 1 36 55 pm

8) 'Type' options => 'Linsen on', click edit URL for defining your Websocket service path. (My sample is '/ws/client/blockchain') Select 'Send/Recieve entire message' and then click 'Update' Button, then it move to the previous page, then click 'Done' button.

screen shot 2017-08-02 at 11 42 13 am screen shot 2017-08-02 at 11 42 52 am

9) Drag the entry point and connect the nodes betwee 'jason' and 'Websocket' node your created just now. Then click the 'Deploy' button on the top of righ side.

screen shot 2017-08-02 at 1 42 06 pm

10) please remember we will use the websocket link in this page in later step.

screen shot 2017-08-02 at 1 42 06 pm

Now you complete the your Node-RED build part in this guide

Next Step -- Follow the Guide for Blockchain on VirtualBoxVM environment --

#

请点击下面链接进行Blockchain的配置

https://github.com/yidlhu/blockchaindemo/blob/master/GuideForVirtualBoxVM.MD

# # # #




< 这一部分比较耗时,已经在虚拟机里面配置完毕,大家不必重新配置,建议课后自行练习 >How to deploy blockchain demo into local docker environment

The goal is to deploy blockchain demo on local blockchain docker images. It is a blockchain demo for 2017 innovation day training.

1. Find your project folder, e.g. /Users/Documents/Blockchain@Local, then run the command: 'unzip fabric_images_v0.6.1.tar.zip' to extract fabric images

2. Need to import fabric images (Keep the below file with same folder with "fabric_images_v0.6.1.tar")by following steps:

### (Mac/Linux)

open Terminal and execute the file: * fabric_import.sh * by the commands:

eg: 
` ./fabric_import.sh `

 ### (Windows)

 (1) Start Menu at All Apps > Windows System > Run
 (2) run command line interface by input: * cmd *
 (3) go to the folder you stored the tar file and execute the batch file.

 eg:    
 ` ./fabric_import.bat `

3. Verify docker images with the below command:

` docker images `

(should include 3 images as below: hyperledger/fabric-membersrvc:x86_64-0.6.1-preview , hyperledger/fabric-peer:x86_64-0.6.1-preview , fabric_client:v0.6.1 )

3 docker images

4. Startup docker network and keep this terminal opening

(Keep the below file in the current folder) docker-compose.yml docker-compose up

5 docker-compose up

5. Verify docker containers(Open another terminal #Tip1)

run the command docker ps (should include 3 containers as below: client_dev_s , peer_dev_s , ca_dev_s)

6 docker ps

6. Login docker container of blockchain app

run the command docker exec -it client_dev_s /bin/bash

7 docker exec

7. Startup web application

cd $WORKSPACE/apps/DEMO root@xxx:~/workspace/apps/DEMO/startup.sh

8 1 8 2

8. Visit app with browser

9 visit app with browser

<下午练习>

Exercises:

1. Make a chaincode "hello" and do unit testing.

1.1. enter the fabric_client environment of Docker Container(In new Terminal)

docker exec -it client_dev_s /bin/bash

1.2. compile chaincode

cd $GOPATH/src/chaincodes/hello
go build

1.3. do unit testing

go test

2. Startup chaincode "hello" in DEV mode by REST

2.1. enter the fabric_client environment of Docker Container(In new Terminal)

docker exec -it client_dev_s /bin/bash

2.2. startup chaincode DEV environment

cd $GOPATH/src/chaincodes/hello/scripts
./startup.sh

3. Access chaincode "hello" by REST (Deploy, Invoke, Query)

3.1. enter the fabric_client environment of Docker Container(In new Terminal)

docker exec -it client_dev_s /bin/bash

3.2. deploy chaincode

cd $GOPATH/src/chaincodes/hello/scripts
./enroll.sh
./deploy.sh

3.3. invoke chaincode

./invoke.sh

3.4. query chaincode

./query.sh

Tips:

1. If you want to reopen this environment, please open a new terminal and execute command "docker-compose down" in workspace dir and then execute command "docker- compose up".

2. When you open a new terminal in Windows every time, please execute "docker-machine env" to initialize docker environment firstly.

3. For Bluemix Environment

guide: https://github.com/yidlhu/blockchaindemo/blob/master/readme%40bluemix.txt

workspace: https://ibm.box.com/s/dj4p2dzxw02ibvt8ppubigcangzqvk69