Zoekresultaten : lopy

LoRaWAN with LoPy and KPN + Loggly

 Gepubliceerd door om 15:49  Hardware, LoRaWAN
mei 202017
 

In the Netherlands, KPN was the first to offer nationwide coverage of a IoT network based on LoRaWAN. You can read about my first tests using their Network in combination with the Marvin node in this post. Unlike with the IoT network that for example is currently being rolled out by T-Mobile, which uses NB-IoT and different hardware than The Things Network (TTN), switching a device from the TTN network to the KPN network is simple: just change the DEV_ADDR, NWK_SWKEY, APP_SWKEY values in the config.py of you Pycom LoPy to the values that are provided in the management environment of KPN (see image left). No changes in the microPython code needed. You could even have a device connect to both networks and switch between them (although you probably don’t want to do that when you’ve got a battery powered node).

KPN offers a free test period where you can test your nodes on their infrastructure without having to pay. It is what I used for my train trip last month where I used both the Marvin node (connected to KPN) and the LoPy (connected to TTN) as a way to get a feel for coverage while moving in the Netherlands.

Besides the fact that KPN offers a commercial solution, the free test version (don’t know about the paid version) has a number of differences: unlike TTN where they provide a number of integration options (Cayenne, Data Storage provided by TTN, HTTP integration, IFTTT Maker), KPN only offers HTTP integration. This means you have to provide a destination URL for an HTTPS endpoint where the data is stored. In the Marvin workshop they use Hookbin.com as a free and easy to setup endpoint. But endpoints created there only store data for a limited time. That is why I now use the free version of Loggly.com to collect the data. But of course, the data is only useful if I manage to get it from Loggly to my own local system.

A second difference is a bit of a mystery. If I used the Marvin to send data over the KPN network, the data gets encrypted by the Marvin, but automatically is being decrypted again on the KPN server. But if I use the LoPy to send data over the KPN network, the data shown in the debug console at KPN and the data received by Loggly is still encrypted.

I managed to get both challenges resolved and in this post I’ll do a write-up not of the (lengthy) process of getting to the working code, but of the end result. All code is available on Github.

Lees verder….

Deel dit bericht:
mei 142017
 

At AliExpress they sell a number of cheap GPS modules that you can use for Arduino. I ordered one (this one) GY-NEO6MV2 for €6,82 incl. free shipping (the seller doesn’t offer free shipping anymore so you might want to shop around a bit) and wanted to try it out on the LoPy. Now, I wanted to say that using it is really easy, it is, but then again there were more than enough bumps in the road to get it to work the way I wanted it. But hey, what is life without some challenges?

First things first: the GPS module is easy to use. It use UART to connect to it. As soon as you have got something that is willing to listen to it, power it (it worked using 3.3V), it start sending you GPS data that you only need to interpret. I soldered 4 header pins to the module, connected the VCC to the 3.3V, GND to GND on the Pyboard, the TX line to “P11” and the RX line to “P12”.

As soon as you connect power to the LoPy, the GPS unit is powered. The red light blinking means that the unit is working and sending data. You just need to listen to it.  The code to do that is available here on GitHub.

To start listening:  com = UART(1,pins=(config.TX, config.RX), baudrate=9600)

To interpret the data coming from the module, I use the MicropyGPS module. It is initialized using my_gps = MicropyGPS().

After that it is a matter of checking if there is any data available, and then feed it character by character to the module:

if com.any():
    my_sentence = com.readline()
    for x in my_sentence:
        my_gps.update(chr(x))

 

Lees verder….

Deel dit bericht:
apr 092017
 

I still wasn’t out of “what if…” scenario’s for the devices I had been playing with in relation to The Things Network / LoRaWAN. Because, although I had used the WiFi (and of course LoRA) capabilities of the LoPy a lot, I had not yet played with its BLE (Bluetooth Low Energy) capabilities. For that I needed something else that could use BLE to connect to it. My iPad Mini, the micro:bit, my desktop machine (thanks to the BLE USB adapter), they all could do that. But I wanted to use the Puck-js buttons that I had for that.

The use-case:  If I press the button on the Puck.js (I have two of them, I can press either of them), then the Puck.js connects over bluetooth to the LoPy. After the connection has been made, the Puck.js sends 1) its device-id 2) the measurement of the light sensor of the Puck.js 3) the measurement of the temperature sensor of the Puck.js and 4) the battery voltage of the Puck-js. Once the LoPy has received those 4 values (encoded as a single HEX-string), it sends it to The Things Network (TTN) via LoRaWAN.

Like with the Adafruit Circuit Playground, one of the challenges was that both devices (the LoPy and the Puck.js) use different programming languages and there were no existing examples that handles the cross platform connection.

I uploaded all code to github.com

Programming the Puck.js

To program the Puck.js, you need the Espruino IDE. I have had my fair share of problems connecting to the Puck.js from within that IDE. It is probably one of the challenges of using BLE as a connection to program. But in the end it got the job done. I wasted most time trying to understand how I can send data from the Puck.js to the LoPy after connecting to it. There was an example using 2 Puck.js to send data, but I could not figure out what the UUID of the PrimaryService and the UUID of the Characteristic for the LoPy that allowed me to write data to it where.

I tried to figure that out using code on the Puck.js, but that didn’t work. In the LoPy code that I found, the service and characteristic were defined like this:

srv1 = bluetooth.service(uuid=b'1234567890123456', isprimary=True)

chr1 = srv1.characteristic(uuid=b'ab34567890123456', value=5)

I finally discovered how these needed to be added in the Puck.js code by using nRF Connect, a free tool for iOS. After setting up the LoPy so that it broadcasts using BLE (see the code below), I connected to the LoPy using the nRF Connect app. It then shows you the correct UUID’s that are in the Send_BT_to_LoPy.js script:

return d.getPrimaryService("36353433-3231-3039-3837-363534333231");

return s.getCharacteristic("36353433-3231-3039-3837-363534336261");

Easy, once you know it.

Note #1:  The Puck.js connects to a device named “LoPy01” so if you change the name of the device in main.py for the LoPy, you also have to change it in the code for the Puck.js
Note #2:  I added the id for the Puck.js in the code, first line. You need to change that to the code for your Puck.js if you have more than 1 Puck.js and want to be able to keep the transmitted values apart afterwards.

Let’s continue with the LoPy.

Lees verder….

Deel dit bericht:
apr 052017
 

One of the challenges left with regards to the LoPy was to find a way to actually connect sensors to the node. I had little luck with the DHT11 temperature/moisture sensor (one of the drawbacks of MicroPython over regular Arduino code is the lack of libraries) and didn’t have any I2C sensors lying around. But I did of course still had the Circuit Playground by Adafruit and I knew how to talk to that one from another device using the hardware serial RX/TX connection because I had already connected it to a micro:bit that way (the posts are here, but in Dutch).

So surely it should be possible to connect it to a LoPy and send the sensor data to The Things Network (TTN) that way? Is was. Not as easy and simple as I had hoped, but in the end it worked. Since it is rather a complex structure, I made a small graphic to explain how all the parts go together.

Let’s start with the easy parts: I have got a LoPy Nano Gateway up and running. That is not a full compliant LoRaWAN gateway, but it takes care of receiving messages send via LoRa / 868 Mhz and relaying them, via WiFi, via my WiFi Router, the internet, to the The Things Network (TTN) backend. That is the regular part.

On the right end lower corner, the action starts with the LoPy Node. It is connected via two cables to the Circuit Playground (CPG). One cable goes from the TX port of the LoPy Node to the RX port of the CPG. The other one goes from the TX port of the CPG to the RX port of the LoPy Node. The LoPy Node sends a signal (a digit ranging from 1 to 10) over the serial connection to the CPG. After the CPG receives the signal, it reads the three build in sensors for light, noise and temperature. It then converts the values to a 12 byte HEX string value and sends that back over the serial connection toe the LoPy Node. After sending the signal, the LoPy node waits a bit, giving the CPG time to return the value, then it reads the values and sends that via LoRa to the first available gateway, in this case the LoPy Nano Gateway on my desk.

After the gateway has delivered the messages to TTN, a Payload function translates the received value back into three individual values. It then send them, via the Integrations option, to the Swagger server where it the is available in JSON format. See, easy peasy. 🙂

I uploaded all the code to Github. You can find it here. The code in the LoPy-flash folder is (of course) intended for the LoPy Node, the code in the Circuit Playground folder needs to be uploaded to the CPG via the regular Arduino IDE. I made some changes to the LoPy node code provided by Pycom: I added the option to have the LoPy Node also connect to your local WiFi. Not necessary, but it makes it easier to debug/connect. If you leave that info blank, it will just ignore. Also, if you take the node outside of the range of you WiFi network, it will just ignore it. Another thing that I changed, is the use of config.py for the Node, so that you only need 1 place to change all the info. Finally I choose OTAA instead of ABP as the authentication for the node.

Lees verder….

Deel dit bericht:
jan 132018
 

Time for part 2 of the post about getting the “cheap” Chinese ESP32 + SX1276 board connected to The Things Network.

