Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ニコニコ動画新着動画表示器
#include "mbed.h"
#include "EthernetInterface.h"
#include "GraphicOLED.h"
#include <string>
const string SERVER_HOST = "your-app.herokuapp.com";
const int SERVER_PORT = 80;
const int CATEGORY_NUM = 28;
const string NICO_CATEGORIES[CATEGORY_NUM] = {
"ent", "music", "sing", "play", "dance",
"vocaloid", "nicoindies", "animal", "cooking", "nature",
"travel", "sport", "lecture", "drive", "history",
"science", "tech", "handcraft", "make", "politics",
"anime", "game", "toho", "imas", "radio",
"draw", "other", "diary"
};
EthernetInterface eth;
GraphicOLED oled(p24, p26, p27, p28, p21, p22);
string access_api(const string host, const int port, string path)
{
TCPSocketConnection sock;
sock.connect(host.c_str(), port);
char http_cmd[256];
sprintf(http_cmd, "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: close\r\n\r\n", path.c_str(), host.c_str());
//printf("Request:\r\n%s\r\n", http_cmd);
sock.send_all(http_cmd, sizeof(http_cmd)-1);
char buffer[300];
int ret;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
if (ret <= 0)
break;
buffer[ret] = '\0';
//printf("Received %d chars from server:\r\n%s\r\n", ret, buffer);
}
sock.close();
return string(buffer);
}
int main()
{
string response, response_body;
oled.cls();
oled.printf("Hello world!\r\n");
wait(5.0);
eth.init();
eth.connect();
wait(5.0);
oled.cls();
oled.printf("IP Address: %s\r\n", eth.getIPAddress());
while(1){
for(int i=0;i<CATEGORY_NUM;i++){
response = access_api(SERVER_HOST, SERVER_PORT, "/" + NICO_CATEGORIES[i]);
response_body = response.substr((int)response.find("\r\n\r\n") + 1);
oled.cls();
oled.printf("%54.54s", response_body.c_str());
wait(8.0);
}
}
//eth.disconnect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.