Dragino PAB2 Скачать руководство пользователя страница 23

 

 

 

4.4

 

Example 4: Use MQTT 

Introduction: 

MQTT is a machine-to-machine (M2M)/"Internet of Things" connectivity protocol. It was 

designed as an extremely lightweight publish/subscribe messaging transport. It is useful for 

connections with remote locations where a small code footprint is required and/or network 

bandwidth is at a premium. For example, it has been used in sensors communicating to a broker 

via satellite link, over occasional dial-up connections with healthcare providers, and in a range of 

home automation and small device scenarios. It is also ideal for mobile applications because of 

its small size, low power usage, minimised data packets, and efficient distribution of information 

to one or many receivers.   

 

This example shows how to use Yun Shield with SSL MQTT protocol.   

Install required packages 

Install below packages for MQTT:   

root@Arduino:~# opkg update 
root@Arduino:~# opkg install libcares 
root@Arduino:~# opkg install libopenssl 
root@Arduino:~# opkg install libmosquitto 
root@Arduino:~# opkg install mosquitto-client 

 

Test with public MQTT test server: 

test.mosquitto.org is a hosts a publicly available Mosquitto MQTT server/broker. User can post 

and subscribe to this MQTT server for testing. To test this server with SSL connection, user has to 

download the certificate authority file 

mosquitto.org.crt

 to verify the server connection. 

 

Open two SSH windows. In the first window, we subscribe to a topic with below command:   

mosquitto_sub -h test.mosquitto.org -p 8883 --cafile mosquitto.org.crt -t dragino/device0/temperature 

This command will listen to this topic and display any change on the server. 

 

And in the other window, we publish the change by another command:   

mosquitto_pub -h test.mosquitto.org -p 8883 --cafile mosquitto.org.crt -t dragino/device0/temperature -m 31 

 

Once the publish command is issued, we can see the result will display in the subscribe 

command.   

 

 

 

w w w . e k t

2

. c o m

Electronics 

Katrangi

 Trading

Содержание PAB2

Страница 1: ...Yun Shield User Manual VERSION 1 1 w w w e k t 2 c o m Electronics Katrangi Trading...

Страница 2: ...duino Uno 12 3 1 3 Connect to Arduino Duemilanove Diecimila 14 3 1 4 Connect to Arduino Mega2560 14 3 2 Detect Yun Shield 15 3 3 Upload Sketch 17 3 4 Bridge Library 17 4 EXAMPLES 18 4 1 Example 1 Say...

Страница 3: ...to Upload Download or Edit files in Yun Shield 27 5 7 How to reset the Yun Shield 29 5 8 How to recover the Yun Shield in case firmware crash 29 6 REFERENCE 32 w w w e k t 2 c o m Electronics Katrangi...

Страница 4: ...do equally to the official Arduino Yun but Yun Shield is more flexible because it can work with other Arduino board such as Uno Duemilanove Mega etc And Yun Shield uses external wifi antenna which pro...

Страница 5: ...e storage for Arduino projects Failsafe design provides robustly system Compatible with Arduino Leonardo Uno Duemilanove Diecimila Mega 1 4 LEDs There are four LEDs on the Yun Shield The functions of...

Страница 6: ...ed by the Arduino VIN pins to avoid overheated in the Arduino onboard 5v LDO So when Yun shield is in used the Arduino board should be powered by DC port instead of USB port The DC input can be 7v 15v...

Страница 7: ...3 3v and 5v Arduino board The on board jumper SV1 is used to set the SPI and UART to 3 3v or 5v level The SPI interface is used to upload the sketches comes from the Arduino IDE SPI interface only con...

Страница 8: ...an IP 192 168 240 xxx and the Yun Shield has the default IP 192 168 240 1 Fall Back IP A fall back IP 172 31 255 254 255 255 255 252 is assigned to Yun Shield s LAN port so user can always access Yun...

Страница 9: ...are Firefox and Chrome Simply type the IP address into your browser and you will see the log in page of Yun Shield Default User name and Password for Yun Shield is root dragino 2 2 2 Access via SSH Vi...

Страница 10: ...ice password and network parameters 2 3 2 Arduino related set up Arduino Board Type Define the bootloarder mcu type fuse setting during Sketch upload Operation Mode make sure it is in Arduino Bridge m...

Страница 11: ...or web upgrade should be a sysupgrade type firmware user can choose if keep settings or not after upgrade Normally it will take about 2 minutes to flash the new firmware Then all the LEDS will blink t...

Страница 12: ...uino Boards 3 1 1 Connect to Leonardo Simply plug the Yun Shield on top of the Leonardo and power the Leonardo via DC jack In Arduino IDE the board type should select Arduino Yun 3 1 2 Connect to Ardu...

Страница 13: ..._touch true unoyun upload wait_for_upload_port true unoyun bootloader tool avrdude unoyun bootloader low_fuses 0xff unoyun bootloader high_fuses 0xde unoyun bootloader extended_fuses 0x05 unoyun bootl...

