Tuesday, February 28, 2017

Little Note

= Little Note =

ifconfig wlan0 | grep "inet " | awk -F'[: ]+' '{ print $ 4 }'
iwinfo |grep "Link Quality" |cut -d: -f3
echo "currentsong" | nc localhost 6600 |grep -e "file"
echo "currentsong" | nc localhost 6600 |grep -e "file" |cut -d'.' -f2

Friday, May 27, 2016

Grab MPD status

Grab MPD status


install MPC
set bind address on mpd.conf to "0.0.0.0"

run command

echo "currentsong" | nc localhost 6600 | grep - e "^Title: " -e "^Name: "

echo "currentsong" | nc localhost 6600 | grep -e "^Name: "|cut -d: -f2
echo "currentsong" | nc localhost 6600 |grep -e "Name"|cut -d: -f2


example

root@OpenWrt:/mnt/data/mp3/slow# echo "currentsong" | nc localhost 6600 | grep -
e "^Title: " -e "^Name: "


Result
Title: Mark Blee - MOVIN' ON! 23.05.16 - Mark Blee - MOVIN' ON! 23.05.16
Name: SOULPOWER-RADIO.COM
root@OpenWrt:/mnt/data/mp3/slow#



MPD on OpenWRT

MPD on OpenWRT

Step :

1. exroot
2. install soundcard driver

# Opkg install kmod-sound-core kmod-usb-audio alsa-utils
3. Install MPC and MPD

# Opkg install mpd mpc alsa-utils

4. Edit mpd.conf file

music_directory         "/mnt/data/mp3"
playlist_directory              "/mnt/data/mpd/playlists"
db_file                 "/mnt/data/mpd/database"
log_file                        "/mnt/data/mpd/log"
pid_file                        "/mnt/data/mpd/mpd.pid"
state_file                      "/mnt/data/mpd/state"
bind_to_address         "0.0.0.0"
port                            "6600"
log_level                       "default"
gapless_mp3_playback           "yes"
save_absolute_paths_in_playlists        "yes"
metadata_to_use "artist,album,title,track,name,genre,date,composer,performer,dis
auto_update     "yes"
auto_update_depth "0"
follow_outside_symlinks "yes"
follow_inside_symlinks          "yes"
password                        "password@read,add,control,admin"
default_permissions             "read,add,control,admin"
input {
        plugin "curl"
}
# An example of an ALSA output:
#
audio_output {
        type            "alsa"
        name            "My ALSA Device"
        format          "44100:16:2"
        device          "hw:0,0"        # optional
        mixer_type      "software"      # optional
        mixer_device    "default"       # optional
        mixer_control   "software"              # optional
        mixer_index     "0"             # optional

}


goto  file /etc/init.d/mpd
change
 [ -x /usr/bin/amixer ] && /usr/bin/amixer set PCM 40
 to
[ -x /usr/bin/amixer ] && /usr/bin/amixer set Speaker 150

Friday, April 22, 2016

Arduino with RFID

Arduino with RFID




#include
#include

#define uchar unsigned char
#define uint unsigned int

//4 bytes tag serial number, the first 5 bytes for the checksum byte
uchar serNumA[5];

uchar fifobytes;
uchar fifoValue;

AddicoreRFID myRFID; // create AddicoreRFID object to control the RFID module

/////////////////////////////////////////////////////////////////////
//set the pins
/////////////////////////////////////////////////////////////////////
const int chipSelectPin = 10;
const int NRSTPD = 9;

//Maximum length of the array
#define MAX_LEN 16

void setup() {                
   Serial.begin(9600);                        // RFID reader SOUT pin connected to Serial RX pin at 9600bps 

  // start the SPI library:
  SPI.begin();
  
  pinMode(chipSelectPin,OUTPUT);              // Set digital pin 10 as OUTPUT to connect it to the RFID /ENABLE pin 
    digitalWrite(chipSelectPin, LOW);         // Activate the RFID reader
  pinMode(NRSTPD,OUTPUT);                     // Set digital pin 10 , Not Reset and Power-down
    digitalWrite(NRSTPD, HIGH);

  myRFID.AddicoreRFID_Init();  
}

void loop()
{
  uchar i, tmp, checksum1;
uchar status;
        uchar str[MAX_LEN];
        uchar RC_size;
        uchar blockAddr; //Selection operation block address 0 to 63
        String mynum = "";

        str[1] = 0x4400;
//Find tags, return tag type
status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
if (status == MI_OK)
{
            Serial.println("RFID tag detected");
      
}

//Anti-collision, return tag serial number 4 bytes
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK)
{
            checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
          
           Serial.print(str[0]);
           Serial.print(" , ");
       Serial.print(str[1]);
            Serial.print(" , ");
       Serial.print(str[2]);
           Serial.print(" , ");
       Serial.print(str[3]);
            Serial.print(" , ");
       Serial.print(str[4]);
            Serial.print(" , ");
            Serial.println(checksum1,BIN);
            
            Serial.println();
            delay(1000);
}
        myRFID.AddicoreRFID_Halt();   //Command tag into hibernation              

}

