{"id":2767,"date":"2015-10-14T08:30:41","date_gmt":"2015-10-14T07:30:41","guid":{"rendered":"http:\/\/telefab.fr\/?p=2767"},"modified":"2026-04-30T17:33:59","modified_gmt":"2026-04-30T15:33:59","slug":"agregateur-flux-rss","status":"publish","type":"projet","link":"https:\/\/hub.imt-atlantique.fr\/fablab\/projet\/agregateur-flux-rss\/","title":{"rendered":"Agr\u00e9gateur flux RSS"},"content":{"rendered":"<p>Ce projet a \u00e9t\u00e9 r\u00e9alis\u00e9 dans de cadre d&rsquo;une validation du mooc \u00ab\u00a0La fabrication num\u00e9rique\u00a0\u00bb.<br \/>\nApr\u00e8s avoir suivi la formation en ligne, j&rsquo;ai con\u00e7u un projet d&rsquo;agr\u00e9gateur RSS avec Arduino.<br \/>\nJeremy Sfez<\/p>\n<p><strong>Pr\u00e9sentation du projet<\/strong><\/p>\n<p>Le dispositif\u00a0r\u00e9cup\u00e8re les informations sur le flux RSS de \u00ab\u00a0Googles news\u00a0\u00bb.\u00a0Apr\u00e8s avoir pars\u00e9 le flux (biblioth\u00e8que \u00ab\u00a0TextFinder\u00a0\u00bb), il affiche le premier titre sur un l&rsquo;\u00e9cran LCD 2&#215;16. Quand l&rsquo;utilisateur appui sur le bouton, le titre suivant est affich\u00e9.<\/p>\n<p>N&rsquo;ayant pas \u00e0 ma disposition de carte ethernet, le t\u00e9l\u00e9chargement du flux RSS est\u00a0fait par\u00a0script python. Le programme communique directement avec le dispositif sur le port s\u00e9rie gr\u00e2ce la biblioth\u00e8que \u00ab\u00a0serial\u00a0\u00bb.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Pr\u00e9sentation du dispositif<\/strong><\/p>\n<figure id=\"attachment_2768\" aria-describedby=\"caption-attachment-2768\" style=\"width: 248px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Flux-RSS-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2768\" src=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Flux-RSS-1-248x300.jpg\" alt=\"Photo du dispositif 1\" width=\"248\" height=\"300\" \/><\/a><figcaption id=\"caption-attachment-2768\" class=\"wp-caption-text\">Le dispositif attend le xml de google news<\/figcaption><\/figure>\n<figure id=\"attachment_2769\" aria-describedby=\"caption-attachment-2769\" style=\"width: 225px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Flux-RSS-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2769\" src=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Flux-RSS-2-225x300.jpg\" alt=\"Photo du dispositif 2\" width=\"225\" height=\"300\" \/><\/a><figcaption id=\"caption-attachment-2769\" class=\"wp-caption-text\">Le dispositif affiche un des titres de l&rsquo;actualit\u00e9<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p><strong>Pr\u00e9sentation de l&rsquo;algorithme<\/strong><\/p>\n<figure id=\"attachment_2772\" aria-describedby=\"caption-attachment-2772\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Capture-d\u2019\u00e9cran-2015-10-05-\u00e0-12.46.07.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-2772 size-large\" src=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Capture-d\u2019\u00e9cran-2015-10-05-\u00e0-12.46.07-1024x685.png\" alt=\"Pr\u00e9sentation de l'algorithme\" width=\"1024\" height=\"685\" \/><\/a><figcaption id=\"caption-attachment-2772\" class=\"wp-caption-text\">Algorithme flux RSS<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p><strong>Mat\u00e9riel utilis\u00e9<\/strong><\/p>\n<ul>\n<li>1 cartes Arduino Uno<\/li>\n<li>1 \u00e9cran LCD 2&#215;16<\/li>\n<li>1 breadboard<\/li>\n<li>1 bouton<\/li>\n<li>1 r\u00e9sistance de 560 Ohms<\/li>\n<li>potentiom\u00e8tre de 10 kOhms (pour r\u00e9gler le contraste de l&rsquo;\u00e9cran)<\/li>\n<li>fils de connexions<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Sch\u00e9ma du montage<\/strong><\/p>\n<figure id=\"attachment_2771\" aria-describedby=\"caption-attachment-2771\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Capture-d\u2019\u00e9cran-2015-10-05-\u00e0-12.24.53.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2771\" src=\"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-content\/uploads\/archives\/2015\/10\/Capture-d\u2019\u00e9cran-2015-10-05-\u00e0-12.24.53-300x274.png\" alt=\"Sch\u00e9ma flux RSS\" width=\"300\" height=\"274\" \/><\/a><figcaption id=\"caption-attachment-2771\" class=\"wp-caption-text\">Sch\u00e9ma du montage<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Code Arduino<br \/>\n<code>\/\/Biblioth\u00e8ques<br \/>\n#include &lt;LiquidCrystal.h&gt;<br \/>\n#include &lt;TextFinder.h&gt;<\/code><\/p>\n<pre>LiquidCrystal lcd(12, 11, 4, 5, 6, 7); \/\/Variables pour ecran LCD\nTextFinder finder(Serial); \/\/Variables pour parser le XML<\/pre>\n<pre>char actualite[5][320];\nint nbrArticlesRecu;\nint nbrArticlesMax=5;\nint t[] = {0, 0, 0, 0, 0};\nint tmp = 0;\nint numArticle = 0;\nint cursor = 0;\nint nbrAppelAffichage = 0;<\/pre>\n<pre>\/\/Variables pour le bouton\nconst int buttonPin = 2;\nint buttonState = 0;\nint lastButtonState = 0;<\/pre>\n<pre>void setup() {\n  \/\/ delay(2000);\n  Serial.begin(115200);\n  nbrArticlesRecu=0; \/\/Initialisation parseur\n  nbrAppelAffichage=0;\n  pinMode(buttonPin, INPUT); \/\/Initialise bouton comme input\n \n  \/\/Initialise ecran LCD\n  lcd.begin(16, 2); \n  lcd.clear();\n  lcd.setCursor(0,0);\n  lcd.print(\"Download news...\");\n  lcd.setCursor(0,1);\n  lcd.print(\"Launch file .py\");\n  Serial.println(\"Debut du programme\");\n}<\/pre>\n<pre>void loop(){\n  if(nbrArticlesRecu&lt;nbrArticlesMax){ \/\/ R\u00e9cup\u00e9ration du flux RSS google news\n    \/\/ Le XML est parcouru pour r\u00e9cup\u00e9rer les titres des articles \u00e0 une \n   if((t[nbrArticlesRecu]=finder.getString(\"&lt;item&gt;&lt;title&gt;\",\"&lt;\/title&gt;\",actualite[nbrArticlesRecu],320))&gt;0){\n     nbrArticlesRecu=nbrArticlesRecu+1; \n   }\n   delay(50);\n  }\n  else{\n    afficherMessage2(actualite[numArticle], t[numArticle], nbrAppelAffichage);\n    nbrAppelAffichage++;\n    delay(4000);<\/pre>\n<pre>    buttonState = digitalRead(buttonPin);\n    if (buttonState != lastButtonState) {\n      if (buttonState == HIGH) {\n        numArticle=(numArticle+1)%nbrArticlesMax;\n        nbrAppelAffichage=0;\n        Serial.println(\" bouton \");\n      }\n      delay(50);\n    }\n    lastButtonState = buttonState;\n  }\n}<\/pre>\n<pre>void afficherMessage2(char* message, int taille, int numAppel){\n  int nombreEcran = (taille-1)\/32 + 1;\n  \/\/ Serial.println(numAppel);\n  int choixEcran = numAppel%nombreEcran;\n  int pointeurMsg = choixEcran*32;\n  for(int i=0;i&lt;16;i++){\n    lcd.setCursor(i,0);\n    if(pointeurMsg+i&lt;taille) lcd.print(message[pointeurMsg+i]);\n    else lcd.print(\" \");\n    lcd.setCursor(i,1);\n    if(pointeurMsg+16+i&lt;taille) lcd.print(message[pointeurMsg+16+i]);\n    else lcd.print(\" \");\n  }\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Code Python<\/strong><code><br \/>\n#!\/usr\/bin\/python<\/code><\/p>\n<p>import serial<br \/>\nimport unicodedata<br \/>\nimport urllib2<\/p>\n<p>ser = serial.Serial(&lsquo;\/dev\/tty.usbmodem1411&rsquo;, 115200);<\/p>\n<p># Recuperation du flux rss google news<br \/>\ndata = urllib2.urlopen(\u00ab\u00a0http:\/\/news.google.fr\/?output=rss\u00a0\u00bb).read();<br \/>\n# Overture d&rsquo;un fichier tampon<br \/>\nf = open(&lsquo;Flux RSS.txt&rsquo;, &lsquo;r+&rsquo;);<\/p>\n<p># Ecriture dans le fichier des donnes recu<br \/>\nf.write(data);<\/p>\n<p>s1 = unicode(data,&rsquo;utf-8&prime;);<br \/>\ndata = unicodedata.normalize(&lsquo;NFD&rsquo;, s1).encode(&lsquo;ascii&rsquo;, &lsquo;ignore&rsquo;);<br \/>\ndata = data.replace(\u00ab\u00a0&lsquo;\u00a0\u00bb,\u00a0\u00bb&lsquo;\u00a0\u00bb);<br \/>\nser.write(data);<\/p>\n","protected":false},"author":1,"featured_media":2772,"parent":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"footnotes":""},"categories":[28,20],"type_projet":[],"class_list":["post-2767","projet","type-projet","status-publish","has-post-thumbnail","hentry","category-blog","category-projets"],"acf":{"objectifs":"","categorie":false,"fichiers_associes":null},"_links":{"self":[{"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/projet\/2767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/projet"}],"about":[{"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/types\/projet"}],"author":[{"embeddable":true,"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/projet\/2767\/revisions"}],"predecessor-version":[{"id":10512,"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/projet\/2767\/revisions\/10512"}],"wp:attachment":[{"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/media?parent=2767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/categories?post=2767"},{"taxonomy":"type_projet","embeddable":true,"href":"https:\/\/hub.imt-atlantique.fr\/fablab\/wp-json\/wp\/v2\/type_projet?post=2767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}