Sono sono stati utilizzati
Arduino UNO
Shield Ethernet
Bridge Ethernet-WiFi Vonets
Display LCD 1602 (modalita' I2C)
Il montaggio e' piuttosto semplice.
Il bridge e' stato usato per dare capacita' wireless all'Arduino senza utilizzare il costoso shield apposito
Il montaggio dei cavi del display e' spiegato in questo post
Di fatto l'Arduino efffettua una richiesta ad uno script Php che e' su server remoto, legge e mette a display il risultato (il tutto e' basato sull'Esempio WebClient della libreria Ethernet di Arduino)
-------------------------------------
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
String currentLine = "";
String fbcount = "";
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "m.xxxx.unifi.it";
IPAddress ip(192,168,0,177);
EthernetClient client;
void setup() {
lcd.init();
lcd.backlight();
lcd.print("Facebook");
lcd.setCursor(0,1);
lcd.print("Like counter");
Serial.begin(9600);
while (!Serial) {
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
client.println("GET /xxxxxxx/like3.php HTTP/1.1");
client.println("Connection: close");
client.println();
}
else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
//Serial.print(c);
currentLine += c;
if ( currentLine.startsWith("Like:")) {
fbcount += c;
Serial.println(fbcount);
lcd.clear();
lcd.print("Like"+fbcount);
}
if (c == '\n') {
currentLine = "";
fbcount = "";
}
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
while(true);
}
}
--------------------------------------------------
Script PHP
--------------------------------------------------
<?
require_once '../src/facebook.php';
$appid = '673135956047578';
$appsecret = 'dde6cfb07dbb769c7efe949c20afd73d';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => false,
));
$like = array(
'method' => 'fql.query',
'query' => 'select fan_count from page where page_id=266068113416863;'
);
$result = $facebook->api($like);
print "Like:".$result[0]['fan_count'];
?>
Script PHP
--------------------------------------------------
<?
require_once '../src/facebook.php';
$appid = '673135956047578';
$appsecret = 'dde6cfb07dbb769c7efe949c20afd73d';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => false,
));
$like = array(
'method' => 'fql.query',
'query' => 'select fan_count from page where page_id=266068113416863;'
);
$result = $facebook->api($like);
print "Like:".$result[0]['fan_count'];
?>