Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3.  
  4. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  5. byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
  6. EthernetClient client;
  7.  
  8. /**
  9. * help functions declaration
  10. */
  11.  
  12. void get_ip(byte ip[4]);
  13. void dump_ip(byte ip[4]);
  14. void initEthernetConfig(byte ip[]);
  15. void getSerialText();
  16. void sendOvertEthernet();
  17. void sendOverSerial();
  18. bool flagIp = false;
  19. bool flagEth = false;
  20. String readString;
  21. /**
  22. * setup && loop
  23. */
  24.  
  25. void setup() {
  26. Serial.begin(9600);
  27. }
  28.  
  29. void loop()
  30. {
  31. byte ip[4];
  32.  
  33. while (Serial.available()) {
  34. delay(3); //delay to allow buffer to fill
  35. if (Serial.available() >0) {
  36. char c = Serial.read(); //gets one byte from serial buffer
  37. readString += c; //makes the string readString
  38. }
  39. }
  40. if (readString == "ip") {
  41. flagIp = true;
  42. Serial.print("String with IP");
  43. get_ip(ip);
  44. dump_ip(ip);
  45.  
  46. Serial.print("Initialize IP");
  47. initEthernetConfig(ip);
  48. }
  49. if (readString == "serial") {
  50. flagEth = true;
  51. initSerialConfig();
  52. }
  53.  
  54.  
  55.  
  56. }
  57.  
  58. /**
  59. * help function implementation
  60. */
  61.  
  62. void get_ip(byte ip[4])
  63. {
  64. for (byte i = 0; i < 4; ++i) {
  65. while (Serial.available() <= 0) {};
  66. ip[i] = (byte)Serial.parseInt();
  67. if (i < 3) { Serial.read(); } // throw away dot
  68. }
  69. };
  70.  
  71. void dump_ip(byte ip[4]) {
  72. for (byte i = 0; i < 4; ++i) {
  73. Serial.print(ip[i]);
  74. if (i < 3) {
  75. Serial.print('.');
  76. }
  77. else {
  78. Serial.println();
  79. }
  80. }
  81. };
  82.  
  83. void initSerialConfig() {
  84. Serial.println("Init serial");
  85. }
  86. void initEthernetConfig(byte ip[])
  87. {
  88. Ethernet.begin(mac, ip);
  89. Serial.println("Init ethernet config");
  90. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement