issue169:micro-ci_micro-la
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue169:micro-ci_micro-la [2021/06/01 07:42] – créée d52fr | issue169:micro-ci_micro-la [2021/06/08 15:12] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | **Many people think that the RPi Pico is a great little microprocessor, | ||
- | Many people think that the RPi Pico is a great little microprocessor, but because there is no “direct” support for networking, it’s not really worth it, even at its very low purchase price. I asked the MicroPython | + | Beaucoup de gens pensent que le RPi Pico est un excellent microprocesseur, mais qu'en raison de l' |
- | Just as an aside, in late April, 2021, the latest firmware for the RPi Pico, ESP8266, and the ESP32, is now at level 1.15. You can now download the latest firmware at https:// | + | |
+ | **Just as an aside, in late April, 2021, the latest firmware for the RPi Pico, ESP8266, and the ESP32, is now at level 1.15. You can now download the latest firmware at https:// | ||
As I mentioned last month, the ESP-01 WiFi module is available, but so far, I haven’t been able to get it to work well enough to really suggest it. I’m still trying to get somewhere with it but have made only limited progress. | As I mentioned last month, the ESP-01 WiFi module is available, but so far, I haven’t been able to get it to work well enough to really suggest it. I’m still trying to get somewhere with it but have made only limited progress. | ||
- | The good folks at Adafruit have a small networking coprocessor called the AirLift that will allow the Pico to connect to the internet and do just about anything that you need. You have to use CircuitPython on the Pico, but the project works well. You can find this project at https:// | + | The good folks at Adafruit have a small networking coprocessor called the AirLift that will allow the Pico to connect to the internet and do just about anything that you need. You have to use CircuitPython on the Pico, but the project works well. You can find this project at https:// |
- | I have tried this project and it works and works well. There are two big drawbacks for me, however. First, is that the project must be done under CircuitPython. The second is that the AirLift is about twice the price of the RPi Pico. | + | Pour l' |
- | If you want a pure MicroPython solution that is less expensive, you are NOT out of luck. There is a project by some of the MicroPython developers that fills the bill. You can find the repository at https:// | + | Comme je l'ai mentionné le mois dernier, le module WiFi ESP-01 est disponible, mais jusqu' |
- | Project of the month | + | Les bonnes gens d' |
- | So we’ll use this as the project of the month. This project will be broken down into multiple parts, the first will be to use the internal temperature sensor on the Pico to get the temperature, | ||
- | Part 1 - RPi Pico Temperature sensor | + | **I have tried this project and it works and works well. There are two big drawbacks for me, however. First, is that the project must be done under CircuitPython. The second is that the AirLift is about twice the price of the RPi Pico. |
+ | |||
+ | If you want a pure MicroPython solution that is less expensive, you are NOT out of luck. There is a project by some of the MicroPython developers that fills the bill. You can find the repository at https:// | ||
+ | |||
+ | J'ai essayé ce projet et il fonctionne et fonctionne bien. Il y a cependant deux gros inconvénients pour moi. Le premier, c'est que le projet doit être réalisé sous CircuitPython. Le second est que l' | ||
+ | |||
+ | Si vous voulez une solution purement MicroPython qui est moins chère, vous n' | ||
+ | |||
+ | |||
+ | **Project of the month | ||
+ | |||
+ | So we’ll use this as the project of the month. This project will be broken down into multiple parts, the first will be to use the internal temperature sensor on the Pico to get the temperature, | ||
+ | |||
+ | Le projet du mois | ||
+ | |||
+ | Nous allons donc utiliser ce projet comme projet du mois. Ce projet sera décomposé en plusieurs parties, la première sera d' | ||
+ | |||
+ | |||
+ | **Part 1 - RPi Pico Temperature sensor | ||
The first logical step is to write a test program that will read the internal temperature sensor on the Pico. We can access the sensor through the ADC (Analogue-to-Digital Converter) built into the Pico. ADC? Yes. The Pico actually has four ADC options, three available on the GPIO pins, and one internal that is dedicated to the temperature sensor. These are all 12-bit converters. | The first logical step is to write a test program that will read the internal temperature sensor on the Pico. We can access the sensor through the ADC (Analogue-to-Digital Converter) built into the Pico. ADC? Yes. The Pico actually has four ADC options, three available on the GPIO pins, and one internal that is dedicated to the temperature sensor. These are all 12-bit converters. | ||
- | Using an ADC is really very easy. We provide a voltage into one of the pins – which comes in as a 16-bit unsigned integer – which will be a number from 0 to 65,535. In theory, the value becomes 0 for no voltage and 65,535 for the full 3.3 volts. Please be sure that your maximum voltage going into the ADC is 3.3 volts DC. Otherwise, you will overload the system and cause the magic blue smoke to escape. This will render the Pico non-functional! | + | Using an ADC is really very easy. We provide a voltage into one of the pins – which comes in as a 16-bit unsigned integer – which will be a number from 0 to 65,535. In theory, the value becomes 0 for no voltage and 65,535 for the full 3.3 volts. Please be sure that your maximum voltage going into the ADC is 3.3 volts DC. Otherwise, you will overload the system and cause the magic blue smoke to escape. This will render the Pico non-functional!** |
- | While this is a nice way to view the range of voltages, and 65,535 is an easy way to visualize the fact that you are receiving the full 3.3 volts, it doesn’t quite relate in most people' | + | Partie 1 - Capteur de température du RPi Pico |
+ | |||
+ | La première étape logique est d' | ||
+ | |||
+ | L' | ||
+ | |||
+ | |||
+ | **While this is a nice way to view the range of voltages, and 65,535 is an easy way to visualize the fact that you are receiving the full 3.3 volts, it doesn’t quite relate in most people' | ||
So we now know that the temperature sensor within the Pico returns an integer that we can use to get the temperature value. However, there is another formula that is specific to the Pico to get our final value. That formula is: | So we now know that the temperature sensor within the Pico returns an integer that we can use to get the temperature value. However, there is another formula that is specific to the Pico to get our final value. That formula is: | ||
- | temperature = 27 - (reading - 0.706) / 0.001721 | + | temperature = 27 - (reading - 0.706) / 0.001721** |
- | Where reading is our ADC value with the conversion factor applied. So assuming the average temperature inside of our house ranges between 22-24 degrees Centigrade, we can assume that our voltage value should be somewhere between 0.7139803 and 0.7107576 (22.36296 and 24.23554 C). The actual voltage reading has a tiny variance. Due to this, many factors can cause the reading to vary quite a bit. Some of this could be due to variance in the voltage provided to the Pico. Many people have commented on the temp sensor in the Pico not being very stable. For our purposes (at least here), it will do us well. I’m sorry for the long dissertation on the way that the ADC works, but I felt you should know. | + | Bien qu'il s' |
+ | |||
+ | Nous savons donc maintenant que le capteur de température du Pico renvoie un nombre entier que nous pouvons utiliser pour obtenir la valeur de la température. Cependant, il existe une autre formule spécifique au Pico pour obtenir notre valeur finale. Cette formule est la suivante : | ||
+ | |||
+ | température = 27 - (lecture - 0, | ||
+ | |||
+ | |||
+ | **Where reading is our ADC value with the conversion factor applied. So assuming the average temperature inside of our house ranges between 22-24 degrees Centigrade, we can assume that our voltage value should be somewhere between 0.7139803 and 0.7107576 (22.36296 and 24.23554 C). The actual voltage reading has a tiny variance. Due to this, many factors can cause the reading to vary quite a bit. Some of this could be due to variance in the voltage provided to the Pico. Many people have commented on the temp sensor in the Pico not being very stable. For our purposes (at least here), it will do us well. I’m sorry for the long dissertation on the way that the ADC works, but I felt you should know. | ||
So, let’s code our test program. First, as always, we need to import the needed libraries... | So, let’s code our test program. First, as always, we need to import the needed libraries... | ||
+ | |||
+ | import machine | ||
+ | import utime** | ||
+ | |||
+ | où « lecture » est notre valeur ADC avec le facteur de conversion appliqué. Ainsi, en supposant que la température moyenne à l' | ||
+ | |||
+ | Alors, codons notre programme de test. D' | ||
import machine | import machine | ||
import utime | import utime | ||
- | Now we set up which ADC we will be using (remember, the temperature sensor is ADC # 4) and our conversion factor: | + | |
+ | **Now we set up which ADC we will be using (remember, the temperature sensor is ADC # 4) and our conversion factor: | ||
sensor_temp = machine.ADC(4) | sensor_temp = machine.ADC(4) | ||
Ligne 45: | Ligne 86: | ||
If you wish, you can certainly add a display (like we did last month) to provide the reading without having to have Thonny (or your IDE of choice) visible all of the time. | If you wish, you can certainly add a display (like we did last month) to provide the reading without having to have Thonny (or your IDE of choice) visible all of the time. | ||
- | Now that we have that done, let’s move on to downloading the MQTT software project. | + | Now that we have that done, let’s move on to downloading the MQTT software project.** |
- | Part 2 - Setting up the ESP8266 | + | Maintenant nous définissons quel ADC nous allons utiliser (rappelez-vous, |
+ | |||
+ | sensor_temp = machine.ADC(4) | ||
+ | |||
+ | facteur_de_conversion = 3.3/ | ||
+ | |||
+ | Nous entrons dans une boucle « forever » (voir ci-dessus) : lire le capteur de température, | ||
+ | |||
+ | Si vous le souhaitez, vous pouvez certainement ajouter un affichage (comme nous l' | ||
+ | |||
+ | Maintenant que nous avons fait cela, passons au téléchargement du projet de logiciel MQTT. | ||
+ | |||
+ | |||
+ | **Part 2 - Setting up the ESP8266 | ||
You can download the software that goes on both the ESP8266 and the Pico from https:// | You can download the software that goes on both the ESP8266 and the Pico from https:// | ||
- | You know me, though. I’ll distill it down as much as I can to get you running as quickly as possible, but you really should read through the md file. If you don’t yet have a .md file reader, I suggest Typora which you can find at typora.io. I’ve tried countless .md readers and editors and this is by far the best one that I’ve found. | + | You know me, though. I’ll distill it down as much as I can to get you running as quickly as possible, but you really should read through the md file. If you don’t yet have a .md file reader, I suggest Typora which you can find at typora.io. I’ve tried countless .md readers and editors and this is by far the best one that I’ve found.** |
- | The first thing that you need to do is flash the bridge software onto the ESP8266. To do this you need to use a tool called esptool. There are various ways to install esptool, but the easiest way for Python programmers is to use pip (or pip3). | + | Partie 2 - Configuration de l' |
+ | |||
+ | Vous pouvez télécharger le logiciel qui s' | ||
+ | |||
+ | Mais vous me connaissez. Je vais le distiller autant que possible pour que vous soyez opérationnel aussi vite que possible, mais vous devriez vraiment lire le fichier md. Si vous n'avez pas encore de lecteur de fichiers .md, je vous suggère Typora que vous trouverez sur typora.io. J'ai essayé d' | ||
+ | |||
+ | |||
+ | **The first thing that you need to do is flash the bridge software onto the ESP8266. To do this you need to use a tool called esptool. There are various ways to install esptool, but the easiest way for Python programmers is to use pip (or pip3). | ||
pip install esptool | pip install esptool | ||
Ligne 65: | Ligne 126: | ||
ls /dev/tty* | ls /dev/tty* | ||
- | On my machine, I get a list that is 17 rows long and 6 columns wide. Buried around the middle is the actual port that I’m connected to – which, for me, is dev/ | + | ** |
+ | |||
+ | La première chose à faire est de flasher le logiciel de bridge sur l' | ||
+ | |||
+ | pip install esptool | ||
+ | |||
+ | ou | ||
+ | |||
+ | pip3 install esptool | ||
+ | |||
+ | Une fois esptool installé, vous devrez connecter votre carte ESP8266 au port USB de votre ordinateur. Par mesure de sécurité, assurez-vous qu' | ||
+ | |||
+ | ls /dev/tty* | ||
+ | |||
+ | |||
+ | **On my machine, I get a list that is 17 rows long and 6 columns wide. Buried around the middle is the actual port that I’m connected to – which, for me, is dev/ | ||
Now, using the same terminal that we just used to find the serial port, enter in the following command, replacing the port with that of your machine. | Now, using the same terminal that we just used to find the serial port, enter in the following command, replacing the port with that of your machine. | ||
Ligne 72: | Ligne 148: | ||
This usually takes about a minute or so to complete. You should see something like this... | This usually takes about a minute or so to complete. You should see something like this... | ||
+ | |||
+ | esptool.py v3.0 | ||
+ | Serial port / | ||
+ | Connecting.... | ||
+ | Detecting chip type... ESP8266 | ||
+ | Chip is ESP8266EX | ||
+ | Features: WiFi | ||
+ | Crystal is 26MHz | ||
+ | MAC: 8c: | ||
+ | Uploading stub... | ||
+ | Running stub... | ||
+ | Stub running... | ||
+ | Erasing flash (this may take a while)... | ||
+ | Chip erase completed successfully in 16.1s | ||
+ | Hard resetting via RTS pin...** | ||
+ | |||
+ | Sur ma machine, j' | ||
+ | |||
+ | Maintenant, en utilisant le même terminal que nous venons d' | ||
+ | |||
+ | esptool.py --port / | ||
+ | |||
+ | Cela prend généralement une minute environ. Vous devriez voir quelque chose comme ceci : | ||
esptool.py v3.0 | esptool.py v3.0 | ||
Ligne 88: | Ligne 187: | ||
Hard resetting via RTS pin... | Hard resetting via RTS pin... | ||
- | Once the memory is erased, we need to load the new firmware. In the terminal, make sure that you are in the bridge folder and enter the following command (again replacing the port definition with that of your own)… | + | |
+ | **Once the memory is erased, we need to load the new firmware. In the terminal, make sure that you are in the bridge folder and enter the following command (again replacing the port definition with that of your own)… | ||
esptool.py --port / | esptool.py --port / | ||
The terminal output should look something like this… | The terminal output should look something like this… | ||
+ | |||
+ | esptool.py v3.0 | ||
+ | Serial port / | ||
+ | Connecting.... | ||
+ | Detecting chip type... ESP8266 | ||
+ | Chip is ESP8266EX | ||
+ | Features: WiFi | ||
+ | Crystal is 26MHz | ||
+ | MAC: 8c: | ||
+ | Uploading stub... | ||
+ | Running stub... | ||
+ | Stub running... | ||
+ | Configuring flash size... | ||
+ | Auto-detected Flash size: 4MB | ||
+ | Flash params set to 0x0040 | ||
+ | Compressed 622784 bytes to 409382... | ||
+ | Wrote 622784 bytes (409382 compressed) at 0x00000000 in 36.1 seconds (effective 137.8 kbit/s)... | ||
+ | Hash of data verified.** | ||
+ | |||
+ | Une fois la mémoire effacée, il faut charger le nouveau firmware. Dans le terminal, assurez-vous que vous êtes dans le dossier bridge et entrez la commande suivante (en remplaçant à nouveau la définition du port par celle de votre choix) : | ||
+ | |||
+ | esptool.py --port / | ||
+ | |||
+ | La sortie du terminal devrait ressembler à ceci : | ||
esptool.py v3.0 | esptool.py v3.0 | ||
Ligne 112: | Ligne 236: | ||
Hash of data verified. | Hash of data verified. | ||
- | Leaving... | + | |
+ | **Leaving... | ||
Verifying just-written flash... | Verifying just-written flash... | ||
(This option is deprecated, flash contents are now always read back after flashing.) | (This option is deprecated, flash contents are now always read back after flashing.) | ||
Ligne 122: | Ligne 247: | ||
During the flash process, there should be an LED flashing on the ESP8266 board as blocks of the firmware are being written. When the process is finished, the LED should stop flashing. If it continues to flash, something happened and you need to start again by erasing the firmware and re-installing it. | During the flash process, there should be an LED flashing on the ESP8266 board as blocks of the firmware are being written. When the process is finished, the LED should stop flashing. If it continues to flash, something happened and you need to start again by erasing the firmware and re-installing it. | ||
- | Now we can move on to making the connections to our Pico. | + | Now we can move on to making the connections to our Pico.** |
- | Part 3 - Connecting the Pico to the ESP8266 | + | Leaving... |
+ | Verifying just-written flash... | ||
+ | (This option is deprecated, flash contents are now always read back after flashing.) | ||
+ | Flash params set to 0x0040 | ||
+ | Verifying 0x980c0 (622784) bytes @ 0x00000000 in flash against firmware-combined.bin... | ||
+ | -- verify OK (digest matched) | ||
+ | Hard resetting via RTS pin... | ||
+ | |||
+ | Pendant le flashage, une LED doit clignoter sur la carte ESP8266 au fur et à mesure que les blocs du firmware sont écrits. Lorsque le processus est terminé, la LED doit cesser de clignoter. Si elle continue à clignoter, quelque chose s'est produit et vous devez recommencer en effaçant le firmware et en le réinstallant. | ||
+ | |||
+ | Nous pouvons maintenant passer à l' | ||
+ | |||
+ | |||
+ | **Part 3 - Connecting the Pico to the ESP8266 | ||
For whatever device you are going to use as the ESP8266 board, you should make sure you download the latest pinout for that board, since the various manufacturers can change the pinouts. In my case, the pinout for the NodeMCU ESP8266 board was found at https:// | For whatever device you are going to use as the ESP8266 board, you should make sure you download the latest pinout for that board, since the various manufacturers can change the pinouts. In my case, the pinout for the NodeMCU ESP8266 board was found at https:// | ||
- | Now be sure to orient the board and the pinout and begin to place your jumpers. Luckily, the data pins on my NodeMCU board are all marked and they match up with the pins for the Mini in the table below. I verified the wires that I connected to the NodeMCU board at least three times then I made the connections to the breadboard that I had the Pico mounted on and verified them again. What can I say? I HATE to blow up boards. Of course, I did this with the boards all unplugged. I’ve copied the table here (left) just to make it easy for you. | + | Now be sure to orient the board and the pinout and begin to place your jumpers. Luckily, the data pins on my NodeMCU board are all marked and they match up with the pins for the Mini in the table below. I verified the wires that I connected to the NodeMCU board at least three times then I made the connections to the breadboard that I had the Pico mounted on and verified them again. What can I say? I HATE to blow up boards. Of course, I did this with the boards all unplugged. I’ve copied the table here (left) just to make it easy for you.** |
- | Host and target must share a common ground. They need not share a common power | + | Partie 3 - Connexion du Pico à l' |
- | source - the order in which they are powered up is not critical. The 5V link enables a USB connection on the host to power the ESP8266. | + | Quel que soit le dispositif que vous allez utiliser comme carte ESP8266, vous devez vous assurer que vous téléchargez le dernier brochage de cette carte, car les différents fabricants peuvent modifier les brochages. Dans mon cas, le pinout de la carte NodeMCU ESP8266 se trouve sur https:// |
+ | |||
+ | Assurez-vous maintenant d' | ||
+ | |||
+ | |||
+ | **Host and target must share a common ground. They need not share a common power source - the order in which they are powered up is not critical. The 5V link enables a USB connection on the host to power the ESP8266. | ||
We will be providing the power for the ESP8266 directly from the Pico. You can see from the wiring diagram on the next page, the 5 volts to power the ESP8266 comes from physical pin 40 – which is VBUS. VBUS provides +5Vdc directly from the Pico’s USB connection with your computer. This is important to remember if you ever want to make this a standalone project. You will have to provide the +5Vdc for the ESP8266 from another source. | We will be providing the power for the ESP8266 directly from the Pico. You can see from the wiring diagram on the next page, the 5 volts to power the ESP8266 comes from physical pin 40 – which is VBUS. VBUS provides +5Vdc directly from the Pico’s USB connection with your computer. This is important to remember if you ever want to make this a standalone project. You will have to provide the +5Vdc for the ESP8266 from another source. | ||
- | So now the hard part is done. | + | So now the hard part is done.** |
+ | L' | ||
+ | Nous allons alimenter l' | ||
+ | Maintenant, le plus dur est fait. | ||
- | Part 4 - The Pico side of things | + | |
+ | **Part 4 - The Pico side of things | ||
Now, we can start to work on the Pico part of the project. There will be two files that we need to load and modify. The first file is net_local.py that is located in the bridge/host folder. You can think of this as your secrets file where you store your network router address, network password, and the location of your broker. Here’s what it looks like (without the comments). See code top right. | Now, we can start to work on the Pico part of the project. There will be two files that we need to load and modify. The first file is net_local.py that is located in the bridge/host folder. You can think of this as your secrets file where you store your network router address, network password, and the location of your broker. Here’s what it looks like (without the comments). See code top right. | ||
- | Set the ssid field to your network name. Change the password to the one you use to connect your computer to the network. Finally, for this test, set the broker field to “test.mosquitto.org”. Save the file. It should look something like the code shown middle right. | + | Set the ssid field to your network name. Change the password to the one you use to connect your computer to the network. Finally, for this test, set the broker field to “test.mosquitto.org”. Save the file. It should look something like the code shown middle right.** |
+ | |||
+ | Partie 4 - Du côté du Pico | ||
+ | |||
+ | Maintenant, nous pouvons commencer à travailler sur la partie Pico du projet. Il y a deux fichiers que nous devons charger et modifier. Le premier fichier est net_local.py et se trouve dans le dossier bridge/ | ||
+ | |||
+ | Définissez le champ ssid avec le nom de votre réseau. Remplacez le mot de passe par celui que vous utilisez pour connecter votre ordinateur au réseau. Enfin, pour ce test, définissez le champ broker à « test.mosquitto.org ». Sauvegardez le fichier. Il devrait ressembler au code affiché au milieu à droite. | ||
- | Now you need to load the file pico_simple.py from the bridge/ | + | **Now you need to load the file pico_simple.py from the bridge/ |
First the import section. There is only one additional import needed here… | First the import section. There is only one additional import needed here… | ||
Ligne 164: | Ligne 318: | ||
The next line doesn’t get changed. | The next line doesn’t get changed. | ||
- | qos = 1 # for test all messages have the same qos. | + | qos = 1 # for test all messages have the same qos.** |
- | Next, we will add a function to read the Pico internal temperature sensor (next page, bottom left). It’s almost the same as the test program we did in part 1 above. The only differences are that we are adding a call to printline, I’ve commented the 2 second sleep statement since we don’t need that and then the return temperaturef to the calling function. If you want to send out temperatures in Celsius, then return the variable temperature. | + | Maintenant vous devez charger le fichier pico_simple.py depuis le dossier bridge/ |
- | The publish function is where we actually send data out to the MQTT server. There are only two lines that need to be added. The first line prints the fact that we are sending something out and the second line actually publishes the internal temperature. Notice that this line is all one line (right). | + | D' |
- | There is one point that I want to make here. The line above – await asyncio.sleep(10) – sets the delay between the publish messages. If you want to speed it up, then set the sleep value to less than 10. If you want a longer delay between the publish messages, make it a bigger value. | + | import uasyncio asyncio |
+ | |||
+ | from pbmqtt import MQTTlink | ||
+ | |||
+ | import hw_pico as hardware # Définitions des broches. Pulsation de la LED du Pico. | ||
+ | |||
+ | import net_local # Identifiants WiFi | ||
+ | |||
+ | from utime import localtime, gmtime, time | ||
+ | |||
+ | |||
+ | La ligne suivante ne sera pas modifiée. | ||
+ | |||
+ | qos = 1 # pour tester que tous les messages ont le même qos. | ||
+ | |||
+ | |||
+ | **Next, we will add a function to read the Pico internal temperature sensor (next page, bottom left). It’s almost the same as the test program we did in part 1 above. The only differences are that we are adding a call to printline, I’ve commented the 2 second sleep statement since we don’t need that and then the return temperaturef to the calling function. If you want to send out temperatures in Celsius, then return the variable temperature. | ||
+ | |||
+ | The publish function is where we actually send data out to the MQTT server. There are only two lines that need to be added. The first line prints the fact that we are sending something out and the second line actually publishes the internal temperature. Notice that this line is all one line (right).** | ||
+ | |||
+ | Ensuite, nous allons ajouter une fonction pour lire le capteur de température interne du Pico (page suivante, en bas à gauche). C'est presque la même chose que le programme de test que nous avons fait dans la partie 1 ci-dessus. Les seules différences sont que nous ajoutons un appel à printline, que j'ai commenté l' | ||
+ | |||
+ | La fonction publish est l' | ||
+ | |||
+ | |||
+ | **There is one point that I want to make here. The line above – await asyncio.sleep(10) – sets the delay between the publish messages. If you want to speed it up, then set the sleep value to less than 10. If you want a longer delay between the publish messages, make it a bigger value. | ||
MQTTlink.will(' | MQTTlink.will(' | ||
Ligne 182: | Ligne 361: | ||
finally: | finally: | ||
- | | + | |
+ | |||
+ | Il y a un point que je veux souligner ici. La ligne ci-dessus - await asyncio.sleep(10) - définit le délai entre les diffusions des messages. Si vous voulez accélérer le processus, fixez la valeur de sleep à moins de 10. Si vous voulez un délai plus long entre les diffusions, fixez une valeur plus grande. | ||
- | When you run the program, you should see the onboard LED flash about every second, and in the shell window you should see… | + | MQTTlink.will(' |
+ | |||
+ | mqtt_link = MQTTlink(hardware.d, | ||
+ | |||
+ | Pour essayer : | ||
+ | |||
+ | | ||
+ | |||
+ | enfin : | ||
+ | |||
+ | | ||
+ | |||
+ | |||
+ | **When you run the program, you should see the onboard LED flash about every second, and in the shell window you should see : | ||
>>> | >>> | ||
Ligne 203: | Ligne 397: | ||
13:52:07 80.67992 | 13:52:07 80.67992 | ||
Sending 3 | Sending 3 | ||
- | 13:52:18 78.9946 | + | 13:52:18 78.9946** |
+ | |||
+ | Quand vous lancez le programme, vous devriez voir clignoter la LED de la carte chaque seconde et dans la fenêtre du shell, ceci : | ||
+ | |||
+ | >>> | ||
+ | initiator | ||
+ | initiator | ||
+ | initiator | ||
+ | Starting... | ||
+ | 13:52:01 Status: | ||
+ | 13:52:01 Status: | ||
+ | 13:52:06 Status: | ||
+ | 13:52:07 Status: | ||
+ | 13:52:07 Status: | ||
+ | About to run user program. | ||
+ | cbnet: network is up | ||
+ | 13:52:07 Status: | ||
+ | 13:52:07 Status: | ||
+ | Sending 2 | ||
+ | 13:52:07 80.67992 | ||
+ | Sending 3 | ||
+ | 13:52:18 78.994 | ||
- | If you want to verify the fact that you are actually sending the messages out to the Broker, open a terminal on your computer (assuming you’ve installed the mosquitto packages) and type: | + | **If you want to verify the fact that you are actually sending the messages out to the Broker, open a terminal on your computer (assuming you’ve installed the mosquitto packages) and type: |
mosquitto_sub -h test.mosquitto.org -t InternalTemperature | mosquitto_sub -h test.mosquitto.org -t InternalTemperature | ||
Ligne 220: | Ligne 436: | ||
One word of warning. I’ve noticed that every time I have to stop the program to make a change or just to restart it, I have to unplug the Pico, wait a few seconds, then plug it back in. I’m not quite sure why. | One word of warning. I’ve noticed that every time I have to stop the program to make a change or just to restart it, I have to unplug the Pico, wait a few seconds, then plug it back in. I’m not quite sure why. | ||
- | I’d suggest that you consider setting up a MQTT server on another machine, like a Raspberry Pi. It’s simple to do. I previously wrote a three-part article in Full Circle issues 132, 133 and 134 which will get you going if you need it. | + | I’d suggest that you consider setting up a MQTT server on another machine, like a Raspberry Pi. It’s simple to do. I previously wrote a three-part article in Full Circle issues 132, 133 and 134 which will get you going if you need it.** |
- | BONUS Part 6 - Monitoring your MQTT Communications | + | Si vous voulez vérifier le fait que vous envoyez réellement les messages au Broker, ouvrez un terminal sur votre ordinateur (en supposant que vous avez installé les paquets mosquitto) et tapez : |
- | Yes, I’m providing a bonus part this month. I’m going to explain how to get and use a fantastic program called MQTT Explorer to monitor the communications between your Pico and the MQTT Server, wherever it is located. | + | mosquitto_sub -h test.mosquitto.org -t InternalTemperature |
+ | Rien ne se passera avant que vous ne commenciez réellement à envoyer, mais lorsque vous le ferez, voici à quoi cela ressemblera. | ||
- | You can find it at http:// | + | greg@earth: |
+ | 79.83727 | ||
+ | 78.15195 | ||
+ | 78.9946 | ||
+ | 78.9946 | ||
+ | 78.9946 | ||
+ | |||
+ | Un mot d' | ||
+ | |||
+ | Je vous suggère d' | ||
+ | |||
+ | |||
+ | **BONUS Part 6 - Monitoring your MQTT Communications | ||
+ | |||
+ | Yes, I’m providing a bonus part this month. I’m going to explain how to get and use a fantastic program called MQTT Explorer to monitor the communications between your Pico and the MQTT Server, wherever it is located. | ||
+ | |||
+ | You can find it at http:// | ||
It’s really easy to get set up and start monitoring your communications to the MQTT server. Since all we are sending is temperature values, you can also see the data as a graph. | It’s really easy to get set up and start monitoring your communications to the MQTT server. Since all we are sending is temperature values, you can also see the data as a graph. | ||
- | You can find the code we’ve written and modified at my github repository at https:// | + | You can find the code we’ve written and modified at my github repository at https:// |
- | Final Thoughts | + | BONUS Partie 6 - Surveillance de vos communications MQTT |
+ | |||
+ | Oui, je vous propose une partie bonus ce mois-ci. Je vais vous expliquer comment obtenir et utiliser un programme fantastique appelé MQTT Explorer pour surveiller les communications entre votre Pico et le serveur MQTT, où qu'il se trouve. | ||
+ | |||
+ | Vous pouvez le trouver à l' | ||
+ | |||
+ | Il est très facile de l' | ||
+ | |||
+ | Vous pouvez trouver le code que nous avons écrit et modifié sur mon dépôt github à l' | ||
+ | |||
+ | |||
+ | **Final Thoughts | ||
Just so you know, I’m going to put the RPi Pico “on pause” so to speak, and look at another popular microcontroller, | Just so you know, I’m going to put the RPi Pico “on pause” so to speak, and look at another popular microcontroller, | ||
• The first has the molex on both ends, which makes quick work of connecting I2C devices to the Thing Plus (https:// | • The first has the molex on both ends, which makes quick work of connecting I2C devices to the Thing Plus (https:// | ||
- | • The other has the molex plug on one end and regular male pins for use on a breadboard (https:// | + | • The other has the molex plug on one end and regular male pins for use on a breadboard (https:// |
- | We’ll be coming back to the RPi Pico in a couple of months, since I’ve got LOTS of goodies that can be done with the Pico. | + | Réflexions finales |
+ | |||
+ | Pour votre information, | ||
+ | ••Le premier a une prise molex aux deux extrémités, | ||
+ | ••L' | ||
+ | |||
+ | |||
+ | **We’ll be coming back to the RPi Pico in a couple of months, since I’ve got LOTS of goodies that can be done with the Pico. | ||
Also, I’m working on a list of “important must have” sensors and displays along with sourcing and packaging. I’ll try to get that started for you in next month’s article as well. | Also, I’m working on a list of “important must have” sensors and displays along with sourcing and packaging. I’ll try to get that started for you in next month’s article as well. | ||
Ligne 245: | Ligne 496: | ||
Well, I’ve taken up way too many pages of the magazine this month, so I'm going to wish you luck and happy times. | Well, I’ve taken up way too many pages of the magazine this month, so I'm going to wish you luck and happy times. | ||
- | Until next time, as always; stay safe, healthy, positive and creative! | + | Until next time, as always; stay safe, healthy, positive and creative!** |
+ | |||
+ | Nous reviendrons au RPi Pico dans quelques mois, car j'ai beaucoup de choses à faire avec le Pico. | ||
+ | |||
+ | Je travaille également sur une liste de capteurs et d' | ||
+ | |||
+ | J'ai occupé beaucoup trop de pages du magazine ce mois-ci, je vais donc vous souhaiter bonne chance et beaucoup de bons moments. | ||
+ | |||
+ | Jusqu' | ||
issue169/micro-ci_micro-la.1622526155.txt.gz · Dernière modification : 2021/06/01 07:42 de d52fr