Страница 14: ...68p they can modify the upload maximum_data_size upload maximum_size and build mcu accordingly 3 Put the Yun Shield on top of Duemilanove and power it via DC jack 3 1 4 Connect to Arduino Mega2560 1 I...

Страница 15: ...oader low_fuses 0xff mega2560Yun bootloader high_fuses 0xd8 mega2560Yun bootloader extended_fuses 0xfd mega2560Yun bootloader file stk500v2 stk500boot_v2_mega2560 hex mega2560Yun bootloader unlock_bit...

Страница 16: ...ibrary simplifies the communication between the Arduino Board and Yun Shield Bridge commands from the AVR Arduino Board are interpreted by Python on the Yun Shield Its role is to execute programs on t...

Страница 17: ...begin Console begin Wait for Console port to connect while Console Console println Hi what s your name Data flow Arduino Yun Shield Arduino IDE void loop if Console available 0 char c Console read rea...

Страница 18: ...ux Commands in Yun Shield include Console h Console lib used to show debug info in Arduino IDE include passwords h contains my passwords see below NOTE passwords h is not included with this repo becau...

Страница 19: ...String url https api xively com v2 feeds url FEEDID url csv Send the HTTP PUT request form the linux command and use Process Class to send this command to Yun Shield Is better to declare the Process...

Страница 20: ...Screen Shot Xively Dashboard w w w e k t 2 c o m Electronics Katrangi Trading...

Страница 21: ...eSystem begin while Console wait for Serial port to connect Console println Filesystem datalogger n void loop make a string that start with a timestamp for assembling the data to log String dataString...

Страница 22: ...time date is a command line utility to get the date and the time in different formats depending on the additional parameter time begin date time addParameter D T parameters D for the complete date mm...

Страница 23: ...update root Arduino opkg install libcares root Arduino opkg install libopenssl root Arduino opkg install libmosquitto root Arduino opkg install mosquitto client Test with public MQTT test server test...

Страница 24: ...type of antennas to the i pex connector of Yun Shield this make the installation is more flexible and possible to transfer the signal to several km distance In Software Aspect The Yun Shield software...

Страница 25: ...Where can I find the source code of Yun Shield The Yun Shield source can be found at https github com dragino linino 5 6 How to Upload Download or Edit files in Yun Shield Yun Shield has a built in L...

Страница 26: ...oot of Yun Shield An instruction in Windows is as below Set up TFTP server Download the tftp server recommend tftp32d exe And download the latest Yun firmware from http www dragino com downloads index...

Страница 27: ...ernel tftpboot 0x81000000 ms14 arduino yun kernel xxx bin erase 0x9fea0000 0x140000 cp b 0x81000000 0x9fea0000 filesize Upgrade rootfs tftpboot 0x81000000 ms14 arduino yun rootfs squashfs xxx bin eras...

Страница 28: ...Yun Shield Quick Start Guide VERSION 1 0 w w w e k t 2 c o m Electronics Katrangi Trading...

Страница 29: ...and it is fully compatible with Arduino IDE v1 5 4 or later Yun Shield is the ideally choice for Arduino Projects which require various internet connections and more storage Basically Yun Shield Leona...

Страница 30: ...sketch to Arduino board via Arduino IDE Managed by Web GUI SSH via LAN or WiFi Software upgradable via network Built in web server Support internet connection via LAN port WiFi or 3G dongle Support US...

Страница 31: ...ed by the Arduino VIN pins to avoid overheated in the Arduino onboard 5v LDO So when Yun shield is in used the Arduino board should be powered by DC port instead of USB port The DC input can be 7v 15v...

Страница 32: ...3 3v and 5v Arduino board The on board jumper SV1 is used to set the SPI and UART to 3 3v or 5v level The SPI interface is used to upload the sketches comes from the Arduino IDE SPI interface only con...

Страница 33: ...te an unsecure WiFi network call Dragino2 xxxxxx User can use their laptop to connect to this WiFi network The laptop will get an IP 192 168 240 xxx and the Yun Shield has the default IP 192 168 240 1...

Страница 34: ...o access internet via your WiFi router 2 4 Detect Yun Shield Assume your laptop and Yun Shield are in the same network The Yun Shield will broadcast data in this network and Arduino IDE will receive t...

Страница 35: ...nication between the Arduino Board and Yun Shield Bridge commands from the AVR Arduino Board are interpreted by Python on the Yun Shield Its role is to execute programs on the GNU Linux side when aske...

Страница 36: ...begin Console begin Wait for Console port to connect while Console Console println Hi what s your name Data flow Arduino Yun Shield Arduino IDE void loop if Console available 0 char c Console read rea...

Страница 37: ...h Console lib used to show debug info in Arduino IDE include passwords h contains my passwords see below NOTE passwords h is not included with this repo because it contains my passwords You need to cr...

Страница 38: ...url FEEDID url csv Send the HTTP PUT request form the linux command and use Process Class to send this command to Yun Shield Is better to declare the Process here so when the sendData function finishe...

Страница 39: ...Screen Shot Xively Dashboard w w w e k t 2 c o m Electronics Katrangi Trading...

Отзывы: