Variable on net

Hi,

In first sorry for my English because i'm french ^^

My project is to collect variables in a ".txt" on my FTP with python !

My code:

import feedparser import serial import time import urllib

------------------------------------------------------------------------------

request = "http://modelismebychico.free.fr/g.txt" SERIALPORT = "COM3" delay = 2

------------------------------------------------------------------------------

def check_gmail (request): try: newmails = urllib.urlopen("http://modelismebychico.free.fr/g.txt") except: return 'ERROR' else: return newmails

------------------------------------------------------------------------------

try: ser = serial.Serial("COM3", 9600) except: print 'No device connected !' else: while True: reply = check_gmail(request) if reply == 'ERROR': ser.write(-1) print reply else: if reply > 0: ser.write("m") else: ser.write("n") print str(reply) + ' new mail(s) !' time.sleep(delay)

My problem is that pyhton don't collect the variable, he say me "no new Emails" all times ...

thx

What is your Arduino doing?

In first sorry for my English because i'm french ^^

My French is probably worse than your English :) and you can always use google translate to check your texts

to debug this you should print the value of - newmails after this line: newmails = urllib.urlopen("http://modelismebychico.free.fr/g.txt")

as the txt file contains [var:"0"] I assume newmails will contain it to.

Then you check if it is greater than zero - if reply > 0: as the textstring in the reply cannot be parsed to a number it will be zero I assume so it will always send 'n' to the Arduino and the Arduino will display

"no new Emails" all times

---- Google TRanslate output ----

En premier désolé pour mon anglais parce que je suis français ^ ^ [/ quote] Mon français est probablement pire que votre niveau d'anglais:) et vous pouvez toujours utiliser Google Translate pour vérifier vos textes

Pour déboguer ce que vous devez imprimer la valeur de - newmails après cette ligne: newmails = urllib.urlopen ("http://modelismebychico.free.fr/g.txt")

que le fichier txt contient [var: "0"] Je suppose newmails le contenir à.

Ensuite, vous vérifiez si elle est supérieure à zéro - si la réponse> 0: que le textstring dans la réponse ne peut pas être analysé pour un certain nombre, il sera zéro Je suppose que oui, il sera toujours envoyer 'n' à l'Arduino Arduino et les affiche

"pas de nouveaux e-mails" toutes les fois [/ quote]

Donc, vous devons enlever le numéro de la variable newmail.

espère que cette aide, Rob PS, s'il vous plaît utilisez le bouton # lors de la publication du code PS2, s'il vous plaît décrire votre application dans un peu plus détaillée, l'objectif que vous souhaitez atteindre (une notification mail), comment les flux de données (site Web - Ethernet -> PC avec pythonscript - série -> Arduino -> Affichage à cristaux liquides). Cela rend plus compréhensible pour le forummembers que nous n'avons pas tous une balle crystall à voir aussi loin que la France;)

So you have to strip out the number from the newmail variable.

hopes this helps, Rob PS, please use the # button when posting code PS2, please describe your application in a bit more detail, the goal you want to reach (a mail notifier) , how the data flows (website - ethernet -> PC with pythonscript -- serial --> Arduino -> LCD display). That makes it more understandable for the forummembers as we don't have all a crystall ball to see as far as France ;)

Hi,

Thanks for your answers ;)

My objectif is to do on or off a LED by a web interface. My web interface whrite in my .txt the variable "0" when i push the button off in my web interface and "1" when i push the button on. My arduino was linked to a PC with my python code who analyse the .txt in my FTP.

the "newmails" variable is that i have use a old chexkmail code to do that ! in fact it will be "led-status" and not "newmails" ^^

Actualy i have not do the web interface because my python code don't work .... :roll_eyes:

When the txt file contain "0" i would the python code said "n" to my arduino and when my file contain "1" i would the pyhton said "m" to my arduino !

thx a lot

When the txt file contain "0"

The text file contains [var:"0"] you can see it when you paste the URL to your webbrowser

This code works and shows the content of reply

import serial
import time
import urllib

request = "http://modelismebychico.free.fr/g.txt"
SERIALPORT = "COM3"
delay = 2

# 
# CHECKMAIL
#
def check_gmail (request):
   try:
      f = urllib.urlopen(request)
      s = f.read()
      f.close()
   except:
      return 'ERROR'
   else:
      return s

# 
# MAIN
#
reply = check_gmail(request)
print reply

Thannnnx a lot XD XD XD XD

The good code:

import serial
import time
import urllib

# ------------------------------------------------------------------------------ #

request = "http://modelismebychico.free.fr/g.txt"
SERIALPORT = "COM3"
delay = 2

# ------------------------------------------------------------------------------ #

# CHECKMAIL
#
def check_gmail (request):
   try:
      f = urllib.urlopen(request)
      s = f.read()
      f.close()
   except:
      return 'ERROR'
   else:
      return s

# ------------------------------------------------------------------------------ #

try:
    ser = serial.Serial("COM3", 9600)
except:
    print 'No device connected !'
else:
    while True:
        reply = check_gmail(request)
        if reply == 'ERROR':
            ser.write(-1)
            print reply
        else:
            if reply == "m": 
               ser.write("m")
            else: 
               ser.write("n")
            print str(reply)
        time.sleep(delay)