TELNET TO UART using STM32F103C8 generic board and ENC28J60. It is a very initial version with just for test program. Uses UIPEthernet Library courtesy of Zoltan hudak and Norbert Truchsess. Thanks

Dependencies:   UIPEthernet mbed-STM32F103C8T6 mbed Adafruit_GFX

Fork of WebSwitch_ENC28J60 by Zoltan Hudak

Files at this revision

API Documentation at this revision

Comitter:
neutron_striker
Date:
Mon Dec 05 18:30:59 2016 +0000
Parent:
7:df33cd7ec9de
Commit message:
In this version OLED display has been added to display IP address assigned via DHCP

Changed in this revision

Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r df33cd7ec9de -r bb8aa896c7f5 Adafruit_GFX.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Mon Dec 05 18:30:59 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/neutron_striker/code/Adafruit_GFX/#09b3b315fc6d
diff -r df33cd7ec9de -r bb8aa896c7f5 main.cpp
--- a/main.cpp	Thu Dec 01 11:42:27 2016 +0000
+++ b/main.cpp	Mon Dec 05 18:30:59 2016 +0000
@@ -6,6 +6,9 @@
  * The example is based on the Tuxgraphics Web Switch <http://www.tuxgraphics.org/>.
  */
  
+ //data transmission from telnet to UART is very smooth but from uart to telnet is not good when I pasted a text of one page all i got was 
+ //garbage.
+ 
 #define TARGET_STM32F103C8T6  1     // uncomment this line when using STM32F103C8T6 boards!                                    
 
 #if defined(TARGET_STM32F103C8T6)
@@ -24,10 +27,22 @@
 #include "UIPClient.h"
 #include "string"
 
+
 using namespace     std;
 
 Serial pc(PA_9, PA_10); // tx, rx
 
+
+/////////OLED STUFF//////////////////////////////
+#include "Adafruit_SSD1306.h"
+//I2C obj(sda,scl);
+I2C i2c2(PB_11,PB_10); //read more info about SSD1306 trouble in "SSD1306_test" project. and I don't know why but using PB_8 and PB_9 for I2C screws up SPI or atleast the ENC28J60, need to find out maybe from STM32F103 DATASHEET.
+//Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 32, uint8_t rawWidth = 128)
+Adafruit_SSD1306_I2c lcd(i2c2,PB_13,0x78,64,128); //also mbed takes i2c address in 8bit mode, any unused pin can be given as "reset" pin.
+
+/////////////////////////////////////////////////////
+
+
 #define DHCP    1   // if you'd like to use static IP address comment out this line 
 
 // UIPEthernet is the name of a global instance of UIPEthernetClass.
@@ -59,7 +74,8 @@
 const uint8_t       MY_MAC[6] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x06 };
 const uint16_t      MY_PORT = 23;           // for TELNET connection
 EthernetServer      server = EthernetServer(MY_PORT);
-EthernetClient clients[4];
+#define MAX_NUM_CLIENT 1
+EthernetClient clients[MAX_NUM_CLIENT];
 
 void loop();
 
@@ -70,6 +86,10 @@
     pc.baud(57600);
    // pc.format(8,SerialBase::Even,1); 
     pc.printf("Program begins\r\n");
+    //lcd.printf("%ux%u OLED Display\r\n", lcd.width(), lcd.height());
+    lcd.printf("Telnet Server\n");
+    lcd.printf("Waiting for DHCP..\n");
+    lcd.display();
 
 #if defined(DHCP)
     pc.printf("Searching for DHCP server..\r\n");
@@ -85,10 +105,17 @@
     UIPEthernet.begin(MY_MAC, MY_IP);
 #endif
     IPAddress   localIP = UIPEthernet.localIP();
-    pc.printf("Type ");
-    for(uint8_t i = 0; i < 3; i++)
+    pc.printf("DHCP assigned IP : ");
+    //lcd.clearDisplay();
+    //lcd.setTextCursor(0,0);
+    lcd.setTextSize(2);
+    lcd.printf("IP:");
+    for(uint8_t i = 0; i < 4; i++){
         pc.printf("%d.", localIP[i]);
-    pc.printf("%d/secret/ into your web browser and hit ENTER\r\n", localIP[3]);
+        lcd.printf("%d.", localIP[i]);
+        }
+    lcd.display();
+    pc.printf("Starting Telnet server");
     server.begin();
     while(1) 
     {
@@ -107,7 +134,7 @@
   if (client) {
 
     bool newClient = true;
-    for (byte i=0;i<4;i++) {
+    for (byte i=0;i<MAX_NUM_CLIENT;i++) {
       //check whether this client refers to the same socket as one of the existing instances:
       if (clients[i]==client) {
         newClient = false;
@@ -117,7 +144,7 @@
 
     if (newClient) {
       //check which of the existing clients can be overridden:
-      for (byte i=0;i<4;i++) {
+      for (byte i=0;i<MAX_NUM_CLIENT;i++) {
         if (!clients[i] && clients[i]!=client) {
           clients[i] = client;
           // clead out the input buffer:
@@ -138,7 +165,7 @@
       // read the bytes incoming from the client:
       char thisChar = client.read();
       // echo the bytes back to all other connected clients:
-      for (byte i=0;i<4;i++) {
+      for (byte i=0;i<MAX_NUM_CLIENT;i++) {
         if (clients[i] && clients[i]!=client) {
           clients[i].write(thisChar);
         }
@@ -147,7 +174,7 @@
       pc.putc(thisChar);
     }
   }
-  for (byte i=0;i<4;i++) {
+  for (byte i=0;i<MAX_NUM_CLIENT;i++) {
     if (!(clients[i].connected())) {
       // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
       clients[i].stop();
@@ -165,10 +192,10 @@
     */
     char data_from_uart = pc.getc();
     //push UART data to all connected telnet clients
-    for(uint8_t i = 0; i < 4; i++){
+    for(uint8_t i = 0; i < MAX_NUM_CLIENT; i++){
       if (clients[i] && clients[i].connected()){
         clients[i].write(data_from_uart);
-        wait(0.001);
+        //wait(0.001);
       }
     }
   }