source: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoBluemixMQTT/CiaoBluemixMQTT.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.3 KB
Line 
1/*
2 Arduino Ciao example
3
4 This sketch uses Ciao mqtt connector. Sketch sends via MQTT brightness and temperature information that will be shown graphically in the blueMix IBM system.
5 Upload your sketch an than connect to the webpage:
6 https://quickstart.internetofthings.ibmcloud.com/#/device/BlueMixTest902345/sensor/
7
8 NOTE: be sure to activate and configure mqtt connector on Linino OS.
9 http://labs.arduino.org/Ciao
10
11 created September 2015
12 by andrea[at]arduino[dot]org
13
14 */
15
16#include <Ciao.h>
17
18int ctrl=0;
19void setup()
20{
21 Ciao.begin(); //Start the serial connection with the computer
22 //to view the result open the serial monitor
23 pinMode(9,OUTPUT);
24}
25
26void loop() // run over and over again
27{
28 //getting the voltage reading from the temperature sensor
29 int readingTemp = analogRead(A0);
30 // converting readingTemp to voltage
31 float voltage = readingTemp * 4.56;
32 voltage /= 1024;
33 // now print out the temperature
34 float temperatureC = (voltage - 0.5) * 100 ;
35 int readingLum = analogRead(A2);
36
37 analogWrite(9,map(readingLum,0,1023,0,255));
38
39 if (ctrl>=10){
40 Ciao.write("mqtt","iot-2/evt/status/fmt/json","{\"d\": {\"temperature\":"+String(temperatureC)+",\"luminosity\":"+String(readingLum)+"}}");
41 ctrl=0;
42 }
43 ctrl++;
44 delay(100);
45
46}
Note: See TracBrowser for help on using the repository browser.