Mearm colorsorting with web application

Dependencies:   TCS3200

main.cpp

Committer:
pierre11
Date:
2017-12-14
Revision:
5:36f1e4e1a427
Parent:
4:62b6eaf030ab
Child:
6:60ab0d214512

File content as of revision 5:36f1e4e1a427:

//#if !FEATURE_LWIP
 //   #error [NOT_SUPPORTED] LWIP not supported for this target
//#endif

#include "mbed.h"
#include "EthernetInterface.h"
#include "TCPServer.h"
#include "TCPSocket.h"
#include "Servo.h"
uint8_t http[1024];
uint8_t httpr[1024]={200,200};
uint8_t httpr1[300]={2,2,2,2};
//static void SendWebPage( float ,float ,float , float );

 
                     

int main()
{
    Servo Servo1(PD_13);
 Servo Servo2(PD_12);
 Servo Servo3(PD_14);
 Servo Servo4(PD_15);
 
  Servo1.Enable(1500,20000);
  Servo2.Enable(1500,20000);
  Servo3.Enable(1500,20000);
    
    int pos,i=0,a=0,a1=0;
    printf("Basic HTTP server example\n");
    
    
    EthernetInterface eth;
    eth.connect();
    
    printf("The target IP address is '%s'\n", eth.get_ip_address());
    
    TCPServer srv;
    
    TCPSocket clt_sock;
    
    SocketAddress clt_addr;
   
    
    /* Open the server on ethernet stack */
    srv.open(&eth);
    
    
    /* Bind the HTTP port (TCP 80) to the server */
    //srv.bind(eth.get_ip_address(), 80);
    srv.bind(eth.get_ip_address(), 5001);
  //  srv1.bind("10.101.1.130",5001);
    
    /* Can handle 5 simultaneous connections */
    srv.listen(5);
    
   
    while (true) {
        
        //==========================
     for ( pos = 500; pos < 2000; pos += 25) 
      {
          Servo1.SetPosition(pos);  
          httpr[i]=8;
          wait_ms(20);
          i++;
      }

      //i=0;
          // SendWebPage(pos,v2,v3,v4);
          srv.accept(&clt_sock, &clt_addr);
          printf("accept %s:%d\n", clt_addr.get_ip_address(), clt_addr.get_port());
          a = clt_sock.send(httpr, strlen((char *)httpr));
          while(true)
          {
              a1 = clt_sock.recv(httpr1, strlen((char *)httpr1)); 
              //printf("accept Xbyte %d\n",a1);
              if (a1 <= 0)
                break;
              //httpr1[a1] = '\0';
               printf("Received %d chars from server:\n%s\n", a1,httpr1);
          }
           clt_sock.close();
           printf("accept voir %d\n",httpr1[0]);
          }