Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
434 lines (352 sloc) 15.3 KB

Online Key Value Service and eMail relay

Key value Online Service: https://www.meeiot.org https://www.meeiot.com

Key JSON Online service

Key FILE Online service

Key QUEUE Online service

Key EMAIL Online service

store a value online http: //meeiot.org/put.. and get it back later https: //meeiot/get...

PUT: https://meeiot.org/put/5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f/mykey=ciao_bambiba

GET: https://meeiot.org/get/5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f/mykey

Use your own named 'keys' with meaning. (only letters, numbers and underscores)

There is a free token in these demos to mess with. The free token has restricted 
credential and response time of 4 seconds. There are 4 types of tokens accounts. 

    - 0 is the free token, and has ben generated for demo purpose. A token for account type 
        1 is generated on social logins. This token have a wide range of access for a decent 
        rig of devices. 
    - 1 social login, has the response time 1 second. Email relay is working with 
        Google social login token, because is the only social login which provie us with 
        your email. 
    - 2 paid token, with extended capabilities. 
    - 3 dedicated server, custom payloads
    
Once you have been authenticated either social login or PayPal you will have a token. 
The token is shown in the status bar. You dont have to stay logged in once you have the token.
Save it in a file so you can use it from anywhere, anytime. If you log in with different 
social logins you can have 3 different tokens, but there is no need, because
on a token you can have create many keys.
The number of active keys per token depends by the account you have. 
If you relog at later date with same social credentials the initial token would be handed back.
On each token you can have at any time 

    - Account 1 (social login)  maximum 16 keys and maximum 32 items in queue.    
    - Account 2 (19$)           maximum 64 keys and maximum 36000 items in queue. 
    - Account 3                 custom.
    
- A key which has not been updated for 2 days, except mail reminders is deleted.
- A queue push can overflow the queue if pop has not been called for long time. When
  the queue overflows, oldest value is deleted.
- Social login credentials can be deleted using the token generated with. 

alt text

Updates

2018 June 4       https://meeiot/act/TOKEN          Activity report on token, last 400 entries.
    check the free token:  https://www.meeiot.org/act/5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f

API's

meeiot.org/put      stores a value under a key
meeiot.org/get      get's a value from a key, updates last access time
meeiot.org/push     push a value to the head of the key queue. (keep adding)
meeiot.org/pop      pops (removes) a value from the tail of the key queue. updates last access time
meeiot.org/del      deletes the key / or a value for a key      

meeiot.org/del/TOKEN=0      Deletes the account associated to token. TOKEN remains active, but the account
                            and all user information associated with the TOKEN is deleted.
                            
https::meeiot.org/del/TOKEN              all the keys and values for token
    https::meeiot.org/del/TOKEN/key         just the key and it's val
    
https://meeiot.org/qdel                     deletes all the queue(s) or one queue
    https::qmeeiot.org/qdel/TOKEN           all the queues
    https::qmeeiot.org/qdel/TOKEN/que       just the queue 

meeiot.org/mail  {HTTP_POST JSON}          {from: to: subject: message:}    sends an email/ or callback mail reminder    

SAMPLES

Test User token: $TOKEN
    Operations using demo user id has a delay of 4 secoonds.
    Mail service is disabled for test token
   
meeIOTtest.sh
    see the extra hdr="headers,..." attribute
    If HTTP_POST has the 'hdr' field  hdr="HTTP_HEADERS,COMMA,SEPARATED", then when the value
    id taken back, proper http headers are send before the value.
# This is a demo token and has restricted access. Many users can mess with.
TOKEN=5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f
curl https://meeiot.org/push/$TOKEN/myq=1  # puts 1 in q
curl https://meeiot.org/push/$TOKEN/myq=1  # puts 1 again in q
curl https://meeiot.org/push/$TOKEN/myq=3  # puts 3 in q

curl https://meeiot.org/lst/$TOKEN         # lists the que items
curl https://meeiot.org/lst/$TOKEN/2       # lists the que items at index 2 which is 3 (index starts with 0)
# pops items from queue tail
curl https://meeiot.org/pop/$TOKEN/myq     # returns 1 (tail of the queue, pop's (deletes))
curl https://meeiot.org/pop/$TOKEN/myq     # returns 1
curl https://meeiot.org/pop/$TOKEN/myq     # returns 3 # now queue is emmpy

#JSON 
# stores a json at key myjson
curl -H "Content-Type: application/json" -X POST -d '{"value":"xyz"}' https://meeiot.org/put/$TOKEN/myjson

# stores a json from a file at key myjson
curl -v -H "Content-Type: application/json" -X POST -d @./json.txt https://meeiot.org/put/$TOKEN/myjson

#JSON WITH HTTP HEADER
# stores a json at key jsonweb and sends it back (get) with HTTP headers 'Content-Type: application/json'
curl  -F jsonweb=@./json.txt -F hdr="Content-Type: application/json"  http://meeiot.org/put/$TOKEN

#JPG WITH HTTP HEADER
# stores an image from a file at key imageweb and get's ig back with proper HTTP image headers
curl  -F imageweb=@./meeiot.jpg -F hdr="Content-Type: image/jpeg"  http://meeiot.org/put/$TOKEN

# The image is shown properly in a browser.
http://meeiot.org/get/$TOKEN/imageweb

# File http multpart is denied for demo token, but this would store a file at key mykey
curl -F mykey=@testfile https://meeiot.org/put/$TOKEN

# Mail relay is denied for demo token, but this would send an email to JSON:to field
curl -H "Content-Type: application/json" -X POST -d @./mail.json https://meeiot.org/mail/$TOKEN

# mail json format
{
    "from":"SENDER EMAIL",  // reply to
    "to":"RECEIVER EMAIL",
    "subject":"test mail meeiot org",
    "message": " an email containing some crap"
}
# mail is sent from 'meeiot.org' (check trash box)    

# Reminder. Sends back to your registered email at specified date. Needs a key for the reminder
# In case you want to delete the reminder use the key 

curl -k  -H "Content-Type: application/json" -X POST -d @./mail.json https://meeiot.org/mail/$TOKEN/birthday
# III  this might not work with community-singin other then Google 
# to keep your privacy to maximum. This would work with PayPal paid tokens only.
# If there is no email in the token's account the API returns an error
{
    "remind":{
        "year":2019,
        "month":12,
        "day":12,
        "gmt":-3
    },
    "cc":"other@email.ext",
    "subject":"wife birthday",
    "message": "gotta get this right!"
}


#To list your reminders, one per line as: when | key for reminder email | recipient to
curl https://meeiot.org/mail/$TOKEN
2018-10-20 12:37:00|myemail2|paypal-account@email.com,

#To list the reminder content as: when|content| recipient to
curl https://meeiot.org/mail/$TOKEN/birthday   # birthday is the mail key
2018-10-20 12:37:00|{exact json content}|paypal-account.com,

#To delete  a reminder send an empty json on the reminder  key
curl -k -H "Content-Type: application/json" -X POST -d '{}' https://meeiot.org/mail/$TOKEN/birthday


RESPONSE STRINGS AND ERROR CODES

0:X     success:scheme used
1:*     user id missing
2:*     value missing
3:*     
4:*     empty json post
5:*     key  too big or to small
6:*     value too big for the account, or empty
7:*     json too big for the account, or empty
8:*     multipart attachment FILE to big for this type of account
9:*     user id mismatch
10:*    user key mismatch. Error++, on 3 errors IP is banned.
11:*    access time to early since last access
12:*    access time error. could not determine last access time.
13:*    delete operation not allowed from other then put/push ip (demo id only)
14:*    client ip retrieval fail
20:*    system error
30:*    database err
31:*    database err
60:*    database err
61:*    database err
99:*    invalid request
111:*   no more data for the key
#mail errors
40:*    to email malformated    
41:*    from email malformated
42:*    subject to long 128 characters.
66:*    access denied for service

PHP SAMPLE

$TOKEN="5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://meeiot.org/put/$TOKEN/mydata");
curl_setopt($ch, CURLOPT_POST, 1);
$payload = json_encode( array( "jsonkey"=> "json value" ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$result = curl_exec($ch);
curl_close($ch);
echo "$result";

// or just inline using GET

file_get_contents("https://meeiot.org/put/$TOKEN/mydata={$MYDATA}");
file_get_contents("https://meeiot.org/get/$TOKEN/mydata");

ARDUINO SAMPLE

Using https://www.arduino.cc/en/Tutorial/WebClient

//
// share data
//
EthernetClient client;
if (client.connect(server, 80)) 
{
    char req[200];
    sprintf(req,"GET /put/5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f/mysensor=$d HTTP/1.1", sensorvalue);
    client.println(req);
    client.println("Host: meeiot.org/put");
    client.println("Connection: close");
    client.println();
    while (!client.available()) {delay(1000);}
    char c = client.read();
    Serial.print(c);
    client.close();    
  }
}

BASH SAMPLE

p=`ping -c 1 meeiot.org 2>&1 | grep "0% packet loss"`
[[ -z ${p} ]] && exit
JSON_TO_SHARE+/tmp/appjson
[[ ! -f ${JSON_TO_SHARE} ]] && exit
MYID="$TOKEN"
curl -vX POST https://meeiot.org/put/${NYID}/mydata -d @${JSON_TO_SHARE}  --header "Content-Type: application/json"

LINUX CRON SAMPLE SHARING A LIVEIMAGE SNAPSHOT IMAGE

#/bin/bash
#
# cron script with liveimage timelapse or motion detection image sharing trough meeiot.
#
p=`ping -c 1 meeiot.org 2>&1 | grep "0% packet loss"`
[[ -z ${p} ]] && exit
TOKEN="$TOKEN" ## need a paid account to allow over 16k POST's
pushd /data/snaps
image=$(ls -rt | tail --lines=1)
if [[ ! -z $lastfile ]];then
        curl -k -F img=@$image https://meeiot.org/push/5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f
fi
popd

TEST SCRIPT

#!/bin/bash
token=5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f
delay=4
echo "Test with free user token. Delay between put's/gets $delay seconds. Adding some values"
curl -k  http://meeiot.org/put/${token}/value=xxxxxxxx
sleep $delay
curl  -k http://meeiot.org/put/${token}/value1=somevalue
sleep $delay
curl  -k http://meeiot.org/put/${token}/value2=zzzzzzzzzzzzz
sleep $delay
echo "getting all keys"
sleep $delay

curl -k http://meeiot.org/get/${token}
echo ""
echo "getting all values"
sleep $delay
curl -k http://meeiot.org/get/${token}/value
echo ""
sleep $delay
curl -k http://meeiot.org/get/${token}/value1
echo ""
sleep $delay
curl -k http://meeiot.org/get/${token}/value2
echo " deleting all keys"
sleep $delay
curl -k http://meeiot.org/del/${token}
echo "getting all keys"
sleep $delay
curl -k http://meeiot.org/get/${token}

sleep $delay

echo "sending a text file as multipart"
curl  -k -F file1=@testfile http://meeiot.org/put/${token}
sleep $delay
echo "getting all keys"
echo ""
sleep $delay
curl -k http://meeiot.org/get/${token}
echo ""
echo "getting file"
sleep $delay
curl  -k http://meeiot.org/get/${token}/file1
echo ""

echo "put an image as raw then with headers"
sleep $delay
curl  -F imageweb=@./meeiot.jpg -F hdr="Content-Type: image/jpeg"  http://meeiot.org/put/${token}
sleep $delay
curl   -F image=@./meeiot.jpg http://meeiot.org/put/${token}
echo "get  image as raw"
echo "open the link in the browser:. See headers for content type are OK"
echo " http://meeiot.org/get/${token}/image"
read dummy
echo "get  image as web with http headers. open thislink in browser. then press a key to continue"
sleep $delay
echo  http://meeiot.org/get/${token}/imageweb
read dummy

echo "push an image as raw then with headers"
sleep $delay
curl  -F imageweb=@./meeiot.jpg -F hdr="Content-Type: image/jpeg"  http://meeiot.org/push/${token}
sleep $delay
curl   -F image=@./meeiot.jpg http://meeiot.org/push/${token}
echo "get  image as raw. open link in browser"
echo "http://meeiot.org/pop/${token}/image"
read dummy

echo "get  image as web with http headers. open thislink in browser. then press a key to continue"
sleep $delay
echo  http://meeiot.org/pop/${token}/imageweb
read dummy

echo "put a jsonraw to [jsonraw] = {...} and get it back raw "
sleep $delay
curl -H "Content-Type: application/json" -X POST -d '{"value":"xyz"}' http://meeiot.org/put/${token}/jsonraw
echo "keys for user"
sleep $delay
curl  http://meeiot.org/get/${token}
echo "getting back json"
curl  http://meeiot.org/get/${token}/jsonraw

echo "put a json and get it back with HTTP headers application/json "
sleep $delay
curl  -F jsonweb=@./json.txt -F hdr="Content-Type: application/json"  http://meeiot.org/put/${token}
echo "open the link in the browser:. See headers for content type are OK"
echo https://meeiot.org/get/${token}/jsonweb
read dummy;

shell sample using curl to check keys and queues storage

the user token was shorten as well for readability

TOKEN=5ba8e5788973226b3255844b37221c2a0f8a3921784b8cf1c93b9f
# add some keys
shell:~$ curl http://meeiot.org/put/$TOKEN/key1=value1
0:0
shell:~$ curl http://meeiot.org/put/$TOKEN/key2=value2
0:0
# make some queues
shell:~$ curl http://meeiot.org/push/$TOKEN/q1=value 
0:0
shell:~$ curl http://meeiot.org/push/$TOKEN/q1=value2
0:0
shell:~$ curl http://meeiot.org/push/$TOKEN/q1=value3
0:0
shell:~$ curl http://meeiot.org/push/$TOKEN/q2=value1
0:0

#list my keys
shell:~$ curl http://meeiot.org/get/$TOKEN          
key1
key2

#list my keys as links in browser
shell:~$ curl http://meeiot.org/get/$TOKEN/?
<pre><a href='https://meeiot.org/get/$TOKEN/key1'>https://meeiot.org/get/$TOKEN/key1</a>
<a href='https://meeiot.org/get/$TOKEN/key2'>https://meeiot.org/get/$TOKEN/key2</a><pre>

#list my keys as url
shell:~$ curl http://meeiot.org/get/$TOKEN/*
https://meeiot.org/get/$TOKEN/key1
https://meeiot.org/get/$TOKEN/key2shell:~$ 

#list my queues and the number of items in each que
shell:~$ curl https://meeiot.org/lst/$TOKEN
q1:3,q2:1

#list queus as web links
shell:~$ curl https://meeiot.org/lst/$TOKEN/?
<pre><a href='https://meeiot.org/lst/$TOKEN/q1/0'>https://meeiot.org/lst/$TOKEN/q1/0</a>
<a href='https://meeiot.org/lst/$TOKEN/q1/1'>https://meeiot.org/lst/$TOKEN/q1/1</a>
<a href='https://meeiot.org/lst/$TOKEN/q1/2'>https://meeiot.org/lst/$TOKEN/q1/2</a>
<a href='https://meeiot.org/lst/$TOKEN/q2/0'>https://meeiot.org/lst/$TOKEN/q2/0</a></pre>

#list as url's
shell:~$ curl https://meeiot.org/lst/$TOKEN/*
https://meeiot.org/lst/$TOKEN/q1/0
https://meeiot.org/lst/$TOKEN/q1/1
https://meeiot.org/lst/$TOKEN/q1/2

#offline now!

BeagleBone GPIO LED's online demo: https://www.meeiot.org/demo.php

(allow 6..7 seconds for LED's to update)

Check README2 too

https://github.com/zirexix/key-value-service/blob/master/README2.md