The picture in this and the other post shows the board with a DHT11 temperature and humidity sensor already connected. I stopped using the small case that was on sale, because with the pinheaders soldered to the board and dupont cables connected to it, it no longer fitted.

Also, I am no longer using the small antenna that was provided with the board. I seem to have accidentally twisted the cable that you use to connect the SMA socket to the U.FL IPX connector on the board. The only suitable antenna I had available, was one that was provided as part of the LoPy kickstarter kits (which apparently is different from the antenna sets they sell now). The antenna I got in the kit is a RP-SMA antenna meaning the cable is also RP-SMA. Long story short: I can connect the LoPy cable + LoPy antenna to the board, but the the provided small antenna won’t fit on the LoPy cable. With the LoPy antenna combi I’ve been able to get about 500 meters range outdoors, combined with the single channel LoPy nanogateway. Which is absolutely not bad at all, also given that I’m fixed not to just one channel there but also to SPF7. I’ll do further comparisons once the replacement cable has arrived.

So, the DHT11 sensor. It helped that I managed to figure out that the provided pinout chart was incorrect. Once I know to which actual ports the DHT11 was connected, it was a matter of integrating the library and code into the existing code.  To keep the number of things that could go wrong manageable, I first tested jut the DHT11 code. I provided an example here. If that doesn’t work, don’t bother with the connection to TTN.

Lees verder….

Deel dit bericht:
jan 132018
 

The previous post about the LoRa board I bought via Aliexpress, I did in Dutch. I should have know that, like often happens with the more technical posts on my blog, the majority of people interested in it are not from the Netherlands.
So, this follow-up post about connecting a sensor to it, I’ll do in English again.

I will do the quick summary of the previous post first, so you’ll have an all-in-one topic:

This board was the first one I bought of Aliexpress. It was cheap, €13,9 incl. shipping for ESP32 + SX1276 + 0.96 inch OLED. ESP32 means WiFi (like you have with the ESP8266) *and* Bluetooth build in. If you compare that to a LoPy (about 50 euros) or a Marvin (about 85 euros), that is cheap. Problem though with Aliexpress is that you don’t always get a nice manual with the device.
Luckely there is a very active forum at The Things Network, and they have a topic specific for this combination of ESP32 and SX1276 chip. A number of people, much smarter than me, took the time there to figure out how to setup the board. All I had to do is go through their posts.

Lees verder….

Deel dit bericht:
jan 102018
 

Tot voor kort had ik 2 verschillende LoraWAN nodes in huis: een tweetal LoPy‘s, waarvan er eentje dienst doet als single channel gateway en een Marvin. Beide zijn niet bijzonder goedkoop, een LoPy met ontwikkelbordje en antenne kost zo’n 50 euro excl. verzendkosten. Een Marvin kost bijna 85 euro excl. verzendkosten. Niet echt sensoren dus die je ergens “kwijt” wilt raken. Terwijl een LoraWAN sensor toch juist vaak op een plek moet komen te hangen die iets verder van alles weg is (zoals sensoren langs een weg die fijnstof meten of zo).

Je kunt zelf een sensor bouwen door een chip te bestellen voor de communicatie, een ESP8266 te kopen, antenne etc en dan solderen. Maar dat kost tijd en extra werk.  De “868MHz/915MHz SX1276 ESP32 LoRa 0.96 Inch Blue OLED Display Bluetooth WIFI Lora Kit 32 Module IOT Development Board for Arduino” zoals de listing op AliExpress voluit luidt, is een voorbeeld van een tussenweg: voor €13,90 incl. verzendkosten heb je een ESP32 + SX1276 chip op een ontwikkelbord. Als je het LCD-scherm dat er dan op zit niet nodig hebt, kun je nog een paar euro besparen en €10,29 betalen incl. verzendkosten. Het is niet mijn eerste node op basis van een ESP32, ook de LoPy maakt daar gebruik van, maar het was wel de eerste die ik via AliExpress bestelde. En ik wist dat het daar bestellen een keerzijde heeft: documentatie is niet altijd voorhanden.

Gelukkig is er ook een heel actief forum bij The Things Network waar een heel topic specifiek voor deze combinatie van ESP32 en SX1276 chip (inclusief het OLED schermpje) ingericht is. En daar hadden sinds oktober 2017 al een paar slimme mensen alles uitgezocht wat ik nodig had om ook mijn exemplaar aan de praat te krijgen. En omdat het een proces is dat ik over een paar maanden zeker niet meer uit mijn hoofd weet te herhalen, documenteer ik het hier weer even.

Lees verder….

Deel dit bericht:
apr 152017
 

