Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
- byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
- EthernetClient client;
- /**
- * help functions declaration
- */
- void get_ip(byte ip[4]);
- void dump_ip(byte ip[4]);
- void initEthernetConfig(byte ip[]);
- void getSerialText();
- void sendOvertEthernet();
- void sendOverSerial();
- bool flagIp = false;
- bool flagEth = false;
- String readString;
- /**
- * setup && loop
- */
- void setup() {
- Serial.begin(9600);
- }
- void loop()
- {
- byte ip[4];
- while (Serial.available()) {
- delay(3); //delay to allow buffer to fill
- if (Serial.available() >0) {
- char c = Serial.read(); //gets one byte from serial buffer
- readString += c; //makes the string readString
- }
- }
- if (readString == "ip") {
- flagIp = true;
- Serial.print("String with IP");
- get_ip(ip);
- dump_ip(ip);
- Serial.print("Initialize IP");
- initEthernetConfig(ip);
- }
- if (readString == "serial") {
- flagEth = true;
- initSerialConfig();
- }
- }
- /**
- * help function implementation
- */
- void get_ip(byte ip[4])
- {
- for (byte i = 0; i < 4; ++i) {
- while (Serial.available() <= 0) {};
- ip[i] = (byte)Serial.parseInt();
- if (i < 3) { Serial.read(); } // throw away dot
- }
- };
- void dump_ip(byte ip[4]) {
- for (byte i = 0; i < 4; ++i) {
- Serial.print(ip[i]);
- if (i < 3) {
- Serial.print('.');
- }
- else {
- Serial.println();
- }
- }
- };
- void initSerialConfig() {
- Serial.println("Init serial");
- }
- void initEthernetConfig(byte ip[])
- {
- Ethernet.begin(mac, ip);
- Serial.println("Init ethernet config");
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement