samedi 31 octobre 2015

PAWLOV : get the right level of romance, at the right time.

Sometimes when you're working late at the office or when you're away for business, you're not there to feed your loved one with your witty romantic lines.

Of course, you can always text or tweet here, but what if (s)he could get the exact level of romance (s)he wants, at the time she wants ? And what if you had all the plans & instructions to build one before next Valentine ?

Introducing the PAWLOV - "Potentiometric Automatic Wireless LOVe button".

Instructions are easy - you just have to adjust the level of romance needed (from zero to highly romantic) using the potentiometer, press the red button and bingo - your lover gets a romantic tweet !

This projects was based on Benlo's ''the button" ESP project (even if this is a simpler version using the fact that the emergency button locks itself in the "on" position), and there are more energy efficient versions.

   - ESP-12 (less than 2$ on aliexpress) with nodemcu lua firmware installed (lots of manuals for this on the internet)
   - emergency push button (4$
   - a 10 kohm linear resistor (1 $ or less)
   - 2 AA batteries + battery holder (a few cents on aliexpress)
   - a 22 kohm resistor (to drop the voltage from 3V  to 1V, which is the maximum voltage for

Software is quite simple: when the user hits the emergency button (the model I used stays locked in the "on" position), this powers the ESP8266. At init, ESP8266 connects the wifi spot. When connected it hits a PHP link and transmits the voltage on A0 pins, which generates a tweet which romantism reflected the volat. Then the ESP goes to sleep.

Software loaded on the ESP-12

Init.lua (nb: you need to put the name of your AP& password instead of the text between "XXX" marks)
wifi.sta.config("XXX you ap anme XXX","XXX password XXX")
tmr.alarm(0, 1000, 1, function()
   if wifi.sta.getip() == nil then
      print("Connecting to AP...\n")
      tries = tries + 1
      if (tries > 100) then
      ip, nm, gw=wifi.sta.getip()
      print("IP Info: \nIP Address: ",ip)
      print("Netmask: ",nm)
      print("Gateway Addr: ",gw,'\n')

sendmail.lua (nb: you need to put the name of you host & PHP pages instead of the text between "XXX" marks)

conn:on("receive", function(conn, payload)
 jdone=jdone + 1

    print("Sent !")
    jdone = jdone + 1

conn:connect(80,'XXX your server IP adress XXX')
conn:send("GET XXX folder of the php file that generates a tweetXXXbuttonp.php?m="" HTTP/1.1\r\n")
conn:send("Host: XXXput the name of your host XXX\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")

tmr.alarm(0, 5000, 1, function()
  if (jdone == 2) then
      print("Going to sleep")


Software loaded on your PHP host
buttonp.php (nb: you need to put the name of you host & PHP pages instead of the text between "XXX" marks)
This page uses TwitterAPIExchange.php (you'll find it easily with google). You need keys to access it, but it is well documented on the internet.



function getFeed($feed_url) { 
    $content = file_get_contents($feed_url);
if (($content != FALSE) and (strpos($content,"<channel>") != FALSE)) {
$x = new SimpleXmlElement($content);

if (rand(0,1)==0) {

$levels=array("pas du tout","un peu","beaucoup","passionnément","a la folie");
$pot=(intval($m) * count($levels)) / 1024;
$tweet=" i love you ".$levels[$pot];

foreach($inFeed->channel->item as $entry) {
if ($twtn==0){
$tweet=substr("@xxxyour loved one twitter account XXXX ".$tweet."-".str_replace('"',"",strip_tags($entry->description)),0,116)." ".$entry->link;

$url = ''; 
$requestMethod = 'POST';
$postfields = array('status' => $tweet ); 
$settings = array(
    'consumer_key' => "XXX put here your twitter account info XXX",
    'consumer_secret' => "XXX put here your twitter account info XXX",,
    'oauth_access_token' => "XXX put here your twitter account info XXX",,
    'oauth_access_token_secret' => "XXX put here your twitter account info XXX",

$twitter = new TwitterAPIExchange($settings);
$twitter->buildOauth($url, $requestMethod)


Aucun commentaire:

Enregistrer un commentaire