Shop OBEX P1 Docs P2 Docs Learn Events
How to use email to control Spinneret OUT port? — Parallax Forums

How to use email to control Spinneret OUT port?

john_sjohn_s Posts: 369
edited 2011-10-23 18:45 in Accessories
Before jumping into a Spinneret project I'd like to ask around in case somebody thought about or implemented this method.

Objective: Every time a PC sends an email it is also forwarded to Spinneret. Upon receiving of a specific email Spinneret reacts by setting the OUT pin HIGH.

Scenario A: Both - PC and Spinneret - are on to the same ethernet network.
Scenario B: PC and Spinneret are a distance apart and not ethernet wired

Question: Can you point me out to where should I start with this? Did anybody come across a working example?

Thanks,
John

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-10-21 18:46
    Email is sent to an email server. A client application knows how to read email on an email server. There are two main email client types; POP3 and IMAP. A POP3 account downloads the email to your local PC then deletes the email from the server. An IMAP account leaves the email on the server.

    To send an email to the Spinneret means that the Spinneret must be an email server. As far as I know, no one has created a Spinneret mail server. However, the community has created email clients.

    Here is Beau's SMTP client
    http://forums.parallax.com/showthread.php?134586-DEMO-SMTP-quot-SpinMail-quot

    The SMTP I built
    http://spinneret.servebeer.com:5000/client/email.htm

    Now both of these examples are SMTP which is out going email but the concept applies to reading email on a server only the port and commands are different.
    john_s wrote:
    Question: Can you point me out to where should I start with this?
    Learn about how email works.
    http://smanage.tripod.com/tel.html
  • john_sjohn_s Posts: 369
    edited 2011-10-21 22:28
    Thanks Mike, it's time to learn 'again' ... but at least I know where to start :-)
  • john_sjohn_s Posts: 369
    edited 2011-10-22 12:39
    I found this http://members.home.nl/bzijlstra/software/examples/wiz810mj.htm#emailswitcher

    He calls it Email-switcher and it's pretty close to what I'm trying to achieve...

    wiz_mail.jpg
    600 x 270 - 55K
  • Mike GMike G Posts: 2,702
    edited 2011-10-22 17:46
    John, if you are using HTTPServer this method will read POP3 email item[1] from your (my) ISP. Understand, your ISP might be a little different. The code assumes the email server has at lest one email to read. The LIST command lists emails and content size. RETR <index> returns an email header and content. It's up to you to parse the content and determine what to do next.
    PRI CheckEmail(id) | size, tempMask, wait
        tempMask := tcpMask
        SetTcpSocketMaskById(id, 0)
    
        wait := 200
        
        Socket.Close(id)
        pause(delay)
        InitializeSocketForPop3(id)
        pause(delay)
        
        ' Connect to the mail server
        pst.str(string(13, "Connecting to POP3 server"))
        
        Socket.Connect(id)
        pause(wait)
        repeat while !Socket.Connected(id)
        
        pst.str(string(13,"Connected... Talking with POP3 server"))
    
        ' Username
        StringSend(id, string("USER ********", 13, 10))
        pause(wait)
    
        ' Password
        StringSend(id, string("PASS ********", 13, 10))
        pause(wait)
    
        StringSend(id, string("LIST", 13, 10))
        pause(wait)
    
        StringSend(id, string("RETR 1", 13, 10))
        pause(wait)
    
        StringSend(id, string("QUIT", 13, 10))
        pause(wait)
    
        pst.str(string(13,"Done",13))
        pst.str(string(13,"Conversation Log",13))
        
        'Display log
        repeat until size := Socket.rxTCP(id, @rxdata)
        pst.str(@rxdata)
        
        pst.str(string(13, "Disconnect and reset socket: "))
        pst.dec(id)
        pst.char(13)
        
        ' Reset the socket
        Socket.Disconnect(id)
        pause(delay)
        
        ' Reset the tcpMask 
        tcpMask := tempMask
        
        InitializeSocket(id)
        pause(delay)
    

    Conversation with the server as seen by the Spinneret (custom terminal).
    Connecting to POP3 server
    Connected... Talking with POP3 server
    Done
    
    Conversation Log
    +OK fed1rmfepi207 InterMail POP3 server ready.
    +OK please send PASS command
    +OK agavejoe is welcome here
    +OK 2 messages
    1 1427
    2 1455
    .
    +OK 1427 octets
    Return-Path: <mike.gebhard@agaverobotics.com>
    Received: from fed1rmimpi06.cox.net ([70.169.32.78])
              by fed1rmfepi108.cox.net
              (InterMail vM.8.01.04.00 201-2260-137-20101110) with ESMTP
              id <20111022233418.IGCH3814.fed1rmfepi108.cox.net@fed1rmimpi06.cox.net>
              for <agavejoe@cox.net>; Sat, 22 Oct 2011 19:34:18 -0400
    Received: from doghorn.arvixe.com ([65.98.8.130])
    	by fed1rmimpi06.cox.net with IMP
    	id nzaD1h00k2oKwY105zaJZA; Sat, 22 Oct 2011 19:34:18 -0400
    X-CT-Class: Clean
    X-CT-Score: 0.00
    X-CT-RefID: str=0001.0A020206.4EA352FA.0084,ss=1,re=0.000,fgs=0
    X-CT-Spam: 0
    X-Authority-Analysis: v=1.1 cv=LEH7A/jAbh7KGh70wc9tg2clxX+UbejRzuZCSJ3RG1w=
     c=1 sm=1 a=342EsJ9rKw4A:10 a=gZEd2G8trekA:10 a=8nJEP1OIZ-IA:10
     a=2xOCi88Fe6CiSJcwON05BQ==:17 a=nS36O97Bj3wUElCrIrAA:9 a=wPNLvfGTeEIA:10
     a=2xOCi88Fe6CiSJcwON05BQ==:117
    X-CM-Score: 0.00
    Received: from [192.168.1.102] ([68.99.244.218])
    	by doghorn.arvixe.com
    	; Sat, 22 Oct 2011 16:33:50 -0700
    X-AuthUser: mike.gebhard@agaverobotics.com
    Message-ID: <4EA352F3.50304@agaverobotics.com>
    Date: Sat, 22 Oct 2011 16:34:11 -0700
    From: Mike Gebhard <mike.gebhard@agaverobotics.com>
    User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2
    MIME-Version: 1.0
    To: agavejoe@cox.net
    Subject: test
    Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    Content-Transfer-Encoding: 7bit
    
    test
    
    .
    +OK agavejoe InterMail POP3 server signing off.
    
    Disconnect and reset socket: 3
    

    You need to know your ISP domain IP and port to initialize the TCP socket.
    PRI InitializeSocketForPop3(id)
      Socket.Initialize(id, TCP_PROTOCOL, port2, pop3Port, @pop3Ip)
      return
    
  • john_sjohn_s Posts: 369
    edited 2011-10-22 19:40
    Mike,

    I understand that the amount of info I need to plow through is way above of what I try to accomplish.

    Let's first try the 'Scenario A' where my Spinneret sits next to my PC and is RJ-cable wired to the same switch.
    Can it be just a switch or is a router more appropriate in this place?

    I'd like to start with my Prop to just start counting the number of emails that my PC sends via Outlook Express.

    Is it possible for the Prop to somehow 'become aware' and count the instances when my PC sends an email without actually going through my ISP email server loop?

    Can I send an email from OE directly to say 192.168.1.120:5000 ?

    Thanks,
    John
  • Mike GMike G Posts: 2,702
    edited 2011-10-23 06:17
    Is it possible for the Prop to somehow 'become aware' and count the instances when my PC sends an email without actually going through my ISP email server loop?
    No, the Spinneret does not listen to all conversation on the network.
    Can I send an email from OE directly to say 192.168.1.120:5000 ?
    It's possible but building a web server is not a trivial task. Instead of sending an email, why not send an HTTP message to Spinneret?
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-10-23 08:12
    Mike G wrote: »
    It's possible but building a web server is not a trivial task. Instead of sending an email, why not send an HTTP message to Spinneret?

    I'm trying to work with the Spinneret as well, and just starting to get my head around this kind of thing. When you say "send an HTTP message to Spinneret", you mean through a control on a web page? I'm working through this tutorial:

    http://spinneret.servebeer.com:5000/index.htm

    and just about at the place where I will be turning on and off the Spinneret's LED through a webpage. I'm not understanding what's going on behind the scenes, though. My browser is requesting a page which is stored on the Micro SD card in the Spinneret, correct? And when that page loads into whatever computer is accessing it, the controls (buttons, hyperlinks, etc.) somehow send messages to the Spinneret? There is going to be Spin (or Prop Asm) code on the Spinneret that interprets those messages, and does things like bring the LED pin high/low, right? Is there a better way to understand this?
  • Mike GMike G Posts: 2,702
    edited 2011-10-23 08:27
    Web browsers generate HTTP requests. For example, clicking a link. The browser sends a HTTP resource (file) request to the web server and the web server responses. That's about it.
    sylvie369 wrote:
    There is going to be Spin (or Prop Asm) code on the Spinneret that interprets those messages, and does things like bring the LED pin high/low, right?
    Yes, read on. Later you'll find filters to intercept resource requests and run custom SPIN code.
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-10-23 08:39
    (Trying not to hijack the thread - stop me if I'm doing that)

    Okay, the LED On/Off code works. I'm able to turn on and off the Spinneret's LED from the browser on my cell phone. That's exceptionally cool. And I understand how that works well enough that I'm confident that I could instead be turning on or off one of the I/O pins (and therefore controlling an external device) or sending a serial message out the serial port. I'm starting to get it, both with respect to the relationship between server and browser, and the relationship between the HTML code and the Spin code on the Spinneret. Amazing device.
  • Mike GMike G Posts: 2,702
    edited 2011-10-23 08:47
    Like anything it takes effort to understand. Glad to hear the concept is sinking in. You might want to start a new thread, if needed, so we don't diverge from the original subject.
  • john_sjohn_s Posts: 369
    edited 2011-10-23 08:51
    sylvie369, I'm working through the same tutorial :-)
  • sylvie369sylvie369 Posts: 1,622
    edited 2011-10-23 13:57
    john_s wrote: »
    sylvie369, I'm working through the same tutorial :-)

    Are you okay with asking both of our questions in your thread, then?
  • john_sjohn_s Posts: 369
    edited 2011-10-23 18:45
    @sylvie369,

    You're welcome to join this thread as it only helps us all to figure out the answer and sharing tips and notes when learning the innards of Spinneret. I'm a beginner with any Prop related subject, and will put my hands on the real thing sometime next week when it arrives. I figure it's a joy to learn when designing something you need. Till then I'd be glad if you keep asking your Spinneret / Pro questions using this thread as well...

    Close to what you've achieved with a cell phone - I would like to see Spinneret's LED blinking ON / OFF every time an email is send or received ....
Sign In or Register to comment.