Stories

Teamviewer not reloading after I quit it

Posted on

This has been an ongoing problem for a long time now. If I was to ever quit Teamviewer, it would cease to reopen, and instead, just give me a prompt saying “TeamViewer is trying to install a new helper tool”.

Today, I finally discovered the answer to my troubles, and hopefully a solution that will work.

I discovered it here.

What happening on my computer was that the launch daemon for the helper tool was not properly started.

So, to fix the problem, I ran this from the Mac terminal:

sudo launchctl load -w /Library/LaunchDaemons/com.teamviewer.Helper.plist

Teamviewer then finally loaded. I haven’t seen anyone else with this issue, so I don’t know why it is doing it, but, until the Teamviewer provide a proper solution, this work around will have to do.

Sadly, even with the latest version (14), this is still current.

Advertisements

Reading text Data from a USB Serial Device in Python on a raspberry pi.

Posted on Updated on

Programming in python is very new to me, and I’m only doing this out of necessity, as it appears it’s the most easy and common method on the raspberry pi. So, here goes…

This code reads data from a USB device which issues text on a serial port, where I can then disseminate the data.

And yes, this is initial version which hasn’t been tested 100% yet.

 

import serial
import time
import csv

port = '/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0'
#port = '/dev/ttyUSB0'
baud = 9600

ser = serial.Serial(port, baud, timeout=1)
ser.flushInput()

print(ser.name)

oldline = []

while True:
    try:
        #ser_bytes = ser.readline()
        #decoded_bytes = float(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
        #print(decoded_bytes)
        
        
        line = ser.readline()                 # read bytes until line-ending
        line = line.decode(encoding='UTF-8')  # convert to string
        #line = line.rstrip('\r\n')            # remove line-ending characters
        
        split_line = line.splitlines()
        
        if oldline != split_line:      
            with open("test_data.csv","a") as f:
                for item in split_line:
                    writer = csv.writer(f,delimiter=",")
                    writer.writerow([time.time(), item])
                
        oldline = split_line
        
    except:
        print("exiting")
        #print("Keyboard Interrupt")
        break

I have now added it here: https://github.com/vrdriver/Serial-PI-thon

Retrieving Backups with Raspberry Pi and sftp

Posted on Updated on

Following on from my recent MYSQL DB, it’s one thing to back up the data, but you have to get the data off the server.

So, with my trusty Raspberry pi, that is going to use considerable less power than my NAS (which has been used for VMs to do this), it’s now time to get some scripts working on the pi to do the offline/off server backups.

 

The biggest problem is finding a solution to download the data securely. It’s easy to use plain FTP, which is not secure, but I need to have SFTP.

So, as it turns out, there is a program called sftp built in to the pi.

I went down the path of using sshpass. My FTP password has to be saved somewhere, and as it’s only for SQL backups, I’m not too concerned.

 

You have a few options other than using public key authentication. I have take this example from here.

  1. Use sshpass (less secured but probably that meets your requirement)

If you decide to give sshpass a chance here is a working script snippet to do so:

You should copy all of this in to a script.sh file.

export SSHPASS=your-password-here
sshpass -e sftp -P PORTNUMBER -oBatchMode=no -b - sftp-user@remote-host << !
   
   lcd local_backup_path1
   cd db_backup_path1 
   get *.gz
   cd..
   lcd ..

   lcd local_backup_path2
   cd db_backup_path2 
   get *.gz
   cd ..
   lcd ..

   bye
!

Please note the PORTNUMBER there. It has also be a capital for it to work.

Then, run the script with sh ./script.sh

MYSQL Backups

Posted on

There are plenty of options to back up mysql DBs.

One method is the following:

Create a backup user in mysql/mariadb like the following:

 

# /usr/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 253404
Server version: 5.1.54-1ubuntu4 (Ubuntu)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> GRANT LOCK TABLES, SHOW VIEW, SELECT ON *.* TO 'backupsonly'@'%' IDENTIFIED BY 'P@$$w0RD';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> Bye

 

Then, create a script “my_backup.conf” that has the following in it:

[mysqldump]
user=backupsonly
password="P@$$w0RD"

Then, run the following script to export the data.

 

