element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog Pi IoT - Simone - #2 - Main System
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: bosc
  • Date Created: 17 Aug 2016 5:37 PM Date Created
  • Views 846 views
  • Likes 2 likes
  • Comments 4 comments
  • pi 3
  • pi iot
  • i2c
  • pi
  • enocean
  • piiot challenge
  • pi iot design challenge
Related
Recommended

Pi IoT - Simone - #2 - Main System

bosc
bosc
17 Aug 2016

This post should cover how the whole system comes together and how it is controlled.

 

Previous posts:

Pi IoT - Simone - Introduction

Pi IoT - Simone - #1 - Light Controller

 

The main system is based on a server application that works on a Raspberry PI. I chose the version 3 for this because it has more connectivity options and more processing power. Mostly there are not many things to process but as the system grows it might be an issue.

This is how the system looks like:

 

image

 

 

Main Server:

The Raspberry that holds the application for the main server is the most important part since it is the one that ensures the communication between the devices. I started writing the application in C++ since it gives me the possibility to optimize it as much as possible. The server also holds a database where all the necessary data is stored (users, current state of things, reports of usage, etc).

 

I2C Interface:

At this point the I2C communication is the most used. This can also be reused for other devices that are centralized by another Raspberry, or another device with more processing power than an AtTiny chip. I chose the I2C because it is cheap to use and easily integrated with any other controllers. Here is a good explanation of how I2C works: https://en.wikipedia.org/wiki/I%C2%B2C

The main issue is that there can be only one master on the I2C network and because the micro controllers are not powerful enough I chose to always use the Raspberry as a Master and it pings the devices one by one to see if they have new notifications. When and communication is initialized by the master to a certain device it can also listen for messages sent by it. I made a ping function on the devices that when it is triggered the device responds with the number of notifications that it has. The Master can then ask for them one by one. With the ping function the Master can also know if something happened to a device and it can notify the user.

 

Another important function is the Identify function. You can see how it responds in the code for the light controller. The idea is that the Raspberry can send an identification message to all available addresses (there are only 127) and if there is an device on that address it can identify itself by saying what type of a device it is and some parameters necessary for the Server to control it.

In the case if the light controller the message was: 1#4#3#Lumini sufragerie#1. The first number is the type if the device. in this case it is defined as  switch and the main server knows to make a switch controller base don it. The second parameter is the I2C address of the device. The next ones are particular to the switch devices. The 3 is the number of switches it controls, then there is the name of the switch to be shown to the user (it says "Dining Room Lights"). The last number is an boolean value that states if the switches can be controlled or not.

 

An issue I encountered is that the I2C communication does not work well on long distances. I used an LAN Cable which has pairs of two wires twisted together. I paired one signal wire with a ground and this clears the signal a bit. Also, to communicate through a 100 m wire I used an transceiver like this one P82B715TD, which actually amplifies the signal to 35 amps and then lowers it back down. This also raises a cost issue but normally you can communicate with no issues in a room through normal I2C but for communication between rooms I've set up a "parrot" device made of two attiny's connected through SPI.

image

So the Raspberry server sees in the message an address written on 4 bytes, the first two are for the parrot device and the last two for the actual device.

 

Here is the functions enum used for implementation, the other functions names are relevant for their functionality:

#ifndef __I2CTYPES_H__
#define __I2CTYPES_H__


enum I2C_FUNCTIONS{
  Ping = 0x01,
  Calibrate = 0x03,
  Identify = 0x05,


  Start = 0x11,
  Stop = 0x13,
  Restart = 0x15,


  Set = 0x21,
  Get = 0x23,
  SetGet = 0x25,


  Execute = 0x31,
  Interrupt = 0x33,


  Send = 0x41,
  SendReceive = 0x43,


  Notify = 0x51,
  GetNotification = 0x53,
  RemoveNotification = 0x54,
  GetAlert = 0x55,
  RemoveAlert = 0x56,


  ResponseConfirmation = 0x61,
  ResendMessage = 0x62,


  Default = 0x00
};


#endif

 

Socket Connection:

The system has two socket servers.

First server is used to communicate with the user through his devices. All the applications if they are for the phone, PC or web applications have behind them a socket client that can pair with the server through this connection and send/receive data. The server has a interpretation layer that can make the message to be sent to the device, or retrieve information from the database if the device interrogation is not necessary.

Second server is made to communicate with other client applications that are controlled by the server and not by the user. In the diagram it is shown another Raspberry that communicates with the EnOcean devices (I could use only one but I don't have enough pins to plug in the display) and can in turn connect to the main server by this socket server. Another use would be a desktop client that could run some script on your computer when it is triggered. As mentioned before, some control devices can get very complex and then you would need a Raspberry PI behind them and not just an Atmel Chip

 

(I'm still working on the communication protocol for the clients)

 

System Communication:

Most of the times the devices that connect through the two socket servers are in the same network. An important thing is to set the IP of the main server as static, and then it can be recognized by the clients. To use the device from outside the network (very important feature this system) you can set up a free host that points to your IP address and foreword the communication port for the User Socket Server to the raspberry PI from your router. Here is one example on how to do it but if I have time I will write one myself for this project: https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=32830

 

Let me know in the comments of possible issues or if something is not covered enough. Thank you!

<I will attach some code soon, still fixing some issues>

Attachments:
Simone.zip
  • Sign in to reply

Top Comments

  • michaelkellett
    michaelkellett over 9 years ago in reply to bosc +2
    For long distance, low cost coms you still can't beat RS422/485 - as you have discovered I2C isn't very good for long distances (more than few feet) without buffer chips and this reduces its cost advantages…
  • bosc
    bosc over 9 years ago in reply to michaelkellett

    Thanks Michael, I will have a look at this solution. As you say, it might be too late to implement it now but I will keep it in mind for future upgrades to the system.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • michaelkellett
    michaelkellett over 9 years ago in reply to bosc

    For long distance, low cost coms you still can't beat RS422/485  - as you have discovered I2C isn't very good for long distances (more than few feet) without buffer chips and this reduces its cost advantages.

     

    422/485 uses the usual UART found on pretty much every micro and an interface chip.

     

    It may be much too late to change but here's  a link to a useful TI paper (but read some others before you buy anything image).

     

    www.ti.com/lit/an/slla070d/slla070d.pdf

     

    MK

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • bosc
    bosc over 9 years ago in reply to DAB

    Yes, the idea was to make modular system that can be easily update and to recognize new devices when they are connected without rebuilding the system. I'm trying to plan it so it can be expanded later. I'm still defining a format for a generic message that all the communication interfaces can use, but I have a problem with the slow micro controllers that communicate through I2C.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago

    Interesting project.

     

    Have you defined the data types and message formats for later use?

     

    DAB

    • 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