Go Down

Topic: [Anfänger] Bitte um Hilfe für Benachrichtigungssystem gMail und Co (Read 855 times) previous topic - next topic

Sylar

Hallo!

Also ich bin noch ein Anfänger und habe grad mal 2 kleine LED spielerein. Hab jetzt ein neues Ziel und ich interessiere mich für so Notifications System für gMail, Facebook, RSS, Skype etc. wäre halt für mich ein "Traum".

Hab schon etwas am gMail Notifications, was ja einige Tutorials im Web gibt, probiert. Leider funktioniert diese Notification nur auf Abruf. Was ja nicht so toll ist.

Also es sind 2 verschiedene und unabhängige Programme die über die gleiche Schnittstelle kommunizieren.

Als erstes mal der Code fürs Arduino
Code: [Select]

int outPin =11; // Output connected to PWM pin 11
int mail = 0; // mail count
int val; // Value read from the serial port
int pwm = 0; // Led PWM control
int myloop = 0;

void setup()
{
Serial.begin(9600);
Serial.flush();
}

void loop()
{
 if (Serial.available())
 {
   val = Serial.read();
   Serial.println(val);
   if (val == 0)
   {
     digitalWrite(outPin, LOW);
   }
   else
   {
       for(myloop = 1; myloop <= mail; myloop+=1)
       {
           for(pwm = 0 ; pwm <= 255; pwm+=5)
           {
               digitalWrite(outPin, pwm);
               delay(20);
           }
           for(pwm = 255; pwm >=0; pwm-=5)
           {
               digitalWrite(outPin, pwm);
               delay(20);
           }
   
       }
       delay(2000);
       // waits 2 seconds before beginning next loop
   }
   if (mail >= 10) digitalWrite(outPin, HIGH);
 }
}

Leider ist der nicht ganz richtig. Da die LED's an den PIN's nicht leuchten...

Hier ein VBA-Code für die GUI. Es gibt 3 Buttons: Reset, Mails abrufen, senden an Arduino und beenden Button.
Wenn ich den "Senden an Arduino" Button ankllicken, dann empfängt Arduino das Signal, aber er leitet das Signal leider nicht an die PIN's weiter, sondern nur die LED's auf den Board leuchtn. Glaubd ie RX LED...

Code: [Select]


Option Explicit
Dim Username As String
Dim Password As String


Private Sub CmdCheck_Click()
   CheckMail 'Oh, if i click "check mail", the app checks mail. Interesting!
   End Sub

Private Sub CmdExit_Click()
   If Serial.PortOpen Then Serial.PortOpen = False 'If we forgot open the serial.. we close it
   Log ("COM closed. Bye")
   Unload Me
   End
End Sub

Private Sub CmdReload_Click()
   LoadSettings 'Reload only re-load settings. Cool.
End Sub


Private Sub CheckMail()
On Error GoTo ERRR 'error handling. a must.
   Log ("Checking mail...")
   
   Dim STRTemp As String 'in "strtemp" we put the whole web page
   STRTemp = INet.OpenURL("https://" & Username & ":" & Password & "@mail.google.com/gmail/feed/atom")
   STRTemp = Right(STRTemp, Len(STRTemp) - InStr(1, LCase(STRTemp), "fullcount") - 9)
   'ok with this step we delete all the crappy things to the left of our mail count
   STRTemp = Left(STRTemp, InStr(1, STRTemp, "<") - 1)
   'and with this step we remove the right part, too. So, we've got only the mail count!
   Log ("New Mail(s): " & Int(STRTemp))
   If Int(STRTemp) > 9 Then STRTemp = ":" 'if we have more than 9 mails, we tell arduino to keep the led on
   SendToArduino (STRTemp) 'send to arduino the mail count!
Exit Sub
ERRR:
Log ("Error in CheckMail: " & Err.Description)
Resume Next
End Sub


Public Sub SendToArduino(Text As String)
On Error Resume Next
   With Serial
       .DTREnable = False 'oh, some settings.
       .RTSEnable = False 'this, too.
       .PortOpen = True 'we open the port...
       .Output = Text 'we send the string...
       .PortOpen = False 'and we close the port! Remember: always close the door.
   End With
End Sub

Private Sub CmdSend_Click()
On Error Resume Next
   SendToArduino (TxtSend.Text) 'with this great button we send the text to arduino.
   'oh arduino accepts 1 byte at time, so if you send "100" it's like sending "1", "0", "0".
   'so you will see "0" mails. ok?
   Log ("Sent: " & TxtSend.Text)
End Sub


Private Sub Form_Load()
   LoadSettings 'when Physical GMail Notifier v2 starts, it reads the settings!
End Sub

Public Sub LoadSettings()
On Error GoTo ERRR
   
   Log ("Loading settings...")
   
   Dim IniFile As String
   IniFile = App.Path          'c:\blabla
   If Right(App.Path, 1) <> "\" Then IniFile = IniFile & "\"   'c:\blabla\
   IniFile = IniFile & "PGN2.ini"    'c:\blabla\PGN2.ini
   Log ("INI: " & IniFile)
   
   PGN2Form.Visible = IIf(GetFromINI("general", "hidden", 0, IniFile) = 1, 0, 1)
   Log ("Hidden: " & Not (PGN2Form.Visible))
   'visible is the opposite of hidden. hidden is the opposite of visible.
       
   Timer.Enabled = False 'stop the timer!
   Timer.Interval = Int(GetFromINI("general", "interval", 60, IniFile)) * 1000 'set the timer!
   Timer.Enabled = True 'start the timer!
   Log ("Interval: " & Timer.Interval & "ms")
   
   If Serial.PortOpen Then Serial.PortOpen = False 'close and set the com port number
   Serial.CommPort = GetFromINI("general", "comport", 1, IniFile)
   Log ("COM: " & Serial.CommPort)
   
   Username = GetFromINI("general", "username", "", IniFile) 'need comments here?
   Log ("Username: " & Username)
   
   Password = GetFromINI("general", "password", "", IniFile)
   Log ("Password: [hidden]")

   Log ("...Settings loaded")

Exit Sub
ERRR:
Log ("Error in LoadSettings: " & Err.Description)
Resume Next
End Sub



Public Sub Log(Text As String)
On Error GoTo ERRR
   TxtDebug.Text = Text & vbCrLf & TxtDebug.Text
Exit Sub
ERRR:
MsgBox "Error while logging: " & Err.Description
Resume Next
End Sub

Private Sub Timer_Timer()
   CheckMail 'every time the timer tick, we check mail. oh, sorry. the app* checks mail.
End Sub


Code: [Select]

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

' Functions
Function GetFromINI(sSection As String, sKey As String, sDefault As String, sIniFile As String)
   Dim sBuffer As String, lRet As Long
   ' Fill String with 255 spaces
   sBuffer = String$(255, 0)
   ' Call DLL
   lRet = GetPrivateProfileString(sSection, sKey, "", sBuffer, Len(sBuffer), sIniFile)
   If lRet = 0 Then
       ' DLL failed, save default
       If sDefault <> "" Then AddToINI sSection, sKey, sDefault, sIniFile
       GetFromINI = sDefault
   Else
       ' DLL successful
       ' return string
       GetFromINI = Left(sBuffer, InStr(sBuffer, Chr(0)) - 1)
   End If
End Function

' Returns True if successful. If section does not
' exist it creates it.
Function AddToINI(sSection As String, sKey As String, sValue As String, sIniFile As String) As Boolean
   Dim lRet As Long
   ' Call DLL
   lRet = WritePrivateProfileString(sSection, sKey, sValue, sIniFile)
   AddToINI = (lRet)
End Function

Angeschlossen wird das Arduino UNO über USB Angeschlossen und nicht übers Ethernet

Auch wenn es schon eine Lösung gibt, mit Python, hab ich auch versucht, aber das ging bei mir leider gar nix. Kein blinken oder sonst was. Ich hoffe ihr könnts mir helfen oder eine andere Lösung. Wäre halt super, wenn es ein Dienst ist, der unauffällig unter windows läuft.

Danke

Go Up