30 maggio 2015

aurora: ERROR: Received bad return code (-1 0)

Hi,
I will explain my experience.
This morning my raspberry, where I installed 123Solar, it didn't communicate with my Power One inverter .
So I tried with putty to run the command:
aurora -a 2 -c -T -Y4 -d0 -e /dev/ttyUSB0
and I have received the error:
aurora: ERROR: Received bad return code (-1 0) 

After that I tested the communication with the command:
 aurora -a 2 -b -e /dev/ttyUSB0
and it returned:
aurora -a 2 -b -e /dev/ttyUSB0

szttyDevice: /dev/ttyUSB0
yDelay:     1
yTimeout    0 mS
yMaxRunTime ~
devLCKfile:
devLCKfileNew:
Got Params

RunTime     20150530-10:50:52 v1.8.8
Endian    : Little
tm_gmtoff : no
PID       : 23089

Attempting to get lock on Serial Port /dev/ttyUSB0...
Checking for lock

Checking process 23089 for lock
rPID: 23089 SubStrPos: aurora command: aurora = me
Appears we got the lock.

Opening Serial Port /dev/ttyUSB0...  Serial Port /dev/ttyUSB0 successfully opene                                                                                        d.
Configuring serial device... Flushing unread data first...  Success!
Flushing serial device buffer... Success!

Comm Check: Let's see if the Aurora is listening...
Elapsed time since last comm 0 us
Attempt 1
Clearing read buffer Success!
szSerBufferSave OK! 02 3a 00 00 00 00 00 00 00 00
command: 02 3a 00 00 00 00 00 00 01 b7
Flushing serial device buffer... Success!
Sending command... sent 10 characters
Draining serial device buffer... Success!
Cleared data buffer: 00 00 00 00 00 00 00 00 00 00
Read char #1 RC=0 (00) waited/max    99272/1000000  uS
answer:  Got -1 characters
Comm Check: Failure, aborting...

Restoring Serial Port settings /dev/ttyUSB0... Success!
Flushing serial device buffer... Success!
Closing Serial Port /dev/ttyUSB0... Success!

devLCKfile:
devLCKfileNew:
Clearing Serial Port Lock (23089)... done.

20150530-10:50:53: aurora: ERROR: Received bad return code (-1 0)

Complete 20150530-10:50:53

So I googled to looking for someone met the same error and I find out a post in a forum where someone have suggested to change the parameter Y from -Y4 to -Y10. 

The parameter Y means:
-Y , --retries=      Retry failed communications with inverter up to   times (1-100)

After the changing it looked works but after a while it stopped.

At the end I discovered that a wire was disconnected in the converter RS-485 to USB! I fixed it and now it works!

Bye
Francesco





18 aprile 2015

How to find out php.ini path?

You can create a simple file info.php where you put:



Then, if you open that file with a browser you can see the path:

 


Otherwise, you can get a full phpinfo() using the command:
php -i

And, in there, there is the php.ini file used:

$ php -i | grep 'Configuration File'

Below the screenshot:


NOTE: As you can see the paths are diffent because it's dipend on the context.

Bye
Francesco

30 marzo 2015

How to setup Wi-Fi dongle on Raspberry Pi

Hi,
in order to enable the wi-fi dongle it’s necessary follow these steps:

  1. Edit the file “interfaces”:

    sudo nano /etc/network/interfaces

    add the follow strings

    allow-hotplug wlan0
    iface wlan0 inet dhcpwpa-conf /etc/wpa_supplicant/wpa_supplicant.confiface default inet dhcp
    below the screeshot:

  2. Edit the file “wpa_supplicant.conf” with the command:

    sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    Add the follow strings

    network={
    ssid="YOURSSID"

    psk="YOURPASSWORD"

    # Protocol type can be: RSN (for WP2) and WPA (for WPA1)

    proto=WPA

    # Key management type can be: WPA-PSK or WPA-EAP (Pre-Shared or Enterprise)

    key_mgmt=WPA-PSK

    # Pairwise can be CCMP or TKIP (for WPA2 or WPA1)

    pairwise=TKIP

    #Authorization option should be OPEN for both WPA1/WPA2 (in less commonly used are SHARED and LEAP)

    auth_alg=OPEN

    }

    below the screeshot:
  3. When editing files is done, is the time to run the command: sudo reboot .Immediately after run the command,  unplug the Ethernet cable and plug in the Wi-Fi dongle.

Bye
Francesco

How to: Change root password in raspberry pi (in a general linux)

Hi,
it’s very simple changing the root password in every Linux with the command “passwd root”.
For do this it’s necessary having the rights and be a sudoers member.
In the screenshot below I used the pi user:


Bye
Francesco

7 marzo 2015

How-to: Clone Raspberry Pi SD Card


  1. Open the application Win32DiskImager (probably you have used it during the first installation)

  2. In the "Image File" textbox, enter the path of the image file. For example, I put c:\temp\clone_raspberry_20131115.img
  3. In the "Device" combobox, select the letter of your SD card reader.
  4. Click the "Read" button to create the image file from your card.
Enjoy it!

Who users are connected or login to Oracle applications?

It give the number of session users on the system in the past 1 hour:

select "is".user_id, user_name, description, email_address,  to_char(min(first_connect) ,  'DD-MON-YYYY HH24:MI:SS') min_first_connect, to_char(max(last_connect),'DD-MON-YYYY HH24:MI:SS') max_last_connect,count(*) "# sessions"
from apps.icx_sessions "is"
inner join apps.fnd_user fu on fu.user_id = "is".user_id
where  last_connect > sysdate - 1/24 and "is".user_id != '-1'
group by "is".user_id, user_name, description, email_address;

This return the user login into system with at least a session and a process:

select d.user_id, d.user_name, d.description, d.email_address, a.terminal_id, b.machine, to_char(a.start_time,  'DD-MON-YYYY HH24:MI:SS') start_time
from apps.fnd_logins a,
v$session b, v$process c, apps.fnd_user d
where b.paddr = c.addr
and a.pid=c.pid
and a.spid = b.process
and d.user_id = a.user_id
and (d.user_name = 'USER_NAME' OR 1=1);

Enjoy it!

6 marzo 2015

How to create a tar file encrypted with gpg in linux

First step is to create a script for the compression + encryption. You could to call it for instance: “encrypt”.

#!/bin/bash
  tput sc
  while [ -s $pass ] || [ $pass '!=' $pass2 ]; do
   read -s -p "Enter Passphrase: " pass;
   tput rc;
  read -s -p "Re-Enter Passphrase: " pass2;
   tput el1;
   tput rc;
  done;

  for file in $@; do
   tar -cf - $file | gpg -c --passphrase $pass > $file.gpg;
   srm $file;
  done

Next, if you want decrypt a file will be necessary to run another script defined as:

#!/bin/bash
  tput sc;
  while [ -s $pass ]; do
   read -s -p "Enter Passphrase: " pass;
   tput el1;
   tput rc;
  done;

  for file in $@; do
    tar -xf <(cat $file | gpg -d --passphrase $pass);
    if [ $? -eq 0 ]; then
      srm $file;
    else
      echo Failed to Decrypt;
      echo [password might be wrong];
    fi;
  done;

Finally, after the script definitions, you could run when you wish encrypt or decrypt a file:

encrypt filename
decrypt filename

Enjoy it!

22 febbraio 2015

How to delete files when minimum free space is reached

Below I have reported a script, find out in a forum page. 
This can be scheduled and it will delete file in a folder when free disk space reaches a threshold:

#!/bin/bash
# Immediately exit upon shell error
set -e

# Set lock file details
scriptname=$(basename $0)
lock="/var/run/${scriptname}"

# Lock the process, or exit if already running
exec 200>$lock
flock -n 200 || exit 1

# Write the PID to the lock file
pid=$$
echo $pid 1>&200

# Define the location of the applications
DF="/bin/df"
AWK="/usr/bin/awk"
SED="/bin/sed"
FIND="/usr/bin/find"

# Define the directory to check
DIR="/motion"

# Define constants
Minimum=100   # Minimum space below which files will be deleted (MB)
DeleteTo=200  # Delete files until this value is reached (MB)
NumtoDel=100  # Number of files to delete between each free disk space check

# Set shell such that empty file listing will return null
shopt -s nullglob

# Check if free space is less than the minimum specified
FreeSpace=$($DF -m $DIR | $AWK '{print $4}' | $SED "1d")
if [ $FreeSpace -lt $Minimum ]; then
  # Free space has dropped below minimum value, delete files until DeleteTo space is free
  while [ $FreeSpace -lt $DeleteTo ]; do
    # Check if any pictures remain in the directory, otherwise break out of the delete loop
    if test -z "$($FIND $DIR -maxdepth 1 -name '*.jpg' -print -quit)"; then
      break
    fi
    # Delete files until NumtoDel has been reached, or no more files exist
    FileCount=0;
    for FileName in $DIR/*.jpg; do
      rm $FileName
      FileCount=$((FileCount+1))
      # Check if number of files to delete has been reached
      if [ $FileCount -ge $NumtoDel ]; then
        break
      fi
    done
    # Check if free space is less than the minimum specified
    FreeSpace=$($DF -m $DIR | $AWK '{print $4}' | sed "1d")
  done
fi

8 febbraio 2015

How create a Xiaopan OS VM in Virtualbox

Xiaopan OS is an easy to use security and penetration testing with a collection of wireless security and forensics tools. It includes a number of advanced tools for network administrators, security professionals and home users to test the strength of their wireless networks and eliminate any vulnerabilities.

In the next step we will see how create a VM with the Xiaopan OS.

1.      Open VirtualBox and click on the button "New". In the popup insert the name of the new VM, select "Linux" as Type and "Other Linux" as Version. After that click "Next".


2.      In the next popup you have to choose the memory size, you can to assign 512MB to the your new VM. Then click “Next”.


3.      Now it’s necessary create a new virtual hard drive. Then click “Create”.


4.      The new hard driver can be a VDI (VirtualBox Disk Image). Then click “Next”.


5.      Leave the default option “Dynamically allocated”, in order to avoid to allocate immediately all the space. Then click “Next”.


6.      It’s sufficient assign only 2 GB at the new VM. Then click “Next”.


7.      Now, it’s necessary download the ISO image from the “Sourceforge” portal: http://sourceforge.net/projects/xiaopanos/

8.      After download the iso image, you have to assign it to the vm. In the VM settings, in the “Storage” section, select the cd-rom disk image, browse the file system (click on the cd-rom) and select the iso image file.


9.      At the end you can start the virtual machine, during the boot you must select “Boot XIAOPAN OS in Virtualization”

Enjoy it!

Bye

 

2 gennaio 2015

How check if a substring is contained in another string in JavaScript

It's possibile use the function "indexOf" that returns the position of the string in the another string. If not found, it will return -1:
For example:
var s = "stringa";
alert(s.indexOf("ng") > -1);


Other way, it could be used jQuery's :contains selector.

Last way is the method String.includes():
For example:
var str = 'To be, or not to be, that is the question.';
console.log(str.includes('To be'));       // true
console.log(str.includes('question'));    // true
console.log(str.includes('nonexistent')); // false
console.log(str.includes('To be', 1));    // false
console.log(str.includes('TO BE'));       // false


Bye

1 gennaio 2015

The correct JSON content type


The MIME media type for JSON text is application/json. The default encoding is UTF-8.

Resources:

Bye

Redirect a page with JavaScript

If you want to simulate someone clicking on a link, use location.href.
If you want to simulate an HTTP redirect, use location.replace.

For example:
// similar behavior as an HTTP redirect
window.location.replace("http://newpage.com");
// similar behavior as clicking on a link
window.location.href = "http://newpage.com";


Bye