find and replace SQL
UPDATE `tablename`
SET `fieldname` = replace(`fieldname`, ‘UNWANTED-TEXT’, ‘WANTED-TEXT’)
UPDATE `tablename`
SET `fieldname` = replace(`fieldname`, ‘UNWANTED-TEXT’, ‘WANTED-TEXT’)
nmr_data = this is the main data, currently not live, but a lot of archive in there to play with
nmr_index = look-up table for ID to tag matching
nmr_readers = list of the reader serial numbers
nmr_records = stores date logged changes in mass, rank, genitalia and teats of each animal (many NULL)
nmr_ethogram = describes the codes used in the manual observation table
nmr_manual_obs = contains a set of behaviours for each animal in the colony (currently 11 are temporary placeholders that have the repeated oos code)
nmr_nest_distances = distances in mm from one sensor to another for the mapping animation
nmr_sensors = will store light and sound fluctuations
nmr_env = environment data, temperature (per change of 2 degrees or more) and humidity (once per hour)
The latest schema is here: https://github.com/misslake/rat.systems/blob/master/sql/nmr%20schema.sql
$ sudo easy_install pip
$ sudo pip install -U setuptools already installed on El Cap
$ sudo pip install pyserial
install MariaDB as that is what is installed on pew
==
$ xcode-select –install
$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
$ brew doctor
This will give you a message – “Your system is ready to brew.”
$ brew update
$ brew info mariadb
$ brew install mariadb
$ unset TMPDIR
$ cd /usr/local/Cellar/mariadb/10.1.13/
$ mysql_install_db
$ brew services start mariadb
$ mysql.server start
$ mysql_secure_installation
Follow security questions (remove anon users, enable access as root user remotely, set up root password)
$ mysql -u root -p
$ select @@version;
===
$ sudo pip install PyMySQL
version at 27-4-16 PyMySQL 0.7.2
===
$ ls /dev/cu.*
You are looking for /dev/cu.usbserial or /dev/tty.usbserial (see http://pbxbook.com/other/mac-tty.html )
If not showing up install driver at http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41 and restart. [note Macmini didn’t need driver install]
===
ser0 = serial.Serial(‘/dev/tty.usbserial’, 9600, timeout=5)
Use CoolTerm to establish which serial port is which reader: http://freeware.the-meiers.org/
===
To get up and running on the command line:
$ mysql.server start
then
$ mysql -u root -p
created nmr db on iMac and created tables using latest schema hosted on github.
install NOOBS from https://www.raspberrypi.org/downloads/noobs/ v 1.8.0 released 2016-02-29
Get online using wifi dongle and QMUL Guest login (fuck eduroam for now)
>sudo apt-get update
>sudo apt-get install mysql-server
>sudo apt-get upgrade
>sudo pip install PyMySQL
Changed mind and went for MariaDB as that is what I use on PEW
>sudo apt-get install mariadb-server
As MySQL was already installed this process migrates MySQL dbs etc to MariaDB and removes old MySQL stuff.
Set-up remote access:
VNC
>sudo apt-get install tightvncserver
>tightvncserver
— Start a VNC server from the terminal: This example starts a session on VNC display one (:1) with full HD resolution:
>vncserver :1 -geometry 1920×1080 -depth 24
NOTE: With RPi3 and NOOBS 29-2-2016 DO NOT RUN the stop service as described on the RPi website as you’ll lose the GUI desktop you are working on… >service lightdm stop
After this I couldn’t access the Pi from my mac like this – cmd-k from Finder and try to login vnc://PI-IPADDRESS :1
Probably something to do with the university network bullshit.
(automation set-up/start on boot instructs are here: https://www.raspberrypi.org/documentation/remote-access/vnc/README.md)
Decided to try weaved:
Weaved Connectd https://www.weaved.com
>create account on https://www.weaved.com/
>sudo apt-get install weavedconnectd
To set-up SSH access:
>sudo weavedinstaller
— enter account details (email and passw)
Then Option 1
Option 1 again
Option 1 again (SSH)
yes to default port num
Enter name
Exit
The above ref’d from: https://www.weaved.com/installing-weaved-raspberry-pi-raspbian-os/
For VNC access via Safari on MacOSX:
Check tightvnc is running (if not start a server as above)
>ps ax | grep tightvnc
Display what port(s) tightvnc is listening to
>`sudo netstat -apn | grep tcp | grep LISTEN
>
Pick lowest port number and install a new Weaved Service Attachment for VNC using the default port of PORTNUMBER.
>sudo weavedinstaller
— enter account details (email and passw)
Then Option 1
Option 3 (you can change Port number if default isn’t what you want)
Enter name
Exit
Sign in to Weaved account in Safari at weaved.com
Your connections will be listed.
Click on the one you want and follow instructs. You’ll need your TightVNC password.
et voila.
Generate key to SSH into pew:
> ssh-keygen -t rsa
Copy public key to clipboard
> pbcopy < ~/.ssh/id_rsa.pub
Add public key to PEW in the authorized_keys file in .ssh
-----
Change hostname, first replace the default name in here:
>sudo nano /etc/hostname
++ new name nmrpi ++
Then find the line starting with 127.0.0.1, and change the name following it to your new hostname:
> sudo nano /etc/hosts
—–
Find MAC address:
> ifconfig
The HWaddr is the MAC address
—-
status at 20151117:
Python script ok. Failing at the MySQL commit as the primary key stuff is not letting the data into the table.
To do: add data to the sensor table. check PKs and FKs. check them again. Look at using python to check for duplicates instead of doing it this way.
$ sudo easy_install pip
$ sudo pip install -U setuptools
$ sudo pip install pyserial
install MariaDB as that is what is installed on pew
==
$ xcode-select –install
$ ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
$ brew doctor
$ brew update
$ brew info mariadb
$ brew install mariadb
$ unset TMPDIR
$ cd /usr/local/Cellar/mariadb/10.0.21/
$ mysql_install_db
$ mysql.server start
$ mysql_secure_installation
$ mysql -u root -p
$ select @@version;
Fabulous source of the above instructions – https://mariadb.com/blog/installing-mariadb-10010-mac-os-x-homebrew
===
$ sudo pip install PyMySQL
===
$ ls /dev/cu.*
You are looking for /dev/cu.usbserial or /dev/tty.usbserial (see http://pbxbook.com/other/mac-tty.html )
If not showing up install driver at http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41 and restart.
===
ser0 = serial.Serial(‘/dev/tty.usbserial’, 9600, timeout=5)
Update 13th Nov 2015
To get up and running on the command line:
$ mysql.server start
then
$ mysql -u root -p
created nmr db on iMac and created tables using latest schema hosted on github.
TODO – export database from pew and install on imac so that nmr_index contains a tag ID that it can match.
for pew:
DB: nmr
TABLE: datatest
Check status (on pew, RHEL)
> mysqladmin -u root -p status
Start Mariadb (on pew, RHEL)
> sudo systemctl start mariadb
Deleting rows
> delete from nmr_records where id = >”799″;
> delete from nmr_index where colony = “800”;
Add columns:
> alter table nmr_records add column worker_pc smallint(4);