I put together a simple hardware
atmega328p – executes programm
enc28j60 – ethernet
programmed it using C code:
…
// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
Stash stash;
char website[] PROGMEM = “vm37.dbweb.ee”;
#define PATH “”
#define VARIABLE “test”
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(“>>>”);
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println(“…”);
}
void setup () {
Serial.begin(57600);
Serial.println(“\n[webClient]”);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( “Failed to access Ethernet controller”);
if (!ether.dhcpSetup())
Serial.println(“DHCP failed”);
ether.hisport = 8080;
ether.printIp(“IP: “, ether.myip);
ether.printIp(“GW: “, ether.gwip);
ether.printIp(“DNS: “, ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println(“DNS failed”);
ether.printIp(“SRV: “, ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 10000;
byte sd = stash.create();
stash.print(“{\”messages\”: [{\”value\”:{\”key\”:\”Margusja\”}}]}”);
stash.print(VARIABLE);
stash.print(“&action=Submit”);
stash.save();
// generate the header with payload – note that the stash size is used,
// and that a “stash descriptor” is passed in as argument using “$H”
Stash::prepare(PSTR(“POST /topics/kafkademo1 HTTP/1.1” “\r\n”
“Host: vm37.dbweb.ee:8080” “\r\n”
//”User-Agent: margusja” “\r\n”
“Accept: */*” “\r\n”
“Content-Type: application/json” “\r\n”
“Content-Length: $D” “\r\n”
“\r\n”
“$H”),
website, PSTR(PATH), website, stash.size(), sd);
// send the packet – this also releases all stash buffers once done
ether.tcpSend();
}
}
…
Uploaded code to MC and powered it up.
And after it got data from DHCP I saw nice picture – it sends data into my kafka queue