I am trying to imitate a SIEMENS S7 PLC so that scanners like Nmap, Zgrab and NESSUS will detect my Raspberry as an PLC. When looking at the NSE script voor Nmap (based on lua) itś clear that the response can be decoded with the following structure:
DATA DATA TYPE Location in response
Protocol ID C 8
SZL-ID C 31
Module information z 44
Basic Hardware z 72
Version Number CCC 123
Plant ID z 108 + offset
Copyright z 142 + offset
Serial Number z 176 + offset
System name z 40 + offset
Module Type z 74 + offset
Where: z is a zero-terminated string
C is an unsgined char
offset = 4
The connection to the PLC is established via socket connection. Now I am looking for a way to recreate this package and respond accordingly.
Have a look at the Snap7.
Somehow this library does what you need. It acts as S7-PLC, and responds even to Simatic Manager.
As Freeman suggests, install windows iot core on your raspberry and use Snap7 to emulate your S7 PLC on raspberry. You will also be able to control remote IO stations with your 'Soft PLC'.
Related
Could someone clarify for me why official documentation of RPI A+ says that it has 40 GPIOs while other sources, such as forums, online courses, and others say that it has 54 GPIOs? What is each one talking about? Is there a difference in types of GPIOs that each source is referring to?
RPI Tutorial by University of Cambridge
https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/ok01.html :
"There are 54 GPIO pins, so we need 6 sets of 4 bytes, which is 24 bytes in total."
Adafruit Website RPI specs
https://www.adafruit.com/product/2266 : "It's still compatible with all Pi operating systems and software, and has the exact same 40 pin GPIO connector and camera/display sockets"
BCM2835/BCM2835 micro-processor have 54 general-purpose I/O (GPIO) lines in total. This what RPI Tutorial by University of Cambridge is claiming but out of these 54 GPIO lines only 28 general-purpose I/O (GPIO) come on the external J8 header which can easily be interfaced with outside world. 12 pin are used as power pins +3.3V (2), +5V (2) and GND (8).
This is related to project that I'd like build using Google AIY VIsion Kit + Raspberry Pi.
I'd like to attach two vision bonnets to RPi zero W. I realized that Pi interacts with Vision Bonnet using SPI interface. From the schematics of RPi GPIO header, there seems to be two SPI interfaces as well. So, I'm wondering if I can connect two vision bonnets to the Pi. Would that be possible?
Furthermore, I've got two ideas in this regard:
(1) I think all the 40 pins won't be used by a single Vision Bonnet. So, if I know what pins are actually used, I can use that information to consider adding another Vision Bonnet. However, I'm not sure how to get this information though. Can you help me with this information?
(2) If I can't get the detail in (1), I'm thinking to extend the GPIO header on Pi by adding one more header on the VisionBonnet. Then, I'll attach the second bonnet to the newly added header. Does this make sense?
Thanks,
Venky
I posted the question in Google AIY Vision kit issue and the Google developers said that it's not possible.
https://github.com/google/aiyprojects-raspbian/issues/348
Based on the modules loaded (run lsmod), and the python code. I believe it uses more than one SPI. Given this, the answer is that very likely it won't work.
1/ I was not able to find a schema of the bonnet.
2/ Adding headers and connecting the second bonnet won't work as SPI supports communication of two peers only. SPI of the second bonnet will have to be connected to SPI2.
More information, that I found later:
The vision bonnet uses the following GPIO:
SPI interface: GPIO10, GPIO09, GPIO11, GPIO08
Handshaking: GPIO06, GPIO13
An SAMD09 MCU is hung off the I2C bus and uses address 0x51, 0x61 (bootloader only)
LED driver uses address 0x30
Not quite what you are after but I managed to get the Movidius NCS to run on the Pi. It has the same accelerator as the VPU bonnet (Intel® Movidius™ Myriad™ 2 vision processing unit (VPU)). They cost more but you can put as more than one NCS on a Pi via the USB interface. I assume you want to run two models simultaneously rather than scale one model.
The 40-pin pinout as described on google/aiyprojects-raspbian and Vision Bonnet :
3.3V --> 1 2 <-- 5V
I2C_SDA --> 3 4 <-- 5V
I2C_SCL --> 5 6 <-- GND
7 8
GND --> 9 10
11 12
13 14 <-- GND
(GPIO_22) BUZZER_GPIO-->15 16 <-- BUTTON_GPIO (GPIO_23)
3.3V --> 17 18
SPI_MOSI --> 19 20 <-- GND
SPI_MISO --> 21 22
SPI_SCLK --> 23 24 <-- SPI_CE_MRD
GND --> 25 26
ID_SDA --> 27 28 <-- ID_SCL
29 30 <-- GND
PI_TO_MRD_IRQ --> 31 32
MRD_TO_PI_IRQ --> 33 34 <-- GND
35 36
MRD_UNUSED --> 37 38
GND --> 39 40
I am making a wireless device to measure a magnetic field based on the HMC5983 magneto-resistive sensor and an ESP8266 (NodeMCU ESP-12e module).
The sensor is connected to the ESP8266 on the I2C interface. The
ESP8266 polls the sensor and sends this to a data collector (Raspberry Pi).
It is extremely important to me to achieve the greatest possible number of computation in a second, as quality of the obtained data for later processing depends on it.
HMC5983 supports the I2C interface in Standard, Fast and High-speed modes. But the NodeMCU I2C Module only supports i2c.SLOW speed.
common I²C bus speeds are the 100 kbit/s standard mode and the 10
kbit/s low-speed mode https://en.wikipedia.org/wiki/I%C2%B2C
Then I connected the HMC5983 directly to the Raspberry Pi via I2C. I could achieve about 500 measurements per second (by monitoring the DRDY interrupt pin) in single-measurement mode and 200 measurements per second in continous-measurement mode (with Data Output Rate at 220 Hz - all right).
The programm was written in Python, here is the code:
#!/usr/bin/python
import smbus #for i2c use
import time
import os
bus = smbus.SMBus(1) #use i2c port 1 on Rasspberry Pi
addr = 0x1e #address HMC5983 0x1E
bus.write_byte_data(addr,0x00,0b00011100) #Write to CRA Speed 220Hz
bus.write_byte_data(addr,0x01,0b00100000) #Write to CRB Gain 660 +-2.5Ga 1.52mG/Lsb
print "Start measuring.....
while True: #if we need infinity cycle
bus.write_byte_data(addr,0x02,0b00000001) #Write to Mode single-measurement mode
while bus.read_byte_data(addr,0x09) == 0b11: #Wait RDY in Status Register
()
#DATA READY
data = bus.read_i2c_block_data(addr,0x03,6)#Take data from data registers
#convert three 16-bit 2`s compliment hex value to dec values and assign x,y,z
x = data[0]*256+data[1]
if x > 32767 :
x -= 65536
y = data[2]*256+data[3]
if y > 32767 :
y -= 65536
z = data[4]*256+data[5]
if z > 32767 :
z -= 65536
print "X=",x, "\tY=",y, "\tZ=",z
When I connected the HMC5983 to the ESP8266, I could achieve only about 140 computations a second in single-computation mode.
----------THIS IS FOR SINGLE-MEASUREMENT MODE-------------
--init i2c
function H_init(sda,scl)
i2c.setup(id, sda, scl, i2c.SLOW)
print("I2C started...")
end
-- reads 6byte from the sensor
function read_axis()
i2c.start(id)
i2c.address(id, dev_addr, i2c.RECEIVER)
data = i2c.read(id, 6)
i2c.stop(id)
return data
end
--set register
function set_reg(reg_addr,val)
i2c.start(id)
i2c.address(id, dev_addr, i2c.TRANSMITTER)
i2c.write(id,reg_addr)
i2c.write(id,val)
i2c.stop(id)
end
--------GPIO INITILIZATION-------
drdyn_pin=3
gpio.mode(drdyn_pin, gpio.INPUT)
-------I2C INITILIZATION-------
id = 0
i2c = i2c
local i=0
dev_addr = 0x1e
H_init(1,2)
set_reg(0x00,0x1c) --set speed 220Hz
set_reg(0x01,0x20) --set gain
print("Start measurement...")
while true do
set_reg(0x02,0x01) --single-measurement mode
while(gpio.read(drdyn_pin) == 1) do
end
data = read_axis()
tmr.wdclr()
end
After that I configured the sensor to continous-measurement mode and received the same 200 measurements per second.
Is operation of the I2C interface in NodeMCU at high speeds possible? Can somebody tell me how to try to accelerate sensor polling?
Of course it is possible, ESP8266 is faster than Pentium :-) Just a few thousands or even just a few ten thousands measurements per second would be really disappointing for such tremendous processing power. Here you are the link to ESP8266 I2C library written in assembly and tested with Arduino toolchain. That way you can communicate at the rate of 800000 messages per second #80 MHz or one million messages per second #160 MHz. I believe that would be more than enough for the project you have described, at 80 kHz I2C speed you can have a few ten thousands measurements per second - if a slave device can handle such speed.
For any future doubts if something could or couldn't be done with ESP8266, I'd say this is more than enough to get a picture - and in this case I mean it literally :-)
A trying to read selec mfm384 c energy meter using modbus RTU protocol in terminal software (Docklight), am getting some irrelevant response starting with 3F...... it need to respond with Slave address in its first byte, how ever CRC is also getting failed,Can you help me in explaining command and response formats in selec mfm 384
Solved : I have 2 Wire RS 485 from energy meter and i have always (Even while energy meter is responding through Rx+ and Rx- lines )enabled Tx+ and Tx- , Which caused corruption of transmitted data from energy meter
I'm new to Raspberry Pi and I don't understand about electricity. I bought a Raspberry B+ today and a 5V 3A power supply, but I'm afraid to connect it because in several places I read about using 5V 2A power supplies. I believe that only higher voltages can damage the Pi but, since I don't know about Amp, I don't know if this is true for 3A too.
My ideia is create a mini-personal server in my home, running Pidora. For data, I have a 1 Tb external USB drive with no external power supply (Seagate model SRD00F1).
My questions are:
can I use the 5V 3A power supply on Raspberry Pi B+ without damage it?
this power supply is compatible with my external USB drive to keep it on safely?
Thank you!
The Raspberry Pi FAQ says that the B+ uses between 0.7 and 1.0 amps, and suggest a 1.2 amp power supply as a minimum.
Using a power supply with a higher amperage rating will not harm your Raspberry Pi. Devices only draw as much current (amperage) as they need. Any additional capacity is unused.
This is where your question about the external hard drive comes in. If you see in the FAQ, they suggest that you might want a larger power supply if you use all of the USB ports. Every USB device you plug in is going to draw more current. To figure out how much you need, you just add up the requirements of all of the devices like so:
Raspberry Pi = 0.7-1.0A
Mouse/Keyboard = 0.5A
Hard Drive = 1.0A
========================
TOTAL = 2.5A
(These numbers are all fake... be sure to check the requirements for your actual devices.)
So if your devices total 2.5A then a 3A supply will handle all of these plus some room for expansion. If all of your devices total 3.5A, maybe you need to consider a bigger one.