Since the S7-200 is a bit different then the newer S7-1500/S7-1200 PLCs it took a bit of work to get it working. The python-snap7 library was missing the connection method for the old TSAP method of connecting. So I forked the library and added the missing function to connect. I did a pull request to get it merged back with the original and it's pending currently. Here is the link to the forked library: https://github.com/SimplyAutomationized/python-snap7
I've also been working on a din rail enclosure for the pi that wasn't so large. I'm going to be adding a 24vdc to 5vdc dc-dc converter to the enclosure it so I don't have to bring in usb to it.
Anyway back to the good stuff. I added the Cli_Connection in the Client.py library so the code will now be as follows:
import snap7 as p
plc = p.client.Client()
plc.set_connection_params('10.10.55.250',11,11)
plc.connect()
print plc.get_connected()
if(plc.get_connected()):
plc.disconnect()
If you import my helper S7200.py library from github the code is as follows:
import S7200 as p
plc = p.S7_200('10.10.55.250',0x1100,0x1100,debug=True)
plc.writeMem('QX0.0',True)
print plc.getMem('freal10')
plc.writeMem('freal10',3.141592653589)
print plc.getMem('freal10')
print plc.getMem('QX0.0')
This will turn on output 1 (Q0.0, will turn on if there's no ladder associated with it).
To see "Part 1" of this project please go here
So we have few new features!!
Ability to hide/show clock and temperature via phone webapp
Change time between image transitions via webapp
Uploading multiple images from the web interface now works.
Deleting Images now works.
Lazy loading of images when looking through them on the webapp. (loads as you scroll)
I just added a 3-axis sensor to the 7" frame and have it broadcast to the HTML side the angle of rotation.
TODO(Coming Soon)
Weather feed option in the config. (see weather every 10 slides, and or outside temperature in right hand corner)
DNLA Support for those who have NAS servers with millions of images.
Option to only show images of the same aspect ratio as your picture frame rotation.(if you frame is vertical show vertical taken images and visa vera)
piframe image for download so no setup is required (except hardware)
Details on the new webapp features
To make it more handy to have a IoT picture frame I've added some handy configurations that load when the frame starts up.
Details on the Acceleromter
I updated the git repository with a class to communicate via i2c to a MMA7455 accelerometer. https://github.com/SimplyAutomationized/piframe/blob/master/MMA7455.py
The class has a callback method within it so it can broadcast a tilt change to whomever instantiates the class. Which I'm calling it within the websocket code and broadcasting to the client(the frame) the correct angle.
#I check the config file to see if you have enabled the tilt sensor
if(config['tiltsensor']):
self.tiltSensor=tilt.TiltSensor(self.rotateFrame)
self.tiltSensor.start()
#...later in the code we define the callback rotateFrame when rotation changes.
#(when the X axis inverts)
def rotateFrame(self,data):
rotation=data*270
self.frameconfig.changeKey('rotation',rotation)
self.sendNewConfig(self,all=True)
#the code then broadcasts it's new rotation, the CSS on the frame then rotate's the images based off of the new rotation :-) win!
It was an interesting process to sniff and break apart the ECOM protocol. But with the help of Wireshark I was able to create a simple class to read/write Inputs,Outputs,V Memory, and C Memory Bits. My class may look a bit hokey to those more skilled at python than I, but I've found it very usefull.
If you're stuck with an old generation H0-ECOM ethernet module and want to make use of it this post may be of use to you. I was able to get a few from work as we phased in new gear. We only had a couple ECOM-100 modules (ModbusTCP). So I was driven to get these working with my Raspberry Pi.
With mine I made a raspberry controlled sprinkler system using the Koyo DL-06 as my remote I/O. There was no logic programmed into the PLC because I wanted my pi to control it 100%. But with this python code anyone could make a raspberry pi powered cheap HMI or web based HMI for their system.
import Koyo as plc
myKoyo = plc.Koyo('192.168.1.26')
myKoyo.WriteOutput(0,1) # write output Y0 to true, (if this isn't tied to any rung in the ladder it should turn on)
print myKoyo.ReadInput(5)
print myKoyo.ReadC(16) #this currently only returns data of the first 4 bytes of C Memory
if(myKoyo.ReadOutput(5)):
myKoyo.WriteC(16,false)
else:
myKoyo.WriteC(16,true)
#other helpful commands:
myKoyo.FindKoyo() #return a list (ip,mac) of koyo plcs on the network
myKoyo.ChangeIP(mac,newIP) #change an ip address of a koyo that's plugged into your subnet
Hope this helps anyone with a Koyo. Other options are trying to install the C Library AutomationDirect provides on the website. I was unable to compile it and found this much more enjoyable.
In my search (hours upon hours upon days..) through the many picture frame pi tutorials I didn't quite find one that was fine tuned for what I wanted. I wanted to control it with my phone (upload, change , remove, and modify images). I tried the following (Pros/Cons):
FBI, Frame Buffer Imageviewer.
Pro: easy to setup and had slideshow modes.
Cons:
No layering if you wanted to put a clock or temperature on the top.
Took lots of ram to buffer all the images up.
No web interface.
Pygame:
Pros:
Python based, and I like python, which could give you a web interface.
Can do layering (add a clock layer.
Interface with web
Cons:
Slow
Not great for animations
HTML5 Web page Kiosk with Slideshow frontend and websocket server backend.
Pros:
Python websocket API for connecting Phone Apps and web apps
Quick animations
Layering upon layers upon layers
Easy programming
Connect it to other things (Weather, Home Automation,etc...)
Cons:
Takes lots of RAM.
So I took a bit of the FBI, and used some Raspberry Pi kiosk tutorials (can't think of which ones I used, just google some to find it) and mixed it into the mighty HTML5 one!!. Here's the parts list if this is your first RPicFrame:
LCD Screen with either Video or HDMI (Ebay/Amazon)
A Picture frame the you can attach your screen to. (May be difficult to find)
I luckily had a philips 10" digital picframe that I found at a garage sale for $15, gutted the lcd driver board and ordered one compatible with the lcd screen. (not always going to work) Also found the 7" digital picture frame at goodwill and gutted it and found a compatible driver (which barely fit with the Model A+).
Some people are skilled with woodworking as I've seen in other rpi pictureframe tutorials. You may be also.
Ok this doesn't have to be a Pi and use another awesome embedded platform sucha as a Minnowboard Max or Beagle Board. As long as you can hook up the screen to it and run some Linux code. (Kudo's to my bro's Blog and his intel edison projects)
**This will add this spinning raspberry pi to your screen. (you'll need to save this gif to /etc/pilogo.gif)
The fbiImage.png is whatever you want to show after this gif finishes and the kiosk hasn't loaded. I just had a solid black image for mine.
Controlling the frame with your mobile device
Ok... A couple more things and we're almost there. Create a file called go.sh and refernce it in your rc.local file:
go.sh:
#/bin/bash
# Disable DPMS / Screen blanking
xset -dpms
xset s off
xset s noblank
while true; do
sudo matchbox-window-manager -use_cursor no -use_titlebar no &
sudo -u pi epiphany-browser -a --profile ~/.config http://localhost/index.html
sleep 2s
done;
Here we are booting matchbox-window-manager as our desktop with epiphany our pictureframe webpage in an app kiosk mode with no title bar.
Now get the git clone of my webpage/websocket stuff and fill the pics folder with your images.
You'll need to make thumbnails to view the image selecting menu on the webpage:
git clone https://github.com/SimplyAutomationized/piframe.git
cd piframe
python thumbMaker.py www/pics www/thumb
After that it should be ready to roll. I just make a piframe image for the sd card. Let me know if that is what some of you would like.
Enjoy!!!
To see Part 2 of this project seehere
The ones below are the 10" digital picture frame I can control my lights with. Along with having a raspberry pi camera in it.