1
0
mirror of https://github.com/mbirth/wiki.git synced 2024-09-20 06:33:24 +01:00
wiki.mbirth.de/_posts/2010-10-09-sonyericsson-mbw150.md

3.9 KiB

title layout created toc tags
SonyEricsson MBW-150 default 2010-10-09 19:02:24 +0200 true
know-how
hardware
sony
sonyericsson
mbw150

![SonyEricsson MBW-150]({{ site.url }}/assets/mbw150.jpg)

Product Page

Android 2.x-Phones

Notification service using OpenWatch, Tasker and PHP

Setup Tasker

  1. create a new time-based profile, let it run every 5 minutes or so
  2. add the following actions: 1. Net → HTTP Get
    • Server:Port: www.example.org (<your webserver>)
    • Path: /notifier/notify.php (adapt according to your setup)
    • Attributes: <leave empty>
    • Timeout: 10 (default)
    • Mime Type: text/plain; charset=utf-8
    • Output File: <leave empty> - Tasker → Stop
    • If: [X]
      • %HTTPD Isn't Set - Variable → Variable Split
    • Name: %HTTPD
    • Splitter:
    • Delete Base: [ ] - Alert → Notify (you can omit this one if you like)
    • Title: Remote Notification
    • Text: %HTTPD1 %HTTPD2 (%HTTPD3 seconds ago) - Misc → Action Intent
    • Action: com.smartmadsoft.openwatch.action.VIBRATE
    • Cat: None
    • Data: <leave empty>
    • Extra: line1:%HTTPD1
    • Extra: line2:%HTTPD2 (Note: There are 2 Extra input fields)
    • Target: Broadcast Receiver
  • Done!

Setup Server

Put the following file onto a webserver capable of running PHP scripts (notify.php):

<?php

class DataStore {
    private $file;
    private $data = array(
        'entries' => array(),
    );
    private $modified = false;

    public function __construct( $filename = 'queue.json' ) {
        $this->file = getcwd() . '/' . $filename;
        if ( file_exists( $this->file ) ) {
            $this->load();
        }
    }

    public function __destruct() {
        if ( $this->modified ) {
            $this->save();
        }
    }

    public function add( $line1, $line2 ) {
        $this->data['entries'][] = array(
            'timestamp' => time(),
            'line1' => $line1,
            'line2' => $line2,
        );
        $this->modified = true;
    }

    public function getNext() {
        if ( $this->getCount() > 0 ) {
            $entry = array_shift( $this->data['entries'] );
            $this->modified = true;
            return $entry;
        }
        return array();
    }
        
    public function getCount() {
        return count( $this->data['entries'] );
    }

    private function save() {
        $json = json_encode( $this->data );
        file_put_contents( $this->file, $json, LOCK_EX );
        $this->modified = false;
    }

    private function load() {
        $fc = file_get_contents( $this->file );
        $this->data = json_decode( $fc, true );
        $this->modified = false;
    }
}
    
$ds = new DataStore();
    
header( 'Content-Type: text/plain; charset=utf-8' );
if ( isset( $_REQUEST['l1'] ) && isset( $_REQUEST['l2'] ) ) {
    // new notification ~~> store
    $ds->add( $_REQUEST['l1'], $_REQUEST['l2'] );
} else {
    // else: Display next notification, if any
    $entry = $ds->getNext();
    if ( isset( $entry['timestamp'] ) ) {
        $span = time() - $entry['timestamp'];
        echo $entry['line1'] . '¶' . $entry['line2'] . '¶' . $span;
    }
}

?>  

Usage

Under Linux, you can send a notification like this:

wget -O - --quiet "http://www.example.org/notifier/notify.php?l1=This+is+line1&l2=And+this+is+line2"