Now that Alex explained everyone how to use MQTT in combination with the LoPy, I thought it was time to show some more advanced uses of MQTT in case you still had no idea why you would bother learning to understand it.
The nice thing about MQTT (MQ Telemetry Transport or Message Queue Telemetry Transport) as a protocol, is that it is not tied to the LoPy or WiPy that Alex used in his example. You can use it in combination with many different devices, tools and applications. For example, in our house, I use a Mosquitto MQTT broker as the central backbone for the home automation. For those that can understand Dutch, see this blogpost I did in 2014, or the one about the lights in my Christmas tree.

MQTT is also supported by The Things Network (TTN) meaning that you can retrieve all the data that your nodes send to TTN using MQTT. This also means you can use MQTT as a way to create a local backup of the data that your nodes send this way.
You can also use it in combination with the KPN LoRaWAN network, but the setup is slightly different. So in this post I am going to focus on TTN, although like before I will be using both the Marvin board and the LoPy board (in combination with Puck.js although that is completely optional of course).

I will be using Node-RED installed on one of my Raspberry Pi devices and I will be using MySQL as the database backend. I will be posting about MySQL versus MongoDB versus InfluxDB one of these days, but on a Raspberry Pi for now this was the quickest and easiest solution.

Let’s dive in:

Lees verder….

Deel dit bericht:
apr 102017
 

Als het in het onderwijs in Nederland over “programmeren” gaat worden eenvoudige vragen al heel snel ingewikkeld. Dus een vraag als “Welke programmeertalen zouden onze leerlingen/studenten moeten kennen?” (bron) is niet helemaal zonder risico. Immers, je moet dan gaan nadenken over het doel dat je daarmee hebt. Wil je ze leren programmeren? Of juist coderen? Of software ontwikkelen? Ik ga niet eens proberen naar bronnen te linken die ze op één hoop of op juist heel verschillende hopen (en dan per bron ook verschillend) gooien.

Dus laat ik het maar even veilig houden in deze blogpost. Zo’n 9 jaar geleden vroeg ik me af welke programmeertalen ik allemaal zou moeten leren. Zoals ik toen beschreef:   Basic was mijn eerste kennismaking met programmeren, maar daar kon je (toen) zo weinig mee dat ik er niet veel interesse voor had. Op de universiteit leerde ik Turbo Pascal om daar vervolgens nooit meer wat mee te doen. Daarna kwam ik in de Windows omgeving en Visual Basic (binnen Office!) en Active Server Pages (ASP) terecht. Mijn eerste kennismaking met JavaScript was in de browser, ASP werd vervangen door PHP toen ik weblogtools ging gebruiken op basis van die taal. En daarna werd het een opeenvolging van “wat heb ik nodig”. Zo kwam er een beetje Python bij, een heel klein beetje .NET en eveneens een klein beetje Java. Dat was toen. Sindsdien zijn er dingen gewijzigd en gelijk gebleven.

Lees verder….

Deel dit bericht:
apr 072017
 

What happens if you take a LoRaWAN node with you in a train while you travel across the Netherlands for about 2,5 hours? I did not know and wanted to find out today because I had to be in Zwolle for a meeting.

So I charged a big external battery (with 2 USB ports), drilled a couple of holes in a plastic container to guide through the micro-USB connectors, and put in some bubble foil inside for safe transport. I drilled another hole to connect the external antenna for the LoPy node. Besides the LoPy, I put the Marvin in the box, with the temperature/humidity sensor on the outside of it. Not that it really mattered, today was going to be about finding gateways while I was on the road.

Things did not look good for the experiment though in the morning. The Things Network (TTN) backbone was acting up again. That was a bummer, because I still had to change the code on the LoPy. It had the code installed for the Circuit Playground and I wasn’t planning on bringing that also. So I changed the code to a simple “send a number every 30 seconds” but was not able to test it before leaving for the train.

To make matters more balanced: I decided to have the Marvin connect to the KPN network (still got 60 days left on my free trial), but the Hookbin.com server decided that today was a good day to refuse to work. And I needed a place to store the data sent by the Marvin. Luckily I found loggly.com another site that you can use as a destination for KPN nodes. I think it is better than Hookbin btw because it keeps more records and even the free plan should be enough for most people. Another nice thing was that Loggly also can act as an HTTP-integration for TTN, so I could collect both the data sent via KPN and the data sent via TTN in one single place. Quick tip: Loggly provides you with an http:// url for the endpoint, KPN doesn’t accept http:// but you can simply change the provided url to https:// and then it works.

OK, into the train. I wasn’t really sure what to expect. A train means lots of metal and a fast moving object (and nodes).

Lees verder….

Deel dit bericht: