Raspberry Pi start for my IOT uart and PyBBIO server(also on PC)

After several time of pushing, there is still no BBB...
now need to get a Pi for testing my IOT set.

Installed Dabian for Raspberry Pi, when frist run up it would bring up

raspi-config  for configuration, I expand file system to full sd card, and changed password, then 

need to change thekeyboard lay out....
we can also execute raspi-config to change anything
should log in as : pi

It comes with DHCP, so obtain IP automatic
SCP server is also installed, winSCP can work











it seems broadcom uart is shown as ttyAMA0


Python is version 2.7.3

start with a python uart testing:
import serial
import array
ser=serial.Serial('/dev/ttyAMA0',115200,timeout=1)
LedOn=[0xFF,0xFF,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0D]
Test=[0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x0D]
ser.write(array.array('B',LedOn).tostring())
ser.write("test on pi uart ttyAMA0")
ser.close()
the program need to execute as root, so it has access to uart, or we can add pi into a group has access to uart
the program works fine to send out data.


I have tested with my python to send out through /dev/ttyAMA0, it works.
But to receive from Pi's uart, it give me an error 5, IO control eror....$%^&
 I found this:
http://codeandlife.com/2012/07/29/arduino-and-raspberry-pi-serial-communication/

Setting Raspberry Pi up for serial communications

In order to use the Pi’s serial port for anything else than as a console, you first need to disable getty (the program that displays login seen) by commenting the serial line out of Pi’s /etc/inittab:
1:2345:respawn:/sbin/getty 115200 tty1# Line below commented out
# 2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
3:23:respawn:/sbin/getty 115200 tty34:23:respawn:/sbin/getty 115200 tty45:23:respawn:/sbin/getty 115200 tty56:23:respawn:/sbin/getty 115200 tty6
If you don’t want the Pi sending stuff over the serial line when it boots, you can also remove the statements console=ttyAMA0,115200 and kgdboc=ttyAMA0,115200 from /boot/cmdline.txt. You’ll need to reboot the Pi in order for the changes to take effect.

But with my 20140620 debain, my inittab are different:

# Format:

#  <id>:<runlevels>:<action>:<process>


# Note that on most Debian systems tty7 is used by the X Window System,

# so if you want to add more getty's go ahead but skip tty7 if you run X.
1:2345:respawn:/sbin/getty --noclear 38400 tty1 

2:23:respawn:/sbin/getty 38400 tty2

3:23:respawn:/sbin/getty 38400 tty3

4:23:respawn:/sbin/getty 38400 tty4

5:23:respawn:/sbin/getty 38400 tty5

6:23:respawn:/sbin/getty 38400 tty6

# Example how to put a getty on a serial line (for a terminal)
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100

#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100

# Example how to put a getty on a modem line.
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3

#Spawn a getty on Raspberry Pi serial line

#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100



So, I'll try to comment out the last one on ttyAMA0, this file can't be modified from remote, so, I used root and nano to comment out the last one on Pi.


To start up my python program at start up, I followed this one:
http://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/

here is how to check what we have on crontab, and how to stop or delete crontab service
https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/cron-jobs-c37727/delete-a-cron-job-a757264.html


If you need to find to program with ps -ef to find to PID and kill the one.....




Then it works not only on sending data, but also works on data receive, decode, and gdata.

Now has to add a web server, need to know which is the easier one


After checking with the maker of PyBBIO, it seems it's possible to use BBIOServer module on Pi, BBIOServer is very nice little tool to present stuff on web.
the trick is to modifed the BBIOServer.py:
1. remove import from PyBBIO
2. replace delay() by time.sleep()

then copy( /scp -avrource/ /destination/) the whole folder in to pi at: /usr/local/lib/python2.7/dist-packages/, that's where I found gdata as well.
For my PC with windows:
C:\Python27\Lib\site-packages\
For detail of python path, you have to check out  /usr/lib/python2.7/site.py

with a little test, it works!
 on another PC browser, type in the IP with port 8000





I left the board for testing over night, but the program stopped, I saw no update on google drive.
next morning I found that the board has been rebooted. So need to make the program auto execute.

http://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/

the idea is to make a script,chmod 755 launcher.sh, and use crontab to do it at reboot, it's working

Here is another method to use service in rc.local
http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs

It comes to my mind, what is the 3v3 out put capability?

Raspberry Pi Web Server
http://www.instructables.com/id/Raspberry-Pi-Web-Server/#step2

Running a lightweight webserver on the Raspberry Pi (lighttpd)

http://www.penguintutor.com/linux/light-webserver


Pi and drop box
http://www.raspberrypi.org/forums/viewtopic.php?f=63&t=21617

there are lib of python on dropbox
and there is API:
https://github.com/andreafabrizi/Dropbox-Uploader

留言

這個網誌中的熱門文章

Heltec ESP32+OLED+Lora, hardware testing

micro SD card for ESP32, on lolin32 with OLED and heltec 32 lora oled

Install Network Time Protocol(NTP) on BeagleBone with Angstrom linux and set local time zone