Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Data logging addon
#21

Updated files on GitHub

Changelog:
- Changes in handling of the unit type to have full compatibility with the WeeWx plugin
Reply
#22

Updated files on GitHub.

Changelog:
Added data validation for TX sensor data from "additional" TX modules which are not configured as main sensor to remove "0" values coming when the packages are not received at the RX already.
Reply
#23

Hi,
I'm running the script under Window with Python2.7 successfully except sending mail.
is there something to adapt in sendmail because although I modify the parameters the sending is not done.
Quote:2020-02-08 10:56:58 Logging script started.
08.02.2020 10:58:59 Mail could not be sent. 

Thanks

Laurent
Reply
#24

Line 430 - 443:
Code:
                                                try:
      # call sendmail() and generate a new mail with specified subject and content
                                                        if EnableDebug == 1:
                                                                print "Sending Email."
                                                        sendmail(str(receiver),'Wetterstation error',str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) + ' No data is logged since 10 minutes')
                                                        if EnableErrorLog == 1:
                                                                with open(ErrorLog,'a') as err:
                                                                        err.write (str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) +" Mail sent to " + str(receiver) + "\n")
                                                                        mailSent = 1
                                                except:
                                                        if EnableErrorLog == 1:
                                                                with open(ErrorLog,'a') as err:
                                                                        err.write (str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) +" Mail could not be sent. \n")
                                                                        mailSent = 1

You change it like this:
Code:
                                               # try:
      # call sendmail() and generate a new mail with specified subject and content
                                                        if EnableDebug == 1:
                                                                print "Sending Email."
                                                        sendmail(str(receiver),'Wetterstation error',str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) + ' No data is logged since 10 minutes')
                                                        if EnableErrorLog == 1:
                                                                with open(ErrorLog,'a') as err:
                                                                        err.write (str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) +" Mail sent to " + str(receiver) + "\n")
                                                                        mailSent = 1
                                                #except:
                                                        #if EnableErrorLog == 1:
                                                                #with open(ErrorLog,'a') as err:
                                                                        #err.write (str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) +" Mail could not be sent. \n")
                                                                        #mailSent = 1
 
Comment the "try" and the whole "except" section then the script will crash with the "real" error message. Otherwise it is always hidden behind de exception.
Reply
#25

I tryed but the script doesn't crash !
(I unplug RX for the email test)
Quote: .......
Rain_TX3: 0.0 mm
Rain_Rate_TX3: 0.0 mm/h
Actual timestamp:2020-02-08 22:54:48; Timestamp at sending:2020-02-08 22:54:53
Sending Email.
An error has happened during receiving. Waiting 5 minutes and start over again

2020-02-08 23:00:49 Open serial interface COM14
2020-02-08 23:00:49 Successfully opened.
Sending Email.
An error has happened during receiving. Waiting 5 minutes and start over again
In error log :
Quote:2020-02-08 22:55:48 Error receiving data from serial port. Maybe connection was lost. Error code:15
2020-02-08 23:00:49 Error receiving data from serial port. Maybe connection was lost. Error code:15

Laurent
Reply
#26

So for the script itself everything seems to be fine. But you do not get an e-mail.
You checked the server stuff twice?

Moreover you most of the time have to setup your router to allow sending.
Reply
#27

I know it's a bit off topic because it's not a Python forum, but it can be simple for you to answer me
I made another script for sending mail and I have this as an error message:
Quote:  sendmail(str(receiver),'Wetterstation error',str(datetime.now().strftime("%d.%m.%Y %H:%M:%S")) + ' TEST')
File "Z:\Partage\Projets\Arduino\WD\Ori\WeatherDuino_Addon\sendmail.py", line 7, in sendmail
msg = MIMEText(content)
NameError: global name 'MIMEText' is not defined
Thanks

Laurent
Reply
#28

It seems that sendmail.py script don't know the variables defined in the main script.
I managed to have an email from script by changing the sensmail script :
Code:
 
#
# function to send a mail
#
def sendmail(recipient,subject,content):
  from email.mime.text import MIMEText
  import smtplib

  # generate a RFC 2822 message
  sender = 'Sender@mail.com'
  smtpserver = 'smtp.free.fr'

  msg = MIMEText(content)
  msg['From'] = sender
  msg['To'] = recipient
  msg['Subject'] = subject

  # open SMTP connection
  server = smtplib.SMTP(smtpserver)

  # start TLS encryption
  #if usetls:
    #server.starttls()

  # login with specified account
  #if smtpusername and smtppassword:
    #server.login(smtpusername,smtppassword)

  # send generated message
  server.sendmail(sender,recipient,msg.as_string())

  # close SMTP connection
  server.quit()
No sure it is a good solution Blush

Laurent
Reply
#29

Hi laurent,
I have to check this again. Probably I lost compatibility because I did not try this feature after releasing the last versions. Because I had no test system anymore.
I will check this annd release a fix if necesary. I think as long as your solution works it is fine .

Sorry for the inconvenience Blush
Reply
#30

Hi laurent,
I confirm - at some stage I outsourced this function into an extra file and not there are some variables unknown.
You can leave your solution as it is.

There will be an update in the next days.

Regards
Reply




Users browsing this thread: 1 Guest(s)