mirror of
https://github.com/mbirth/wiki.git
synced 2024-11-14 14:06:46 +00:00
4.0 KiB
4.0 KiB
title | layout | created | updated | toc | tags | |||||
---|---|---|---|---|---|---|---|---|---|---|
SonyEricsson MBW-150 | default | 2010-10-09 19:02:24 +0200 | 2010-10-09 19:02:24 +0200 | true |
|
![SonyEricsson MBW-150]({{ site.url }}/assets/mbw150.jpg)
Android 2.x-Phones
Notification service using OpenWatch, Tasker and PHP
Setup Tasker
- create a new time-based profile, let it run every 5 minutes or so
- add the following actions:
- 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>
- Server:Port:
- Tasker → Stop
- If:
[X]
%HTTPD
Isn't Set
- If:
- Variable → Variable Split
- Name:
%HTTPD
- Splitter:
¶
- Delete Base:
[ ]
- Name:
- Alert → Notify (you can omit this one if you like)
- Title:
Remote Notification
- Text:
%HTTPD1 %HTTPD2 (%HTTPD3 seconds ago)
- Title:
- 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
- Action:
- Net → HTTP Get
- Done!
Setup Server
Put the following file onto a webserver capable of running PHP scripts (notify.php
):
{% highlight php %}
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; } } {% endhighlight %} ### 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"