mysqldump --defaults-extra-file=my_backup.conf -u backupsonly databasename --single-transaction --quick --lock-tables=false | gzip > databasename_full-backup-$(date +%F).sql.gz

 

 

Download a WordPress wp-content uploads folder

Posted on Updated on

There are times I work with groups and much of their online artwork is stored in a WordPress Upload folder.

There’s a few methods to get those images from that path. I like being able to use SiteSucker, but it often downloads the entire site.

The other easy option is to use wget.

Run this command in the path that you wish to save all the files to, and it’ll get everything in the upload path.

wget -r --no-parent http://yoursite.com/wp-content/uploads/

This is a single threaded command and will take a long time, so just be patient while it does its thing.

Try Vagrant they said…

Posted on Updated on

I’d heard good things, but installation and basic setup is not a one click solution. There are things that have to setup to get it going.

Vagrant is basically a way of controlling virtual machines on your computer, for those boxes that don’t really need or have a gui, which makes it great for web development and more.

So, while it sounds easy and great, you may run in to some dramas in setting it up.

Firstly, there aren’t really many front-end GUIs for setting this up. It’s basically command line driven.

So, go here and click on your version. For me, it was Windows x64 and run the msi file.

https://www.vagrantup.com/downloads.html

You also need to install VirtualBox as well.

https://www.virtualbox.org/wiki/Downloads

You will also need to install git

https://git-scm.com/download/win

Secondly, if you are trying to install it on a Windows 7 computer, like I was, your first hurdle will be having the correct version of Powershell. Mine came with version 2, so, I needed to find version 3 – as a minimum.

You find it here: https://www.microsoft.com/en-us/download/details.aspx?id=34595

There’s 4 files to download (plus a readme). You’ll need either the x86, or the x64 files. Only one of them installed for me, because my system said that I didn’t need or was applicable for my computer.

After a restart, and checking I had the correct version by running in powershell:

 Get-Host | Select-Object Version

It told me I had version 3.0

So, good to go?

I started with these instructions: https://dev.to/lechatthecat/how-to-use-virtualbox-and-vagrant-for-windows-1dnn

It gave me a basic centos install. You can try this if you like, but there’s a big downside, because you’ll still have to install everything else that goes with it, such as php, mysql, apache/nginx as well. So, follow a little further below, and I’ll show you a setup out of the box.

vagrant -v
Vagrant 2.0.1

cd C:\
mkdir vagrant\centos
cd C:\vagrant\centos 
vagrant init bento/centos-7.3

After about 10 minutes or so, it’ll download everything. eg:

C:\>cd vagrant

C:\vagrant>dir
Volume in drive C is WINDOWS
Volume Serial Number is 4XXX-XXXX

Directory of C:\vagrant

15/10/2018 03:35 PM <DIR> .
15/10/2018 03:35 PM <DIR> ..
15/10/2018 03:38 PM <DIR> centos
0 File(s) 0 bytes
3 Dir(s) 347,443,544,064 bytes free

C:\vagrant>cd centos

C:\vagrant\centos>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'bento/centos-7.3' could not be found. Attempting to find and i
nstall...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'bento/centos-7.3'
default: URL: https://vagrantcloud.com/bento/centos-7.3
==> default: Adding box 'bento/centos-7.3' (v201708.22.0) for provider: virtualb
ox
default: Downloading: https://vagrantcloud.com/bento/boxes/centos-7.3/versio
ns/201708.22.0/providers/virtualbox.box
default: Progress: 43% (Rate: 614k/s, Estimated time remaining: 0:05:35)

In case you didn’t know, there are many different vagrant ‘boxes’ available to download and use. https://app.vagrantup.com/boxes/search

I am just using the bento/centos-7.3 box because the tutorial was easy to follow.

For ease of development, I went with a scotch/box because it contained a full LAMP setup.

cd C:\
mkdir vagrant\scotch

cd C:\vagrant\scotch

vagrant init scotch/box

vagrant up

While that downloads, go and get putty, and an ftp client and watch the videos on here:
https://scotch.io/courses/getting-started-with-scotch-box-vagrant-for-the-absolute-beginner/downloading-and-installing

Some basic commands:

To start the virtual machine:

vagrant up

To stop the virtual machine:

vagrant halt

To restart the virtual machine:

vagrant reload

 

Or… They easier way, is to do the following:

Do all the install business as mentioned at the top of this post, then, open a command box (cmd)

cd \
mkdir vagrant
git clone https://github.com/scotch-io/scotch-box my-project
cd my-project
vagrant up

Then, open up the ip address of http://192.168.33.10/ in your web browser.
The best thing though is that you can then drop and edit your files directly in to

c:\vagrant\my-project

without having to upload, ssh or ftp anything to anywhere…

Just edit away…

For MySQL operations: https://box.scotch.io/docs/

Since using the scotch-box option, it’s been a brease to use, if you are content with a little bit of command line stuff.

There was only one problem I ran in to.

After working on a web app for many years, of which has been functioning well in various production and dev environments with no changes to the mysql config, I came across a problem yesterday where I couldn’t perform a query because I had the “Group By” statement in the query. See here for more details.

I solved the problem by editing /etc/mysql/mysql.conf.d/mysqld.cnf

I added the following line to the bottom of the config file.

[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

 

 

Ionic ramblings with version 4 and version 3…

Posted on Updated on

After many hours of using Ionic to create “the perfect app” that compiled and functioned as expected, I was nearly ready to launch.

However that all changed almost overnight.

I had started out using Ionic 3, as what the original install had put on my system. Everything worked fine. As I progressed and installed more and more NPM modules, it still seemed to function ok, even with the various dependencies.

Until, I decided to upgrade my laptop to Ionic version 4. I’d read about how simple it was to upgrade and so I thought, “why not”. Sadly, what followed was a series of problems, which made the app un-usable, to the point where it wouldn’t compile and builds were failing.

 

In this process, I had also updated to XCode 10. This proved to also be another problem in it self, because not all of the modules I’m using are compatible with it.

 

OneSignal for example, have a warning message on their site to say not to use XCode 10. Oops.

 

Xcode 10 Notice

Cordova is currently incompatible with Xcode 10’s new build system. For a workaround, please see this post

Because of changes to Xcode’s build process, this results in the embedded.mobileprovision file not being attached to your app bundle. This breaks push notifications – it will cause Mismatched User errors.

 

I’ve had strange error messages such as 
“Ionic 3: Build in “prod” mode: Cannot find module “.” Yep, a module called ‘.’… This was only discovered after building my code for xcode, and then observing a white empty background (and like here) in my newly built app for my iphone. What was the cause? I have no idea – still… but, I was getting some interesting errors (and others like it) from OneSignal in the XCode build notes:

OneSignal has detected that your application delegate implements a deprecated method (application:didReceiveLocalNotification:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead…

 

Other errors such as this were also common:

no-unused-variable is deprecated. Since TypeScript 2.9. Please use the built-in compiler checks instead.

CordovaError: Promise rejected with non-error: 'ios-deploy was not found. Please download, build and install version 1.9.2 or greater from https://github.com/phonegap/ios-deploy into your path, or do \'npm install -g ios-deploy\''

   at cli.catch.err (/usr/local/lib/node_modules/cordova/bin/cordova:30:15)

   at <anonymous>

   at process._tickCallback (internal/process/next_tick.js:188:7)

[ERROR] An error occurred while running cordova build ios (exit code 1).

 

So, after a lot of message, It was time to downgrade the app back to Ionic version 3.20.0.  Josh Morony does an excellent job at saying how to upgrade your app, but, I’ve got to be honest, this is a really crazy thing the Ionic team have proposed to do. You basically have to recreate your entire project and copy and paste and make it work again. a whole days work (and probably some more) just to have the same functionality… I can’t see it being worth it just yet.

 

I have no plans on touching version 4 yet – for a long time, as doing so, will break the entire build environment. In upgrading this, I also experienced NPM dependency hell as they call it. It was not fun.

 

I’m going back to running c4i App. V3 for the time being.

 

You may need this command at some stage too:

npm cache clean --force

 

This list is compatible with each other:

Since the “upgrade”, and then “downgrade”, this list allows for the build to go ahead, but still isn’t enough to solve the white screen of death in my app on iOS under “prod”.

sudo npm install -g ionic@3.20.0
sudo npm i cordova-ios@3.6.3

sudo npm i cordova-ios@4.5.5

sudo npm i @ionic-native/core@3.14.0 –save
sudo npm i @ionic-native/android-permissions@3.14.0 –save
sudo npm i @ionic-native/file-transfer@4.1.0 –save
sudo npm i cordova-plugin-whitelist –save
sudo npm i @ionic/app-scripts –save
sudo npm i -g typescript@2.7.2 –save
sudo npm install -g ios-deploy –unsafe-perm=true

 

 

You may have to do this command at some stage too

sudo chmod -R 775 /Users/YOU/Your_App_Path/node_modules/

I have an iOS build script for production and XCODE testing:

deploy_ios.sh

 

 

# BUILDING FOR IOS
ionic cordova platform remove ios
ionic cordova platform add ios
#ionic cordova platform update ios@3.9.2
#ionic cordova platform update ios@3.20.0
ionic cordova build ios --prod
#ionic cordova build ios --prod --buildFlag="-UseModernBuildSystem=0"
cd platforms
cd ios
#Open XCode for building and creating
open "APP_NAME.xcworkspace"
cd ..
cd ..

 

My Android script is a little more complicated, but also works:

deploy_android.sh
ionic cordova platform rm android
#ionic cordova platform add android
#cordova platform add android --save
ionic cordova platform add android@6.4.0
#https://forum.ionicframework.com/t/ionic-v1-android-ionic-cordova-platform-add-android/127543
ionic cordova build android --prod --release --debug
#keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.jks platforms/android/build/outputs/apk/release/android-release-unsigned.apk my-alias
cp ~/Library/Android/sdk/build-tools/27.0.3/zipalign platforms/android/build/outputs/apk/release/
cd platforms/android/build/outputs/apk/release/
rm app_name.apk
./zipalign -v 4 android-release-unsigned.apk app_name.apk
#copy to dropbox
# cp app_name.apk /Volumes/Creative2HD/DropBox/Dropbox/
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..
cd ..


So, as you read this, I’m still content to battle through and make this work, it’s just the observations I’ve had. I’ll continue to use Ionic, but will be lightly treading. If there is a way to sandbox each install or ionic version, I’d be very happy to know how. Does Vagrant, or Droplet type thing allow for this kind of Ionic development? I have no idea… but to spin up a VM would be crazy. Surely there’s another way…

I’m currently redownloading XCode version 9 from the Apple Developer site in an effort to downgrade the program.  Hopefully this will solved all problems and I’ll be back again to normal and it will build correctly.

If it ain’t broke, don’t fix it.

This is my current build environment. It’ll probably change though:

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0

global packages:

cordova (Cordova CLI) : 8.1.1 (cordova-lib@8.1.0)

local packages:

@ionic/app-scripts : 3.2.0
Cordova Platforms : android 6.4.0 ios 4.5.5
Ionic Framework : ionic-angular 3.9.2

System:

Node : v8.11.1
npm : 6.4.1 
OS : macOS High Sierra

Environment Variables:

ANDROID_HOME : not set

Misc:

backend : pro

 

Now, it’s time to install Xcode 9 and see if she will compile and deploy.

So, now that I’ve spent half the day sorting this out, I’ve managed to get the app to compile – eventually, and remove the white screen of death.

Strangely enough, this was only happening on the –prod builds.

To actually diagnose this a little better, I added the browser platform and then tried to run it there. Well, the browser –prod –release platform actually shows more error messages, than Safari. This proved to be very helpful, as it it turned out that typescript or more specific @angular/cli was missing or had the wrong version.

Now, it’s time to get the Android platform to build successfully again for deployment.

Make sure you have the correct Android SDKs installed. I’m using version 27.0.3

 brew install gradle

There is also a problem with brew and using gradle on High Sierra.

As per here outlines the solution: https://github.com/Homebrew/brew/issues/3285

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After you have done this and it’s working for you, the first time it runs, it’ll download a lot of necessities. Wait, and it’ll eventually load/compile.

I guess that in doing this, you really only ever set up a dev environment once, and then from there, you move on. This is a crazy ride, but I’m getting there.

 

As a side note, always, always, always, have your source code in a source control repository of some sort. I like Git, and use it with SourceTree and their remote git platform. It’s free for closed source and small projects.

 

Everything now compiles and is deployable again.