-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo_p2gw_email.spin2
113 lines (84 loc) · 4.79 KB
/
demo_p2gw_email.spin2
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'' =================================================================================================
''
'' File....... demo_p2gw_email.spin2
'' Purpose.... Demonstrate sending an email message
'' Authors.... Stephen M Moraco
'' -- Copyright (c) 2022 Iron Sheep Productions, LLC
'' -- see below for terms of use
'' E-mail..... [email protected]
'' Started.... Jan 2022
'' Updated.... 11 Jan 2022
''
'' =================================================================================================
CON { timing }
CLK_FREQ = 200_000_000 ' system freq as a constant
_clkfreq = CLK_FREQ ' set system clock
CON { fixed io pins }
RX1 = 63 { I } ' programming / debug
TX1 = 62 { O }
SF_CS = 61 { O } ' serial flash
SF_SCK = 60 { O }
SF_SDO = 59 { O }
SF_SDI = 58 { I }
CON { RPi Gateway io pins }
RX_GW = 25 { I } ' Raspberry Pi (RPi) Gateway
TX_GW = 24 { O }
GW_BAUDRATE = 624_000 ' 624kb/s - allow P2 rx to keep up!
OBJ { Objects Used by this Object }
IoT_GW : "isp_rpi_iot_gw" ' serial I/O
strFmt : "isp_mem_strings" ' format to memory routines
DAT { our email and hardware ID strings }
p2HardwareID byte "P2 Edge - GWDemo1",0
emailTo byte "[email protected]",0
emailFrom byte "[email protected]",0
emailSubj byte "Hello from P2!",0
emailBody byte 0[1024] ' 1k bytes in which to format the email text
sampleStrVar byte "72.6 Degr F",0
sampleintVar byte 124
PUB main() | nLen
'' DEMO tell our RPi send an email for us
IoT_GW.startx(RX_GW, TX_GW, GW_BAUDRATE, IoT_GW.PU_15K)
' (one time) tell the RPi about how to identify this hardware
IoT_GW.identify(@p2HardwareID)
' ---------------------------------------------------------------
' build up our email message by appending strings into the buffer
' used to hold our email body text
' ---------------------------------------------------------------
' this first one assigns the current length value
nLen := strFmt.sFormatStr0(@emailBody, string("hi,\n"))
' from here on, we simply add to the current length with each new string append.
' (this allows us to know where to place next string in buffer)
nLen += strFmt.sFormatStr0(@BYTE[@emailBody][nlen], string(" This is being sent from the P2 via the RPi gateway\n"))
nLen += strFmt.sFormatStr0(@BYTE[@emailBody][nlen], string("\n")) ' blank line
nLen += strFmt.sFormatStr1(@BYTE[@emailBody][nlen], string(" Sample Temperature reading: %s\n"), @sampleStrVar)
nLen += strFmt.sFormatStr1(@BYTE[@emailBody][nlen], string(" Sample data value: %d\n"), sampleintVar)
nLen += strFmt.sFormatStr0(@BYTE[@emailBody][nlen], string("\n")) ' blank line
nLen += strFmt.sFormatStr0(@BYTE[@emailBody][nlen], string("Regards,\n"))
nLen += strFmt.sFormatStr0(@BYTE[@emailBody][nlen], string("Your friendly P2!\n"))
' Tell the RPi to send an email message
IoT_GW.sendEmail(@emailTo, @emailFrom, @emailSubj, @emailBody)
debug("*** DONE ***")
' terminate communication with our gateway RPi
IoT_GW.stop()
CON { license }
{{
-------------------------------------------------------------------------------------------------
MIT License
Copyright (c) 2022 Iron Sheep Productions, LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=================================================================================================
}}