Tuesday, February 16, 2016

Playing Ultrasonic sensor with Arduino


Playing Ultrasonic sensor with Arduino


1. The Connection


1424201420-2wire_bb.png




2. The script

#define echopin 3
#define TRIGPIN 2

void setup()
{
  Serial.begin (9600);
  pinMode (echopin,INPUT);
  pinMode (TRIGPIN, OUTPUT);
}
void loop()

{ digitalWrite(TRIGPIN,LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN,HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN,LOW);

float distance = pulseIn(echopin,HIGH);
distance = distance/46;
Serial.print (distance);
Serial.println (" cm");
if (distance < 10)
{
Serial.print("AWAS HATI-HATI");
Serial.println (" Jarak kurang dari 10 cm");
}
else if
 (distance < 20)
{
Serial.print("Waspada");
Serial.println (" Jarak kurang dari 20 cm");
}
else
{
  Serial.println ("Jarak Masih Aman");

}
delay (200);
}

playing with Gyro sensor GY-291 and Arduino



1. connection.





2. The Script

/* Include the standard wire library */
#include

/* Alternate I2C address of the module */
#define I2C_Add 0x53

/* ADXL345 register addresses */
#define POWER_CTL 0x2D
#define DATA_FORMAT 0x31
#define X_Axis 0x32
#define Y_Axis 0x34
#define Z_Axis 0x36

/* Accelerometer range modes */
#define RANGE_2g 0
#define RANGE_4g 1
#define RANGE_8g 2
#define RANGE_16g 3

void setup()
{
  /* Initialise the I2C bus */
  Wire.begin();  
  
  /* Initialise the serial interface */
  Serial.begin(9600);
  
  /* Initialise the ADXL345 */  
  Init_ADXL345(RANGE_2g);
}

/* Main program */
void loop()
{
  /* Continually read and output all 3 axis to the serial port */
  Serial.print("X: ");
  Serial.print(Read_Axis(X_Axis));
  
  Serial.print(" Y: ");
  Serial.print(Read_Axis(Y_Axis));
  
  Serial.print(" Z: ");
  Serial.println(Read_Axis(Z_Axis));
}

/* Read one of the 3 axis via the I2C interface */
int Read_Axis(byte axis)
{
  int Data;
   
  Wire.beginTransmission(I2C_Add); 
  Wire.write(axis); 
  Wire.endTransmission(); 
  
  Wire.beginTransmission(I2C_Add);
  Wire.requestFrom(I2C_Add, 2);
  
  /* If data is available then read it (2 bytes) */
  if(Wire.available())     
  { 
    Data = (int)Wire.read();
    Data = Data  | (Wire.read() << 8);
  }else
  {
    Data = 0;
  }
    
  Wire.endTransmission();  
  return Data;
}


/* Initialise the ADXL345 */
void Init_ADXL345(byte range)
{
  Wire.beginTransmission(I2C_Add);
  
  /* Set the sensitivity of the module */
  Wire.write(DATA_FORMAT); 
  Wire.write(range); 
  Wire.endTransmission(); 
  
  /* Put the module into measurement mode to start taking measurements */
  Wire.beginTransmission(I2C_Add);
  Wire.write(POWER_CTL); 
  Wire.write(0x08); 
  
  Wire.endTransmission(); 
}


Friday, February 5, 2016

Controlling arduino using serial openwrt

Controlling arduino using serial openwrt




1. Create sketch

// include the library code:
#include

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
}

2. Upload the sketch
3. For testing the arduino ,open serial monitor, and type something.


4. Install modem driver on openwrt

root@OpenWrt:~# opkg install kmod-usb-serial kmod-usb-serial-ftdi

5. Attach Arduino to OpenWRT, and check on dmesg

[ 5182.260000] usb 1-1: new full-speed USB device number 3 using ehci-platform
[ 5182.430000] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

6. Install coreutils-stty

root@OpenWrt:~# opkg install coreutils-stty

7. Add  this to /etc/rc.local before start
stty -F /dev/ttyACM0 4:0:18b2:0:0:0:0:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:
stty -F /dev/ttyACM0 9600 raw
=> Reboot router

8. Test from openwrt,

- open ssh to IP of openwrt
- type echo -en "Selamat Siang" > /dev/ttyACM0   than press enter.

9. Result on LCD screen.