-
Notifications
You must be signed in to change notification settings - Fork 4
/
imax_charger.ps1
70 lines (54 loc) · 1.57 KB
/
imax_charger.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
Joe Ostrander
Monitor SkyRC imax charger and notify when charging complete
2018.03.16
#>
# -------------------------------------------------------
#Note! Set these to your settings. Verify server, port, etc.
$comPort = "COM##"
$smtpServer = "smtp.gmail.com"
$EmailPort = 587
$EmailTo = "<your email address>"
$EmailFrom = "<your email address>"
$EmailUsername = "<your email username>"
$EmailPassword = "<your email password>"
$EmailSubject = "Battery charge done!"
# -------------------------------------------------------
$port= new-Object System.IO.Ports.SerialPort $comPort,57600,None,8,one
$port.Open()
$boolContinue = $true
while ($boolContinue)
{
$existing = $port.ReadExisting()
if ($existing)
{
if ($existing.Contains("NO RESPONSE"))
{
$boolContinue = $false
break;
}
else
{
$last_message += $existing
$last_message = $last_message.Substring($last_message.LastIndexOf("Status:"))
Clear-Host
Write-Host $last_message #-NoNewLine
}
$existing = ""
}
}
$port.Close()
Write-Host ""
Write-Host "DONE!"
$EmailBody = $last_message
$msg = New-Object Net.Mail.MailMessage
$msg.From = $EmailFrom
$msg.Sender = $EmailFrom #important if the sender is fake!
$msg.To.Add($EmailTo)
$msg.Subject = $EmailSubject
$msg.Body = $EmailBody
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Credentials = New-Object System.Net.NetworkCredential($EmailUsername,$EmailPassword)
$smtp.EnableSsl = $true
$smtp.Port = $EmailPort
$smtp.Send($msg)