{"id":285,"date":"2018-09-05T13:45:41","date_gmt":"2018-09-05T12:45:41","guid":{"rendered":"https:\/\/computenodes.net\/?p=285"},"modified":"2025-01-17T16:03:57","modified_gmt":"2025-01-17T16:03:57","slug":"emf-camp-2018-air-quality-lorawan-workshop","status":"publish","type":"post","link":"https:\/\/computenodes.net\/2018\/09\/05\/emf-camp-2018-air-quality-lorawan-workshop\/","title":{"rendered":"EMF camp 2018 Air Quality LoRaWAN workshop"},"content":{"rendered":"
At EMF camp 2018 we ran three workshops in order to improve people’s understanding of air quality. The workshop details can be found at https:\/\/www.emfcamp.org\/line-up\/2018\/180-air-quality-sensor-devices-build-program-and-test<\/a>. Here are the details needed to recreate the workshop. The workshop was designed to be suitable for anyone with no prior experience using a Raspberry Pi, however, the setup steps that we performed in advance of the workshop do require more advanced knowledge.<\/p>\n Some of the slides presented at the beginning of the workshop were infographics taken from the World Health Organization (WHO). They can be found along with other general figures about air quality in the world at http:\/\/www.who.int\/airpollution\/infographics\/en\/<\/a>. If you want to learn more about air quality and especially about air quality in UK, we suggest you to read the report published by the Royal College of Physicians and the Royal College of Paediatrics and Child Health in 2016: Every breath we take: the lifelong impact of air pollution<\/a>. <\/p>\n The links below are the suppliers we used to purchase the parts – other suppliers are available.<\/p>\n We used heat shrink to attach the USB-serial adapter to the sensor as a single module. The heat shrink is not available in small quantities so a Velcro pad can be used instead to both secure the USB-serial adapter and to prevent accidental shorting of pins. The equipment was mounted on a custom laser cut perspex sheet, however, feel free to create your own mounting solution.<\/p>\n We have written a couple of custom libraries to facilitate this workshop (which will be installed in the setup steps). If you want to dig deeper into the code it can be found on github.\u00a0 If you make any improvements to the code please submit a pull request.<\/p>\n Having purchased \/ acquired the hardware the following steps have to be carried out to get to the stage where the workshop code can be run. In order for the LoRaWAN part to work you have to be in coverage of The Things Network. For the workshop we deployed 3 gateways on site. Coverage can be checked by using TTN Mapper<\/a>. If you are not in coverage you can extend the network by running your own gateway. See https:\/\/www.thethingsnetwork.org\/docs\/gateways\/<\/a> for details.<\/p>\n In order to assemble the hardware do the following steps:<\/p>\n Our finished nodes looked like<\/p>\n Copy the latest Raspbian image on to the SD card, and then connect to the Pi and run the following script. Once the node has rebooted make sure it has the correct time (If it’s connected to a network it will do this automatically). Then run:<\/p>\n This sets the time on the hardware RTC so the Pi knows the time when it boots even without GPS or network connections.<\/p>\n We use The Things Network to transfer the data from the device to Cayenne for viewing. This also requires setting up which can be done with the following steps. For more information please read The Things Network documentation.<\/p>\n Having done the above steps your config file should look similar but not identical to the following (The devaddr, nwskey and appskey lines will be different:<\/p>\n In order to visualise the data you will also need an account on Cayenne https:\/\/cayenne.mydevices.com\/cayenne\/dashboard\/start<\/a>. Having created the account you need to add the device. To do this follow these steps:<\/p>\n Finally we are at the point where we can write the code that was used in the workshop. Connect to the Jupyter notebook, the exact address for this will depend on your network but it may be available at http:\/\/raspberrypi:8888. If you find any mistakes in these instructions or they become out of date please comment below.<\/p>\n","protected":false},"excerpt":{"rendered":" At EMF camp 2018 we ran three workshops in order to improve people’s understanding of air quality. The workshop details can be found at https:\/\/www.emfcamp.org\/line-up\/2018\/180-air-quality-sensor-devices-build-program-and-test. Here are the details needed to recreate the workshop. The workshop was designed to be suitable for anyone with no prior experience using a Raspberry Pi, however, the setup stepsAir quality and low-cost sensors<\/h1>\n
\nThe sensors used during the workshop are low-cost sensors used to monitor fine particles (PM10<\/sub> and PM2.5<\/sub>). We strongly encourage you to read the advice from the Department for Environment Food & Rural Affairs (DEFRA) on the use of low-cost sensors for air pollution to have a better understanding of their limitations. The recommendation can be found at https:\/\/uk-air.defra.gov.uk\/library\/aqeg\/pollution-sensors.php<\/a><\/p>\nHardware<\/h1>\n
\n
Software<\/h1>\n
\n
Setup<\/h1>\n
Hardware setup<\/h2>\n
\n
Software installation<\/h2>\n
\nThe code below will install the required libraries and software to run the workshop. This will take some time.<\/p>\n\r\necho "dtparam=spi=on" | sudo tee -a \/boot\/config.txt\r\necho "dtoverlay=spi-gpio-cs" | sudo tee -a \/boot\/config.txt\r\necho "dtparam=i2c_arm=on" | sudo tee -a \/boot\/config.txt\r\nsudo raspi-config noint do_serial 2\r\n\r\n#get the spi CS pin overlay\r\nwget https:\/\/github.com\/computenodes\/dragino\/releases\/download\/v0.0.1\/spi-gpio-cs.dtbo\r\nsudo mv spi-gpio-cs.dtbo \/boot\/overlays\/\r\n\r\n#install jupyter\r\nsudo apt update\r\nsudo apt-get install -y python-dev\r\nsudo -H pip install --upgrade pip\r\nsudo -H pip install jupyter\r\nsudo apt-get install -y python-seaborn python-pandas python3-pandas\r\nsudo apt-get install -y ttf-bitstream-vera\r\n\r\nsudo pip3 install jupyter\r\nsudo ipython3 kernelspec install-self\r\njupyter notebook --generate-config\r\njupyter notebook password # this will prompt you for a password\r\n\r\n\r\n#add jupyter to crontab\r\necho "@reboot pi \/usr\/local\/bin\/jupyter notebook --ip=0.0.0.0 --no-browser --notebook-dir=\/home\/pi >> \/tmp\/jupyter.out 2>> \/tmp\/jupyter.err" | sudo tee -a \/etc\/cron.d\/jupyter\r\n\r\n#setup the RTC\r\necho "i2c-bcm2708" | sudo tee -a \/etc\/modules\r\nsudo modprobe i2c:mcp7941x\r\necho "@reboot root echo mcp7941x 0x6f > \/sys\/class\/i2c-adapter\/i2c-1\/new_device; ( sleep 2; hwclock -s ) &" | sudo tee -a \/etc\/cron.d\/rtc\r\n\r\n\r\n#get the cayenne module\r\nwget https:\/\/github.com\/FEEprojects\/cayennelpp-python\/releases\/download\/v1.0.0\/simplecayennelpp-1.0.0.tar.gz\r\n#install it\r\npip3 install simplecayennelpp-1.0.0.tar.gz\r\n#get the plantower module\r\nwget https:\/\/github.com\/FEEprojects\/plantower\/releases\/download\/v0.0.2\/plantower-0.0.2.tar.gz\r\npip3 install plantower-0.0.2.tar.gz\r\n#get the dragino lib and install\r\nwget https:\/\/github.com\/computenodes\/dragino\/releases\/download\/v0.0.2\/dragino-0.0.2.tar.gz\r\npip3 install dragino-0.0.2.tar.gz\r\nsudo reboot\r\n<\/pre>\n
\r\nsudo hwclock -w\r\n<\/pre>\n
The Things Network Setup<\/h2>\n
\n
\r\n#GPS configuration\r\ngps_baud_rate = 9600\r\ngps_serial_port = "\/dev\/serial0"\r\ngps_serial_timeout = 1\r\ngps_wait_period = 10\r\n\r\n#LoRaWAN configuration\r\nspreading_factor = 7\r\nmax_power = "0x0F"\r\noutput_power = "0x0E"\r\nsync_word = 0x34\r\nrx_crc = True\r\n#Where to store the frame count\r\nfcount_filename = "\/home\/pi\/.lora_fcount"\r\n\r\n##Valid auth modes are ABP or OTAA\r\n##All values are hex arrays eg devaddr = 0x01, 0x02, 0x03, 0x04\r\nauth_mode = "abp"\r\ndevaddr = 0x26, 0x01, 0x19, 0xA9\r\nnwskey = 0x4A, 0xE5, 0x3B, 0x8E, 0x1B, 0x4C, 0x24, 0x7C, 0x07, 0xA3, 0x52, 0x38, 0x3A, 0x28, 0x1F, 0xCD\r\nappskey = 0x02, 0x1D, 0x25, 0xF1, 0x92, 0xCE, 0x2B, 0xA2, 0x89, 0x8F, 0x29, 0x18, 0x43, 0xA9, 0x00, 0x1E\r\n\r\n#auth_mode = "otaa"\r\n#deveui =\r\n#appeui =\r\n#appkey =\r\n<\/pre>\n
Cayenne Setup<\/h2>\n
\n
Workshop Code<\/h1>\n
\nThe code created is as follows:<\/p>\n\r\nfrom dragino import Dragino # import the module required for GPS and LoRaWAN\r\nfrom simplecayennelpp import CayenneLPP # import the module required to pack the format cayenne expects\r\nfrom plantower import Plantower # import the module to speak to the PM sensor\r\nfrom time import sleep # import sleep so can wait between polling the sensor\r\nsensor = Plantower()\r\ndataList = []\r\nfor i in range(10):\r\n data = sensor.read()\r\n dataList.append(data.gr03um)\r\n sleep(1)\r\naverage_reading = sum(dataList) \/ len(dataList)\r\n\r\nD = Dragino("\/home\/pi\/dragino.ini") # Set up the dragino HAT\r\nmy_position = D.get_gps()\r\nlpp = CayenneLPP()\r\nlpp.addAnalogInput(1, round(average_reading))\r\nlapp.addGPS(2, my_position.latitude, my_position.longitude, myposition.altitude)\r\nD.send_bytes(list(lpp.getBuffer()))\r\n<\/pre>\n
Continue reading EMF camp 2018 Air Quality LoRaWAN workshop<\/span> <\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,2,8,6],"tags":[],"class_list":["post-285","post","type-post","status-publish","format-standard","hentry","category-gps","category-lorawan","category-raspberry-pi","category-sensors","col-1"],"_links":{"self":[{"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/posts\/285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/comments?post=285"}],"version-history":[{"count":17,"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/posts\/285\/revisions"}],"predecessor-version":[{"id":321,"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/posts\/285\/revisions\/321"}],"wp:attachment":[{"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/media?parent=285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/categories?post=285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computenodes.net\/wp-json\/wp\/v2\/tags?post=285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}