element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog [FMN#06] : Let's dweet with raspberry pi
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: vish
  • Date Created: 29 Aug 2014 6:40 PM Date Created
  • Views 1360 views
  • Likes 0 likes
  • Comments 2 comments
  • forget_me_not
  • raspberry_pi_b+
  • iot_intelligent_home
  • python
  • dweepy
  • enocean
  • dweet
  • raspberry-pi
  • forget_me_not_challenge_2014
Related
Recommended

[FMN#06] : Let's dweet with raspberry pi

vish
vish
29 Aug 2014

In my last post, I introduced Dweet.io and explained how to dweet from your raspberry pi. in this post, I'm going one step ahead and wiring together my Enocean-Py library with dweepy and start dweeting my Enocean sensor data.


Let's start dweeting

The whole idea is this - my raspberry pi, my first python script will first decode a received radio telegram with Enocean-Py and extract the rocker switch state. Then it will dweet this information to the public. On my desktop, I'll be running a second python script which will display as and when a new new dweet is posted by my raspberry pi. This demo utilizes the real time streaming capability of dweepy library and also showcases Enocean-Py library. As a word of caution, Enocean-Py is still under development and I recommend you always to update Enocean-Py before using it.( Details as in this post [FMN#03] : Decoding Enocean Protocol with Enocean Py )

 

Script for Raspberry pi

I'm assuming that you have already installed dweepy as explained in this post. First create a folder for this demo in your raspberry pi. Say this is '/home/pi/dweet_demo'. Now enter this directory and clone Enocean-Py repository by

git clone https://github.com/v-i-s-h/Enocean-Py.git

Now create a file named 'demo_sender.py' and contents as below :

#  demo_sender - a demo for using dweepy and enocean-py for dweeting enocean data.

import sys
import time
import dweepy
sys.path.insert( 0, "./Enocean-Py/src/" );
import EO
import ESP

'''
Function    : main
Description : main function
Arguments   : none
Returns     : none
'''
def main():
    print "\t\t*************************************************"
    print "\t\t**    Forget Me Not 2014 - Dweeting demo       **"
    print "\t\t**               by vish                       **"
    print "\t\t*************************************************"

    ttyPort = "/dev/ttyAMA0"
    print "\tUsing serial port : " + ttyPort + '\n'

    hEOGateway = EO.connect( ttyPort )
    # better to wait a little for connection to establish
    time.sleep( 0.100 )

    # this is your thing ID, change accordingly
    thingId = "fmn2014_vish_raspberrypi"
    # this hash table holds our dweet message
    myDweet = {}

    try:
        while( True ):
            rawResp = EO.receiveData( hEOGateway )
            if rawResp:
                pkts = ESP.decodeRawResponse( rawResp )
                for pkt in pkts:
                    myDweet = {}    # clear old data
                    myDweet['sender'] = 'enocean_py demo'
                    # currently no response radio decoding is implemented in Enocean Py
                    # I'm just checking whether the radio is from my rocker switch RORG = F6
                    # and then blindly checks for the bits set.
                    if pkt['data_recv'][0] == 0xF6:     # is this my rocker switch
                        # assuming we got a radio telegram from rocker switch
                        if pkt['data_recv'][1] == 0x70:
                            print "Channel B : OFF ",
                            myDweet['Channel B'] = 'OFF'
                        if pkt['data_recv'][1] == 0x50:
                            print "Channel B : ON  ",
                            myDweet['Channel B'] = 'ON'
                        if pkt['data_recv'][1] == 0x30:
                            print "Channel A : OFF ",
                            myDweet['Channel A'] = 'OFF'
                        if pkt['data_recv'][1] == 0x10:
                            print "Channel A : ON  ",
                            myDweet['Channel A'] = 'ON'
                        if pkt['data_recv'][1] == 0x00:
                            print "Rocker Released.",
                            myDweet['Rocker0'] = 'Released'
                        dweepy.dweet_for( thingId, myDweet );
                        print "......dweeted"
    except KeyboardInterrupt:
        print "\nExiting Demo"
        EO.disconnect( hEOGateway )
        print "Bye..bye.. :) "

if __name__ == "__main__":
    main()

 

Once you are done, you can save and close the file. Remember to change the 'thingId' to your thing's id.


Desktop Viewer

Now we'll create a desktop viewer application for viewing the dweets send by out beloved raspberry pi. What we will do is we'll use the realtime streaming capability of dweepy library and create a python script which will decode and show the dweet from raspberry pi.

Off course you need to install dweepy in your PC also.

Now create a new file name 'dweet_viewer.py' and copy paste these contents to the file.

#  dweet_viewer.py - a desktop application to view your thing's dweets

import json
import dweepy

def main():

    # replace with your thing Id
    thingId = "fmn2014_vish_raspberrypi"

    print "\t\t*************************************************"
    print "\t\t**    Forget Me Not 2014 - Dweet Viewer        **"
    print "\t\t**               by vish                       **"
    print "\t\t*************************************************"

    for dweetJSON in dweepy.listen_for_dweets_from( thingId ):
        if type(dweetJSON) is int:
            continue
        dweet = json.loads( dweetJSON )
        timeStamp = dweet['created']
        content = dweet['content']
        for items in content.keys():
            print "At " + timeStamp + " \"" + items + "\" updated to \"" + content[items] + "\"";

if __name__ == "__main__":
    main()

Save and close the file.


Running the demo

To run the demo, first start your 'dweet_viewer.py' script in your PC and then starting 'demo_sender.py' in your raspberry pi. Now press and release your demo switch and see what happens at both PC and raspberry pi.

Here is  a video of demo running.


You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Happy hacking,

vish


<< Prev | Index | Next >>

  • Sign in to reply
  • vish
    vish over 11 years ago in reply to ipv1

    Thanks IP image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ipv1
    ipv1 over 11 years ago

    Nice

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube