1 00:00:04,960 --> 00:00:20,000 [Music] 2 00:00:20,320 --> 00:00:27,560 hello welcome back everyone thank you 3 00:00:23,519 --> 00:00:31,360 for joining us again after lunch now uh 4 00:00:27,560 --> 00:00:33,800 AJ Fisher is going to talk to us about 5 00:00:31,360 --> 00:00:37,239 ridiculously exciting things I'm really 6 00:00:33,800 --> 00:00:41,039 Keen AJ is uh a senior analytical 7 00:00:37,239 --> 00:00:42,840 engineer at Synergy uh in Perth um they 8 00:00:41,039 --> 00:00:45,399 literally keep the lights on doing all 9 00:00:42,840 --> 00:00:48,239 sorts of electrical stuff um and you are 10 00:00:45,399 --> 00:00:49,760 a self-described DAT holic uh which I 11 00:00:48,239 --> 00:00:53,840 think a few of us in the room perhaps 12 00:00:49,760 --> 00:00:56,600 can relate to AJ thank you very 13 00:00:53,840 --> 00:00:59,120 much and uh thank you so much Nikki 14 00:00:56,600 --> 00:01:03,120 really appreciate that welcome everyone 15 00:00:59,120 --> 00:01:05,720 to build your own iot fun with python 16 00:01:03,120 --> 00:01:08,560 and Raspberry Pi thank you so much for 17 00:01:05,720 --> 00:01:11,080 having me today I am incredibly excited 18 00:01:08,560 --> 00:01:13,040 to be here and uh I hope we can have 19 00:01:11,080 --> 00:01:16,000 some fun 20 00:01:13,040 --> 00:01:18,479 so uh a little bit about what we'll be 21 00:01:16,000 --> 00:01:21,360 talking about today um so we'll start 22 00:01:18,479 --> 00:01:24,840 the talk with an introduction to the 23 00:01:21,360 --> 00:01:27,320 growing importance of solar energy in 24 00:01:24,840 --> 00:01:31,079 Australia uh then we are going to build 25 00:01:27,320 --> 00:01:33,479 out a live uh data system meaning we are 26 00:01:31,079 --> 00:01:35,960 going to be collecting data every single 27 00:01:33,479 --> 00:01:40,280 one second and working with that data in 28 00:01:35,960 --> 00:01:41,479 the internet or in the cloud um so 29 00:01:40,280 --> 00:01:44,759 before we do that though we'll need to 30 00:01:41,479 --> 00:01:46,200 talk about the hardware required um and 31 00:01:44,759 --> 00:01:48,119 then at the end of the talk we'll talk 32 00:01:46,200 --> 00:01:52,439 about how we can build out this like 33 00:01:48,119 --> 00:01:54,920 live data pipeline into a full uh iot 34 00:01:52,439 --> 00:01:57,759 application so the focus of this talk is 35 00:01:54,920 --> 00:02:01,520 not on building an entire application 36 00:01:57,759 --> 00:02:05,360 it's about a live uh data pipeline that 37 00:02:01,520 --> 00:02:07,320 you can do everything uh in using python 38 00:02:05,360 --> 00:02:10,599 uh and then at the end we'll wrap things 39 00:02:07,320 --> 00:02:11,680 up and hopefully have about five minutes 40 00:02:10,599 --> 00:02:13,200 uh for 41 00:02:11,680 --> 00:02:15,720 questions 42 00:02:13,200 --> 00:02:18,959 so I'll start with the question why 43 00:02:15,720 --> 00:02:20,640 should you care well why should you care 44 00:02:18,959 --> 00:02:22,879 I'd like to talk a little bit about the 45 00:02:20,640 --> 00:02:26,519 situation in the city I'm living in at 46 00:02:22,879 --> 00:02:29,680 the moment uh in Perth uh over in West 47 00:02:26,519 --> 00:02:32,000 Australia and it is currently estimated 48 00:02:29,680 --> 00:02:35,640 that that one in three homes in the 49 00:02:32,000 --> 00:02:38,080 Perth metro area currently have solar PV 50 00:02:35,640 --> 00:02:41,519 uh installed on the roofs of their homes 51 00:02:38,080 --> 00:02:44,280 which is amazing and just to give you a 52 00:02:41,519 --> 00:02:48,080 figure for how much uh solar 53 00:02:44,280 --> 00:02:51,040 energy uh was generated in calendar year 54 00:02:48,080 --> 00:02:54,159 2023 uh doing uh taking some numbers 55 00:02:51,040 --> 00:02:56,760 from the market operator and uh Amo and 56 00:02:54,159 --> 00:02:59,959 running a small calculation on that uh 57 00:02:56,760 --> 00:03:03,080 comes out to a little bit over 3,000 uh 58 00:02:59,959 --> 00:03:06,080 gigawatt hours now you don't need to 59 00:03:03,080 --> 00:03:08,920 know what a gigawatt hour is but I want 60 00:03:06,080 --> 00:03:11,720 to compare that to a traditional coal 61 00:03:08,920 --> 00:03:17,360 plant and here I'm going to compare that 62 00:03:11,720 --> 00:03:19,560 to the muja power station um in uh coli 63 00:03:17,360 --> 00:03:22,440 uh West Australia and again just looking 64 00:03:19,560 --> 00:03:26,959 at one year of generation and that comes 65 00:03:22,440 --> 00:03:30,519 out to about 3,000 gwatt hours of 66 00:03:26,959 --> 00:03:33,159 electricity so how amazing is that that 67 00:03:30,519 --> 00:03:35,640 already today there is enough rooftop 68 00:03:33,159 --> 00:03:38,439 solar in the Perth metro area to 69 00:03:35,640 --> 00:03:40,680 generate as much electricity as a coal 70 00:03:38,439 --> 00:03:44,280 plant on an annual basis that is 71 00:03:40,680 --> 00:03:47,920 absolutely bloody awesome and the market 72 00:03:44,280 --> 00:03:50,560 operator Amo is predicting that the 73 00:03:47,920 --> 00:03:52,760 amount of installed solar capacity is 74 00:03:50,560 --> 00:03:55,680 actually going to overd double in the 75 00:03:52,760 --> 00:03:59,239 next 10 years to 76 00:03:55,680 --> 00:04:01,720 2034 and with all this uh installed uh 77 00:03:59,239 --> 00:04:04,920 rooftop solar you can imagine there's a 78 00:04:01,720 --> 00:04:06,519 lot of data involved and uh the 79 00:04:04,920 --> 00:04:09,200 government of West Australia is 80 00:04:06,519 --> 00:04:13,200 investing in uh looking at how we can 81 00:04:09,200 --> 00:04:16,199 best um invest in these uh rooftop solar 82 00:04:13,200 --> 00:04:20,079 panels and uh utilize that in our 83 00:04:16,199 --> 00:04:22,040 Electrical uh grid so in terms of what 84 00:04:20,079 --> 00:04:23,840 we're going to be building today we're 85 00:04:22,040 --> 00:04:27,320 essentially going to be building a live 86 00:04:23,840 --> 00:04:29,720 data system for a microscale version of 87 00:04:27,320 --> 00:04:32,479 the following where we can have solar 88 00:04:29,720 --> 00:04:36,560 panels all over Australia whether in 89 00:04:32,479 --> 00:04:39,440 Perth or Sydney or Brisbane or whatever 90 00:04:36,560 --> 00:04:41,039 City you live in and we can also have 91 00:04:39,440 --> 00:04:44,479 multiple data 92 00:04:41,039 --> 00:04:46,560 consumers so here uh just using a madeup 93 00:04:44,479 --> 00:04:49,479 example of like a central Melbourne 94 00:04:46,560 --> 00:04:51,840 Control Center and uh perhaps our friend 95 00:04:49,479 --> 00:04:54,919 Alice uh up in Darwin who's going to be 96 00:04:51,840 --> 00:04:57,479 using uh this data as well and we're 97 00:04:54,919 --> 00:05:00,199 going to be using a uh very special and 98 00:04:57,479 --> 00:05:03,080 very exciting piece of software to help 99 00:05:00,199 --> 00:05:05,160 facilitate um the movement of this data 100 00:05:03,080 --> 00:05:08,400 to our Downstream consumers and that 101 00:05:05,160 --> 00:05:11,600 software is called Apache 102 00:05:08,400 --> 00:05:13,880 Kafka so we're going to be building a 103 00:05:11,600 --> 00:05:16,080 data pipeline to move the data from the 104 00:05:13,880 --> 00:05:18,720 data producers to the data 105 00:05:16,080 --> 00:05:21,080 consumers and uh a couple messages I 106 00:05:18,720 --> 00:05:23,880 want to share with the audience so 107 00:05:21,080 --> 00:05:27,080 Hardware is not typically seen as being 108 00:05:23,880 --> 00:05:29,400 in the python realm like people uh 109 00:05:27,080 --> 00:05:30,360 typically assume that you need to know C 110 00:05:29,400 --> 00:05:33,560 or 111 00:05:30,360 --> 00:05:35,560 C++ uh to work with Hardware but I'm 112 00:05:33,560 --> 00:05:38,720 here today to tell you that with a 113 00:05:35,560 --> 00:05:41,319 Raspberry Pi you can do this All in 114 00:05:38,720 --> 00:05:43,759 Python and after the talk today I 115 00:05:41,319 --> 00:05:46,880 encourage everyone in the room to uh go 116 00:05:43,759 --> 00:05:50,240 out and try to build their own iot and 117 00:05:46,880 --> 00:05:52,560 or Raspberry Pi application so rather 118 00:05:50,240 --> 00:05:55,160 than doing a deep dive into any one 119 00:05:52,560 --> 00:05:58,160 topic today uh we'll be looking at a 120 00:05:55,160 --> 00:05:59,880 whole uh range of topics um some of 121 00:05:58,160 --> 00:06:02,720 which I hope will interest you in and 122 00:05:59,880 --> 00:06:06,720 maybe you'll uh go out after the talk 123 00:06:02,720 --> 00:06:10,160 and um learn a bit more but most 124 00:06:06,720 --> 00:06:12,560 importantly and above all else uh the 125 00:06:10,160 --> 00:06:15,280 one thing I want you uh to walk away 126 00:06:12,560 --> 00:06:18,639 with after the talk today is being able 127 00:06:15,280 --> 00:06:21,960 to go home to collect your very own 128 00:06:18,639 --> 00:06:21,960 Raspberry Pi 129 00:06:23,639 --> 00:06:30,720 data okay let's talk Hardware so with 130 00:06:28,080 --> 00:06:33,919 any iot application you first require 131 00:06:30,720 --> 00:06:37,880 some kind of sensor and the sensor we're 132 00:06:33,919 --> 00:06:41,360 going to use today is a little mini 1.5 133 00:06:37,880 --> 00:06:44,000 volt solar panel so this is essentially 134 00:06:41,360 --> 00:06:46,800 a light sensor but it's going to tell us 135 00:06:44,000 --> 00:06:49,440 about the light in the room with voltage 136 00:06:46,800 --> 00:06:51,319 and that panel costs roughly about $20 137 00:06:49,440 --> 00:06:54,319 at your local electronic 138 00:06:51,319 --> 00:06:56,520 shop and the next piece of equipment 139 00:06:54,319 --> 00:06:58,919 that we're going to use is this thing 140 00:06:56,520 --> 00:07:00,800 called an analog to digital converter or 141 00:06:58,919 --> 00:07:03,919 ad 142 00:07:00,800 --> 00:07:06,199 um and what that's going to do is uh the 143 00:07:03,919 --> 00:07:09,919 little mini solar panel produces an 144 00:07:06,199 --> 00:07:12,319 analog signal and that nice waveform 145 00:07:09,919 --> 00:07:14,599 that you can see on the left side of the 146 00:07:12,319 --> 00:07:17,639 ADC and what this little piece of 147 00:07:14,599 --> 00:07:19,280 equipment is going to do this little ADC 148 00:07:17,639 --> 00:07:21,680 this is going to translate that signal 149 00:07:19,280 --> 00:07:22,960 into a digital signal that can be used 150 00:07:21,680 --> 00:07:26,560 by a 151 00:07:22,960 --> 00:07:29,879 computer and of course uh to introduce 152 00:07:26,560 --> 00:07:33,080 the rockar of this project we have our 153 00:07:29,879 --> 00:07:37,960 Raspberry Pi uh which is a single board 154 00:07:33,080 --> 00:07:41,000 computer here acting as a local server 155 00:07:37,960 --> 00:07:42,720 now uh the Raspberry Pi um comes in at 156 00:07:41,000 --> 00:07:45,520 about 157 00:07:42,720 --> 00:07:48,560 $133 um understandably that may not be 158 00:07:45,520 --> 00:07:50,479 in everyone's budget uh if not I do 159 00:07:48,560 --> 00:07:54,120 encourage you also to look at the 160 00:07:50,479 --> 00:07:56,759 Raspberry Pi Pico uh which comes out at 161 00:07:54,120 --> 00:07:58,639 $6 now with the Raspberry Pi Pico you 162 00:07:56,759 --> 00:08:02,039 just need to program that in micro 163 00:07:58,639 --> 00:08:03,919 python rather than then um just base uh 164 00:08:02,039 --> 00:08:05,000 python which we'll use with the 165 00:08:03,919 --> 00:08:07,879 Raspberry 166 00:08:05,000 --> 00:08:09,960 Pi and fully set up it looks a little 167 00:08:07,879 --> 00:08:12,199 bit something like this starting at the 168 00:08:09,960 --> 00:08:17,000 bottom of the screen we have our little 169 00:08:12,199 --> 00:08:19,680 mini uh solar panel connected to our ADC 170 00:08:17,000 --> 00:08:24,319 and then that is being read into the 171 00:08:19,680 --> 00:08:26,159 i2c uh pins on the Raspberry Pi so the 172 00:08:24,319 --> 00:08:28,599 really fun thing about Hardware is we 173 00:08:26,159 --> 00:08:31,159 can actually do a bit of a showand tell 174 00:08:28,599 --> 00:08:34,360 so we will now uh pass around these 175 00:08:31,159 --> 00:08:36,839 three items and uh you can take a look 176 00:08:34,360 --> 00:08:38,039 um so we'll start with the Raspberry Pi 177 00:08:36,839 --> 00:08:39,959 and the pinout 178 00:08:38,039 --> 00:08:42,959 configuration and uh we also have the 179 00:08:39,959 --> 00:08:47,800 mini solar panel and 180 00:08:42,959 --> 00:08:50,720 ADC all right so we have our Hardware 181 00:08:47,800 --> 00:08:54,320 set up and the first thing we need to do 182 00:08:50,720 --> 00:08:56,800 now is we need to read a voltage value 183 00:08:54,320 --> 00:08:59,480 from the ADC and the solar panel into 184 00:08:56,800 --> 00:09:01,399 our Raspberry Pi and here you might be 185 00:08:59,480 --> 00:09:05,079 Be Wondering okay is it time to bust out 186 00:09:01,399 --> 00:09:08,279 the KRC book um it's a great book a 187 00:09:05,079 --> 00:09:11,800 great language but the answer is nope 188 00:09:08,279 --> 00:09:14,560 you can use pure python so the amazing 189 00:09:11,800 --> 00:09:17,320 thing here is that the uh manufacturer 190 00:09:14,560 --> 00:09:20,200 of the ADC Ada fruit has actually 191 00:09:17,320 --> 00:09:22,360 produced their own uh python library 192 00:09:20,200 --> 00:09:26,839 that allows us to read values into the 193 00:09:22,360 --> 00:09:31,000 pi and I want to give you a number that 194 00:09:26,839 --> 00:09:33,519 number being nine so with just nine 195 00:09:31,000 --> 00:09:35,880 lines of code excluding our import 196 00:09:33,519 --> 00:09:38,920 statements we can start reading values 197 00:09:35,880 --> 00:09:40,440 into the pi in a loop even less is 198 00:09:38,920 --> 00:09:42,640 required if you just want to read a 199 00:09:40,440 --> 00:09:44,519 single value but we'll be reading them 200 00:09:42,640 --> 00:09:47,560 in a loop and getting values every 201 00:09:44,519 --> 00:09:49,760 single one second so just to show you a 202 00:09:47,560 --> 00:09:51,560 little bit of what that looks like uh I 203 00:09:49,760 --> 00:09:54,120 have a conceptual map on the left side 204 00:09:51,560 --> 00:09:57,160 of the screen and the code on the right 205 00:09:54,120 --> 00:10:00,200 side of the screen so what we need to do 206 00:09:57,160 --> 00:10:02,959 is we'll be importing our libraries for 207 00:10:00,200 --> 00:10:06,320 uh Adafruit and then a couple libraries 208 00:10:02,959 --> 00:10:09,079 uh this board in bus IO to help us uh 209 00:10:06,320 --> 00:10:13,640 set up the i2c and uh 210 00:10:09,079 --> 00:10:16,680 ADC so um with that we now have three 211 00:10:13,640 --> 00:10:19,800 lines of code and what these three lines 212 00:10:16,680 --> 00:10:21,279 of code are designed to do are um 213 00:10:19,800 --> 00:10:23,880 they're going to help us set up the i2c 214 00:10:21,279 --> 00:10:26,680 bus and the ADC but really what we want 215 00:10:23,880 --> 00:10:29,920 to get out of this is we want to get uh 216 00:10:26,680 --> 00:10:31,880 the channel on the ADC so essenti 217 00:10:29,920 --> 00:10:35,480 just asking the ADC where are we going 218 00:10:31,880 --> 00:10:38,120 to read values from and um this can be a 219 00:10:35,480 --> 00:10:40,720 little bit tricky uh especially um doing 220 00:10:38,120 --> 00:10:43,200 this uh for the first time so I do 221 00:10:40,720 --> 00:10:45,800 recommend uh looking at the Adafruit uh 222 00:10:43,200 --> 00:10:48,240 GitHub where they have all of this code 223 00:10:45,800 --> 00:10:51,440 uh ready to go um and you can start 224 00:10:48,240 --> 00:10:54,279 playing with that um but then once we 225 00:10:51,440 --> 00:10:56,959 have the uh a ADC Channel all set up 226 00:10:54,279 --> 00:11:00,399 ready to go we can then just set up uh 227 00:10:56,959 --> 00:11:03,519 an infinite Loop and uh just read those 228 00:11:00,399 --> 00:11:06,360 values using the uh voltage attribute of 229 00:11:03,519 --> 00:11:09,120 the channel and then we have a 1second 230 00:11:06,360 --> 00:11:10,720 sleep statement um it'll read in a lot 231 00:11:09,120 --> 00:11:13,240 quicker than that if you don't put that 232 00:11:10,720 --> 00:11:15,240 in but we only want to get values every 233 00:11:13,240 --> 00:11:17,639 single one 234 00:11:15,240 --> 00:11:18,639 second and then later we can clean it up 235 00:11:17,639 --> 00:11:22,480 a 236 00:11:18,639 --> 00:11:24,560 bit so that's great but the next 237 00:11:22,480 --> 00:11:26,279 question is what does that data actually 238 00:11:24,560 --> 00:11:29,800 look like we have some voltage values 239 00:11:26,279 --> 00:11:33,120 coming in um and there's two ways that 240 00:11:29,800 --> 00:11:36,279 you can uh work with this data and uh 241 00:11:33,120 --> 00:11:39,040 eventually send this to the Internet so 242 00:11:36,279 --> 00:11:41,839 the easier way is to just have a single 243 00:11:39,040 --> 00:11:45,120 decimal or float value and keeping in 244 00:11:41,839 --> 00:11:47,440 mind that these are timestamped values 245 00:11:45,120 --> 00:11:49,920 so each value that you get is going to 246 00:11:47,440 --> 00:11:52,720 be associated with a certain point in 247 00:11:49,920 --> 00:11:54,519 time and that ends up looking a bit 248 00:11:52,720 --> 00:11:56,800 something like this at the end of the 249 00:11:54,519 --> 00:11:58,800 day whereas you have the time stamp and 250 00:11:56,800 --> 00:12:01,320 then you just have your single number uh 251 00:11:58,800 --> 00:12:03,200 for the voltage and uh just wanted to 252 00:12:01,320 --> 00:12:07,040 mention one thing as well uh on that 253 00:12:03,200 --> 00:12:08,959 mini solar panel uh 1.5 volts so at the 254 00:12:07,040 --> 00:12:11,279 uh peak of the day when it's very sunny 255 00:12:08,959 --> 00:12:15,120 we expect to see 1.5 volts when it's 256 00:12:11,279 --> 00:12:17,560 dark outside uh expect to see zero volts 257 00:12:15,120 --> 00:12:21,279 um but another way that we um see this 258 00:12:17,560 --> 00:12:24,920 data being um flown around in real life 259 00:12:21,279 --> 00:12:26,760 is as Json messages so if you're new to 260 00:12:24,920 --> 00:12:29,240 uh python you can kind of imagine this 261 00:12:26,760 --> 00:12:30,880 as like a little dictionary but what 262 00:12:29,240 --> 00:12:33,160 I've done here is we're measuring the 263 00:12:30,880 --> 00:12:35,000 voltage every 1 second and then I've 264 00:12:33,160 --> 00:12:38,800 padded this with some additional dummy 265 00:12:35,000 --> 00:12:40,920 data to create these uh Json messages 266 00:12:38,800 --> 00:12:43,279 and what that looks like then is instead 267 00:12:40,920 --> 00:12:46,800 of every 1 second we send a decimal 268 00:12:43,279 --> 00:12:49,639 number we then send uh these little 269 00:12:46,800 --> 00:12:52,839 messages um every one 270 00:12:49,639 --> 00:12:54,160 second okay now we need to talk about 271 00:12:52,839 --> 00:12:58,360 Apache 272 00:12:54,160 --> 00:13:00,279 Kafka so Apache Kafka is a cloud-based 273 00:12:58,360 --> 00:13:03,320 uh data streaming platform that's going 274 00:13:00,279 --> 00:13:07,519 to help us handle many uh data producers 275 00:13:03,320 --> 00:13:09,279 and many data consumers in livetime so 276 00:13:07,519 --> 00:13:12,800 um there there will be a little bit of 277 00:13:09,279 --> 00:13:14,720 latency um over that uh Kafka platform 278 00:13:12,800 --> 00:13:17,440 but essentially those Downstream 279 00:13:14,720 --> 00:13:21,160 consumers should be able to uh use that 280 00:13:17,440 --> 00:13:24,279 data in nearly real time as that data is 281 00:13:21,160 --> 00:13:27,000 produced so just to give a little bit of 282 00:13:24,279 --> 00:13:28,560 an analogy here I want to uh I want you 283 00:13:27,000 --> 00:13:32,040 to pretend that these messages being 284 00:13:28,560 --> 00:13:34,920 sent are are like male and I'm going to 285 00:13:32,040 --> 00:13:36,279 simplify Apache Kafka a little bit here 286 00:13:34,920 --> 00:13:39,000 but you can kind of sort of think of 287 00:13:36,279 --> 00:13:41,320 Apache Kafka is like a big cloud-based 288 00:13:39,000 --> 00:13:44,079 conveyor belt that's going to help get 289 00:13:41,320 --> 00:13:46,320 the the data from our local machines 290 00:13:44,079 --> 00:13:49,519 wherever they are in Australia to our 291 00:13:46,320 --> 00:13:50,600 Downstream apps um in different places 292 00:13:49,519 --> 00:13:53,959 in 293 00:13:50,600 --> 00:13:57,279 Australia now unfortunately we can't 294 00:13:53,959 --> 00:14:02,639 just teleport our uh mail from our home 295 00:13:57,279 --> 00:14:04,959 to the uh local uh oost uh Warehouse so 296 00:14:02,639 --> 00:14:06,800 I want to introduce another term here on 297 00:14:04,959 --> 00:14:10,160 how we're going to do that we need a 298 00:14:06,800 --> 00:14:11,560 special client called a producer and the 299 00:14:10,160 --> 00:14:13,399 producers are essentially the mail 300 00:14:11,560 --> 00:14:15,560 trucks that are going to operate every 301 00:14:13,399 --> 00:14:19,000 single one second delivering those 302 00:14:15,560 --> 00:14:22,399 messages uh to that uh Central data 303 00:14:19,000 --> 00:14:25,199 platform now we need a way as well to uh 304 00:14:22,399 --> 00:14:28,279 get the data from Apache Kafka to the 305 00:14:25,199 --> 00:14:30,079 downstream apps and you might assume 306 00:14:28,279 --> 00:14:33,160 again that the these are going to be 307 00:14:30,079 --> 00:14:35,279 more trucks essentially delivering that 308 00:14:33,160 --> 00:14:39,120 mail but it's a little bit different in 309 00:14:35,279 --> 00:14:41,680 Apache Kafka and rather than trucks uh 310 00:14:39,120 --> 00:14:44,079 the analogy I'll use here is more people 311 00:14:41,680 --> 00:14:46,480 with barcode scanners so it's the same 312 00:14:44,079 --> 00:14:48,800 messages but people going along walking 313 00:14:46,480 --> 00:14:52,560 along those messages and scanning the 314 00:14:48,800 --> 00:14:55,040 messages um as they come in but not 315 00:14:52,560 --> 00:14:57,560 really uh delivering those not taking 316 00:14:55,040 --> 00:14:59,560 them out just scanning them um and 317 00:14:57,560 --> 00:15:00,440 leaving them in 318 00:14:59,560 --> 00:15:03,920 as you 319 00:15:00,440 --> 00:15:05,880 go now in terms of actual implementation 320 00:15:03,920 --> 00:15:08,000 I do want to talk about uh one of the 321 00:15:05,880 --> 00:15:11,000 elephants in the room in the software 322 00:15:08,000 --> 00:15:14,120 Community which is the cloud can 323 00:15:11,000 --> 00:15:17,320 sometimes be a bit uh overwhelming uh 324 00:15:14,120 --> 00:15:21,040 especially for beginners so uh with this 325 00:15:17,320 --> 00:15:23,160 project I wanted to choose a service um 326 00:15:21,040 --> 00:15:26,079 that was a bit more user friendly 327 00:15:23,160 --> 00:15:29,079 perhaps and as well uh was a bit on the 328 00:15:26,079 --> 00:15:31,480 more affordable side so to that point I 329 00:15:29,079 --> 00:15:34,680 choosen uh sorry chosen uh confluent 330 00:15:31,480 --> 00:15:38,399 Cloud um for this so rather than uh 331 00:15:34,680 --> 00:15:40,560 needing to um set up some comp complex 332 00:15:38,399 --> 00:15:43,199 uh infrastructure you just go to the 333 00:15:40,560 --> 00:15:44,959 website they have a 30-day free trial 334 00:15:43,199 --> 00:15:47,560 and then you can set up a server by 335 00:15:44,959 --> 00:15:49,680 following these guided forms so it it'll 336 00:15:47,560 --> 00:15:52,000 ask you some questions you fill in your 337 00:15:49,680 --> 00:15:55,199 uh information and it'll set up the 338 00:15:52,000 --> 00:15:58,040 server sorry it'll set up the uh Kafka 339 00:15:55,199 --> 00:16:00,440 cluster um for you and really what we 340 00:15:58,040 --> 00:16:02,360 want to get out of this is this uh 341 00:16:00,440 --> 00:16:05,079 configuration dictionary that we can 342 00:16:02,360 --> 00:16:07,360 give to our uh Python program so 343 00:16:05,079 --> 00:16:09,959 essentially helping to tell the program 344 00:16:07,360 --> 00:16:12,440 where is this data system located in the 345 00:16:09,959 --> 00:16:15,440 internet it'll give us some credentials 346 00:16:12,440 --> 00:16:19,199 so not just everyone can access our data 347 00:16:15,440 --> 00:16:22,279 and uh we can use that moving forward so 348 00:16:19,199 --> 00:16:24,560 here's what we have so far and again we 349 00:16:22,279 --> 00:16:27,160 need to think about that producer so the 350 00:16:24,560 --> 00:16:30,040 trucks delivering that mail from our 351 00:16:27,160 --> 00:16:33,199 local machine and then we also o need a 352 00:16:30,040 --> 00:16:35,880 uh Downstream consumer and uh another 353 00:16:33,199 --> 00:16:38,880 reason I really like confluent is uh 354 00:16:35,880 --> 00:16:42,440 they actually have a free uh course on 355 00:16:38,880 --> 00:16:45,199 their website um so this Apache Kafka 356 00:16:42,440 --> 00:16:47,759 for python developers course and in 357 00:16:45,199 --> 00:16:50,319 particular they have uh provided an an 358 00:16:47,759 --> 00:16:53,160 incredibly convenient Library the uh 359 00:16:50,319 --> 00:16:55,279 confluent kofka python Library which 360 00:16:53,160 --> 00:16:57,519 we're going to be using for the uh rest 361 00:16:55,279 --> 00:16:59,800 of the presentation here and this is 362 00:16:57,519 --> 00:17:01,360 going to act as the client um again to 363 00:16:59,800 --> 00:17:03,560 deliver those 364 00:17:01,360 --> 00:17:05,439 messages so just wanted to show you a 365 00:17:03,560 --> 00:17:07,720 bit of the code here just keeping in 366 00:17:05,439 --> 00:17:11,079 mind that um I've only shown the main 367 00:17:07,720 --> 00:17:14,559 ideas um not all of the helper functions 368 00:17:11,079 --> 00:17:16,600 um and all that but essentially what 369 00:17:14,559 --> 00:17:18,799 that code is going to look like is we're 370 00:17:16,600 --> 00:17:21,199 going to be using the confluent Kafka 371 00:17:18,799 --> 00:17:24,559 library and we're going to be using the 372 00:17:21,199 --> 00:17:26,439 producer class from there what we need 373 00:17:24,559 --> 00:17:29,679 to do is we're going to feed that 374 00:17:26,439 --> 00:17:31,720 producer uh the dictionary that setup 375 00:17:29,679 --> 00:17:34,080 dictionary that we got in the previous 376 00:17:31,720 --> 00:17:36,240 step and as well we're going to tell it 377 00:17:34,080 --> 00:17:39,000 a little bit more information where to 378 00:17:36,240 --> 00:17:40,960 look in that uh Kafka data system and 379 00:17:39,000 --> 00:17:44,200 where to put that data so we're going to 380 00:17:40,960 --> 00:17:45,320 give it this thing called a topic and a 381 00:17:44,200 --> 00:17:49,480 uh and a 382 00:17:45,320 --> 00:17:52,360 key so from there we get our ADC uh set 383 00:17:49,480 --> 00:17:54,520 up and ready to go and essentially we 384 00:17:52,360 --> 00:17:57,559 modify that infinite Loop that we had 385 00:17:54,520 --> 00:18:00,080 before reading values from the Raspberry 386 00:17:57,559 --> 00:18:02,919 Pi so we're still reading values from 387 00:18:00,080 --> 00:18:05,520 the pi in a loop but we add a couple 388 00:18:02,919 --> 00:18:07,360 additional steps and one of the most 389 00:18:05,520 --> 00:18:11,000 important things here is we first have 390 00:18:07,360 --> 00:18:13,919 to turn the data into bytes before we uh 391 00:18:11,000 --> 00:18:17,240 send that to the internet now uh the 392 00:18:13,919 --> 00:18:18,640 confluent Kafka Library does have some 393 00:18:17,240 --> 00:18:21,520 uh convenience functions that you can 394 00:18:18,640 --> 00:18:24,280 use for that here I've used the struct 395 00:18:21,520 --> 00:18:26,640 uh. PAC function um just I was having a 396 00:18:24,280 --> 00:18:29,120 bit of trouble getting uh the built-in 397 00:18:26,640 --> 00:18:31,080 function working on the pi but it still 398 00:18:29,120 --> 00:18:33,679 does the same thing it converts it into 399 00:18:31,080 --> 00:18:36,559 bytes and then we use the produce method 400 00:18:33,679 --> 00:18:38,960 on that uh producer instance and that 401 00:18:36,559 --> 00:18:42,720 will uh help us deliver those messages 402 00:18:38,960 --> 00:18:44,760 to our Kafka cluster and again we'll uh 403 00:18:42,720 --> 00:18:47,120 have it sleep for one second uh in 404 00:18:44,760 --> 00:18:51,840 between sending things to the 405 00:18:47,120 --> 00:18:54,520 cloud awesome so once we have that data 406 00:18:51,840 --> 00:18:56,799 um in our Kafka data system we can now 407 00:18:54,520 --> 00:18:59,080 do uh we can now interact with that data 408 00:18:56,799 --> 00:19:01,679 in two ways we can interact with that 409 00:18:59,080 --> 00:19:06,159 data in real time or we can save that 410 00:19:01,679 --> 00:19:07,840 data for a uh a longer term analysis so 411 00:19:06,159 --> 00:19:10,120 say for example we can come back in a 412 00:19:07,840 --> 00:19:12,880 week and we can analyze that whole week 413 00:19:10,120 --> 00:19:15,880 worth of data so just wanted to mention 414 00:19:12,880 --> 00:19:18,919 another uh nice feature of using this uh 415 00:19:15,880 --> 00:19:21,720 confluent Cloud which is they have uh no 416 00:19:18,919 --> 00:19:23,520 code connectors through Kafka connect 417 00:19:21,720 --> 00:19:26,159 and what I mean by that is you can 418 00:19:23,520 --> 00:19:28,120 actually sync your data um from that 419 00:19:26,159 --> 00:19:29,600 Kafka cluster into your favorite 420 00:19:28,120 --> 00:19:32,080 databases 421 00:19:29,600 --> 00:19:35,200 um just by configuring those databases 422 00:19:32,080 --> 00:19:38,799 and uh telling it where to go no python 423 00:19:35,200 --> 00:19:41,640 code uh required for that so here I've 424 00:19:38,799 --> 00:19:43,799 just used elastic and uh snowflake uh 425 00:19:41,640 --> 00:19:46,080 just the easiest two to set up but you 426 00:19:43,799 --> 00:19:49,000 could also use uh I believe other 427 00:19:46,080 --> 00:19:53,520 options as well such as uh mongod DB 428 00:19:49,000 --> 00:19:55,360 shout out to our Platinum sponsor so um 429 00:19:53,520 --> 00:19:59,280 so you can sync that data into an actual 430 00:19:55,360 --> 00:20:01,480 database analyze it later on but uh we 431 00:19:59,280 --> 00:20:04,000 still want to analyze that data in real 432 00:20:01,480 --> 00:20:05,880 time as well we want that data for our 433 00:20:04,000 --> 00:20:08,960 Central Melbourne Control 434 00:20:05,880 --> 00:20:11,440 Center and we're going to do that with 435 00:20:08,960 --> 00:20:13,880 uh this thing called a Kafka consumer 436 00:20:11,440 --> 00:20:15,520 again going back to that male analogy 437 00:20:13,880 --> 00:20:18,320 the person with the barcode scanner 438 00:20:15,520 --> 00:20:21,559 walking along and um and getting the 439 00:20:18,320 --> 00:20:24,600 data out of those um objects and again 440 00:20:21,559 --> 00:20:28,080 remembering that the data in uh Kafka is 441 00:20:24,600 --> 00:20:30,039 coming in as bytes so we need to uh work 442 00:20:28,080 --> 00:20:33,480 with that bite 443 00:20:30,039 --> 00:20:35,640 data so uh similar to the producer we're 444 00:20:33,480 --> 00:20:38,559 going to use the confluent Kafka Library 445 00:20:35,640 --> 00:20:40,559 again and importing a consumer this time 446 00:20:38,559 --> 00:20:42,440 instead of a 447 00:20:40,559 --> 00:20:46,200 producer and we're going to use this 448 00:20:42,440 --> 00:20:48,880 double deserializer um this um thing 449 00:20:46,200 --> 00:20:50,919 here to help us turn those bytes back 450 00:20:48,880 --> 00:20:52,120 into a decimal value that we can use in 451 00:20:50,919 --> 00:20:54,640 our 452 00:20:52,120 --> 00:20:56,600 application so similar to the producer 453 00:20:54,640 --> 00:20:59,440 again we give it a configuration 454 00:20:56,600 --> 00:21:02,159 dictionary we tell the uh consumer where 455 00:20:59,440 --> 00:21:05,280 to go but a little bit differently we 456 00:21:02,159 --> 00:21:08,280 actually subscribe that consumer to the 457 00:21:05,280 --> 00:21:10,279 topic so uh we tell that cons that 458 00:21:08,280 --> 00:21:12,880 person with the barcode okay you're 459 00:21:10,279 --> 00:21:15,799 specifically going to be in this part of 460 00:21:12,880 --> 00:21:18,960 the uh data system 461 00:21:15,799 --> 00:21:22,080 essentially and then what we do is uh 462 00:21:18,960 --> 00:21:25,480 similar to the um producer we set up an 463 00:21:22,080 --> 00:21:28,600 infinite Loop every second we pull that 464 00:21:25,480 --> 00:21:32,279 uh consumer to see if there's an event 465 00:21:28,600 --> 00:21:36,200 excuse me and if there's an event we 466 00:21:32,279 --> 00:21:38,640 then uh deserialize that uh double uh so 467 00:21:36,200 --> 00:21:41,120 that that decimal number is bytes back 468 00:21:38,640 --> 00:21:43,799 to a decimal number that we can use in 469 00:21:41,120 --> 00:21:47,679 our application and really that's kind 470 00:21:43,799 --> 00:21:50,400 of it it's um what I'd like to say on 471 00:21:47,679 --> 00:21:52,679 this is yes there's a little bit of code 472 00:21:50,400 --> 00:21:54,840 uh that's hidden here but my message to 473 00:21:52,679 --> 00:21:58,159 the crowd is you know this isn't 474 00:21:54,840 --> 00:22:00,760 thousands of lines of code so with just 475 00:21:58,159 --> 00:22:03,039 you know a couple slides worth of code 476 00:22:00,760 --> 00:22:05,360 you can start getting up and running uh 477 00:22:03,039 --> 00:22:08,640 with Apache Kafka and start flowing your 478 00:22:05,360 --> 00:22:10,880 data uh through the internet and really 479 00:22:08,640 --> 00:22:13,880 that's kind of it we have now created a 480 00:22:10,880 --> 00:22:16,120 fully functioning live data pipeline 481 00:22:13,880 --> 00:22:19,159 where on the left we are getting values 482 00:22:16,120 --> 00:22:21,360 every single one second voltage values 483 00:22:19,159 --> 00:22:23,400 uh we're sending those to the cloud and 484 00:22:21,360 --> 00:22:26,080 then not only are we storing that value 485 00:22:23,400 --> 00:22:27,559 in multiple databases for later analysis 486 00:22:26,080 --> 00:22:29,000 but we can actually work with that data 487 00:22:27,559 --> 00:22:31,679 in real time so so you could have like 488 00:22:29,000 --> 00:22:33,880 an app on your phone where every single 489 00:22:31,679 --> 00:22:36,480 uh second or every single couple seconds 490 00:22:33,880 --> 00:22:38,720 that value is refreshing on some sort of 491 00:22:36,480 --> 00:22:40,279 app which is uh really 492 00:22:38,720 --> 00:22:43,159 exciting 493 00:22:40,279 --> 00:22:45,760 and uh so essentially we have built out 494 00:22:43,159 --> 00:22:48,200 something like this now for today's 495 00:22:45,760 --> 00:22:50,880 presentation we've just used a single uh 496 00:22:48,200 --> 00:22:54,559 solar panel and one Downstream uh 497 00:22:50,880 --> 00:22:58,000 consumer but Apache Kafka is excellent 498 00:22:54,559 --> 00:23:00,400 at handling uh multiple uh producers and 499 00:22:58,000 --> 00:23:02,880 consumers so with what we've built so 500 00:23:00,400 --> 00:23:06,320 far it would be fairly straightforward 501 00:23:02,880 --> 00:23:08,360 to uh add more solar panels um using 502 00:23:06,320 --> 00:23:10,000 this same type of methodology and then 503 00:23:08,360 --> 00:23:13,400 you can also have more Downstream 504 00:23:10,000 --> 00:23:16,120 consumers consuming that data and from 505 00:23:13,400 --> 00:23:19,799 there we can add a couple of cherries on 506 00:23:16,120 --> 00:23:21,960 top uh one of my favorites being the uh 507 00:23:19,799 --> 00:23:24,799 Azure key volt to help store some of our 508 00:23:21,960 --> 00:23:26,600 API secrets and if you've worked with 509 00:23:24,799 --> 00:23:29,480 electronics before you'll know that 510 00:23:26,600 --> 00:23:32,120 voltage isn't necessarily everything 511 00:23:29,480 --> 00:23:35,880 um Watts or Watt hours might be a little 512 00:23:32,120 --> 00:23:38,799 bit more interesting um for our purposes 513 00:23:35,880 --> 00:23:41,120 so just wanted to talk briefly uh just a 514 00:23:38,799 --> 00:23:43,799 couple minutes on how we can now build 515 00:23:41,120 --> 00:23:47,400 out this data pipeline into a full iot 516 00:23:43,799 --> 00:23:49,400 app so here's what we have so far uh 517 00:23:47,400 --> 00:23:52,279 where we have our essentially a local 518 00:23:49,400 --> 00:23:53,919 Perth panel a local Perth server and 519 00:23:52,279 --> 00:23:57,720 then we're sending that to the cloud for 520 00:23:53,919 --> 00:23:59,799 use somewhere else so what if we added 521 00:23:57,720 --> 00:24:02,400 an additional Raspberry Pi or an 522 00:23:59,799 --> 00:24:04,880 additional server where we had multiple 523 00:24:02,400 --> 00:24:07,279 solar panels producing to that Central 524 00:24:04,880 --> 00:24:11,720 server all using confluent cloud or 525 00:24:07,279 --> 00:24:14,840 Apache Kafka from there we can add uh 526 00:24:11,720 --> 00:24:16,799 this thing I'm going to call an actuator 527 00:24:14,840 --> 00:24:18,720 and in particular here we're going to 528 00:24:16,799 --> 00:24:19,960 use this thing called a variable 529 00:24:18,720 --> 00:24:22,000 resistance 530 00:24:19,960 --> 00:24:24,799 potentiometer now that sounds like a 531 00:24:22,000 --> 00:24:27,880 very complex instrument but what that is 532 00:24:24,799 --> 00:24:31,240 going to do is it's going to allow us to 533 00:24:27,880 --> 00:24:34,480 adjust the resistance in our circuit and 534 00:24:31,240 --> 00:24:36,720 give it a set point so uh meaning if we 535 00:24:34,480 --> 00:24:38,840 want to Cel our solar if we're seeing 536 00:24:36,720 --> 00:24:42,080 too much production we can raise how 537 00:24:38,840 --> 00:24:46,000 much resistance is in that circuit and 538 00:24:42,080 --> 00:24:50,679 um curtail that production and then from 539 00:24:46,000 --> 00:24:53,279 there we can use Jango to send a uh 540 00:24:50,679 --> 00:24:55,880 value for that set point on the 541 00:24:53,279 --> 00:24:57,679 resistance in that circuit or any of 542 00:24:55,880 --> 00:24:59,960 these circuits you can imagine any of 543 00:24:57,679 --> 00:25:02,440 these different circuit CS having um 544 00:24:59,960 --> 00:25:04,440 these variable resistance potentiometers 545 00:25:02,440 --> 00:25:08,679 and we can use this uh Jango interface 546 00:25:04,440 --> 00:25:12,520 in Python to help us uh set those set 547 00:25:08,679 --> 00:25:14,120 points so that brings us to the end of 548 00:25:12,520 --> 00:25:17,320 the presentation 549 00:25:14,120 --> 00:25:20,120 today and in conclusion the importance 550 00:25:17,320 --> 00:25:23,200 of solar energy continues to grow in 551 00:25:20,120 --> 00:25:26,000 Australia and with that comes uh a lot 552 00:25:23,200 --> 00:25:30,960 of importance around data and in 553 00:25:26,000 --> 00:25:32,799 particular live streaming data data so 554 00:25:30,960 --> 00:25:35,919 uh today we had a lot of fun building 555 00:25:32,799 --> 00:25:38,440 out uh that live data Pipeline and we 556 00:25:35,919 --> 00:25:41,440 learned that anyone can build one just 557 00:25:38,440 --> 00:25:45,320 using python you don't need to know C or 558 00:25:41,440 --> 00:25:47,640 C++ and although um like Apache Kafka is 559 00:25:45,320 --> 00:25:49,720 typically associated with Java you don't 560 00:25:47,640 --> 00:25:51,919 need to know Java to start working with 561 00:25:49,720 --> 00:25:54,640 Apache Kafka which is 562 00:25:51,919 --> 00:25:58,440 great uh and as well again I want to 563 00:25:54,640 --> 00:26:00,679 encourage everyone in the room to um 564 00:25:58,440 --> 00:26:02,520 after you leave The Talk today to go out 565 00:26:00,679 --> 00:26:04,640 and investigate these topics a little 566 00:26:02,520 --> 00:26:07,320 bit more lots of fun things to learn 567 00:26:04,640 --> 00:26:10,039 lots we didn't cover today um and as 568 00:26:07,320 --> 00:26:13,520 well try to build out your own iot and 569 00:26:10,039 --> 00:26:16,679 or Raspberry Pi Project but most 570 00:26:13,520 --> 00:26:19,760 importantly and above all else my 571 00:26:16,679 --> 00:26:22,240 conclusion for today 572 00:26:19,760 --> 00:26:27,000 is python 573 00:26:22,240 --> 00:26:29,399 rules so thank you so much uh we'll now 574 00:26:27,000 --> 00:26:31,440 uh take question now have some questions 575 00:26:29,399 --> 00:26:33,640 I think we've got time for one question 576 00:26:31,440 --> 00:26:35,440 sorry we were a little late to start no 577 00:26:33,640 --> 00:26:38,360 no no here we go 578 00:26:35,440 --> 00:26:40,960 yeah hi uh great talk by the way yeah 579 00:26:38,360 --> 00:26:42,880 thank um I just had a question like um 580 00:26:40,960 --> 00:26:45,799 could we use something like an mqtt 581 00:26:42,880 --> 00:26:49,080 broker or and an mqd client instead of 582 00:26:45,799 --> 00:26:53,640 using Apache Kafka here in this use case 583 00:26:49,080 --> 00:26:59,840 um I would need to have a think uh for 584 00:26:53,640 --> 00:26:59,840 so for a simple use case like this um 585 00:27:00,880 --> 00:27:04,760 I'd want to take that one offline but uh 586 00:27:02,760 --> 00:27:07,799 potentially um because this is a fairly 587 00:27:04,760 --> 00:27:09,640 simple application but uh as we get more 588 00:27:07,799 --> 00:27:11,520 solar panels and as we get more 589 00:27:09,640 --> 00:27:14,840 Downstream consumers then I'd want to be 590 00:27:11,520 --> 00:27:16,600 using uh Apache Kafka just for that um 591 00:27:14,840 --> 00:27:18,000 again just for that uh in the 592 00:27:16,600 --> 00:27:20,480 presentation called it like the barcode 593 00:27:18,000 --> 00:27:24,159 scanners but just how the consumers um 594 00:27:20,480 --> 00:27:25,880 work Downstream it's it's um for 595 00:27:24,159 --> 00:27:28,480 multiple Downstream consumers it just 596 00:27:25,880 --> 00:27:29,720 tends to uh my personal experience is I 597 00:27:28,480 --> 00:27:33,760 like it a lot more than just like a 598 00:27:29,720 --> 00:27:33,760 messaging cue um 599 00:27:37,840 --> 00:27:43,600 yeah I I'll interpret that as general 600 00:27:40,600 --> 00:27:46,320 agreement and another outrageous Round 601 00:27:43,600 --> 00:27:48,120 of Applause thank you so much 602 00:27:46,320 --> 00:27:52,559 AJ thank 603 00:27:48,120 --> 00:27:52,559 you thank you cheers