Exemplo n.º 1
0
static void ICACHE_FLASH_ATTR networkRecvCb(void *arg, char *data, unsigned short len) {

  uart0_tx_buffer("recv",4);
  
  struct espconn *conn=(struct espconn *)arg;
  int x;
  uart0_tx_buffer(data,len);
  //for (x=0; x<len; x++) networkParseChar(conn, data[x]);
}
Exemplo n.º 2
0
int main()
{
  int uart0_core = 0;
  int uart1_core = 1;
  uart0_tx_ctrl.busy = 0;
  
  /* Set up interrupt handler */
  int_init();

  /* Install UART core 0 interrupt handler */
  int_add(UART0_IRQ, uart_int_handler,(void*) &uart0_core);
  
  /* Install UART core 1 interrupt handler */
  //int_add(UART1_IRQ, uart_int_handler,(void*) &uart1_core);

  /* Enable interrupts in supervisor register */
  mtspr (SPR_SR, mfspr (SPR_SR) | SPR_SR_IEE);
  
  uart_init(uart0_core);
  //uart_init(uart1_core);
  
  //uart_rxint_enable(uart1_core);
  uart_rxint_enable(uart0_core);
  
  char* teststring = "\n\tHello world from UART 0\n\0";

  uart0_tx_buffer(teststring);

  // Do other things while we transmit
  float f1, f2, f3; int i;
  f1 = 0.2382; f2 = 4342.65; f3=0;
  for(i=0;i<32;i++) f3 += f1*f3 + f2;

  report(f3);
  report(0x4aaaaa1f);
  
  char* done_calculating = "\tDone with the number crunching!\n\0";

  uart0_tx_buffer(done_calculating);
  
  // Character '*', which will be received in the interrupt handler and cause
  // the simulation to exit.
  char* finish = "*\n\0";
  
  uart0_tx_buffer(finish);
  
  while(1); // will exit in the rx interrupt routine

}
Exemplo n.º 3
0
// Recv callback
static void ICACHE_FLASH_ATTR tcpRecvCb(void *arg, char *data, uint16_t len) {
	struct espconn *conn = arg;
	TcpConn *tci = conn->reverse;
	os_printf("TCP recv CB (%p %p)\n", arg, tci);
	if (tci->state == TCP_data) {
		uint8_t chan;
		for (chan=0; chan<MAX_CHAN && tcpConn+chan!=tci; chan++)
		if (chan >= MAX_CHAN) return; // oops!?
		char buf[6];
		short l = os_sprintf(buf, "\n~%d", chan);
		uart0_tx_buffer(buf, l);
		uart0_tx_buffer(data, len);
		uart0_tx_buffer("\0\n", 2);
	}
	serledFlash(50); // short blink on serial LED
}
Exemplo n.º 4
0
static void ICACHE_FLASH_ATTR ntp_udp_recv(void *arg, char *pdata, unsigned short len) {
	
	struct tm *dt;
	time_t timestamp;
	ntp_t *ntp;

	os_timer_disarm(&ntp_timeout);

	// extract ntp time
	ntp = (ntp_t*)pdata;
	timestamp = ntp->trans_time[0] << 24 | ntp->trans_time[1] << 16 |ntp->trans_time[2] << 8 | ntp->trans_time[3];
	// convert to unix time
	timestamp -= 2208988800UL;
	// create tm struct
	dt = gmtime(&timestamp);

	// do something with it, like setting an rtc
	//ds1307_setTime(dt);
	// or just print it out
	char timestr[11];
	os_sprintf(timestr, "%02d:%02d:%02d\r\n", dt->tm_hour, dt->tm_min, dt->tm_sec);
	uart0_tx_buffer(timestr, 10);

	// clean up connection
	if (pCon) {
		espconn_delete(pCon);
		os_free(pCon->proto.udp);
		os_free(pCon);
		pCon = 0;
	}
}
void ICACHE_FLASH_ATTR networkRecvCb(void *arg, char *data, unsigned short len) 
{
  //uart0_tx_buffer("recv",4);
  
  struct espconn *conn=(struct espconn *)arg;
  uart0_tx_buffer(data,len);
}
void ICACHE_FLASH_ATTR esp8266_connectCallback(void* arg)
{
    uart0_tx_buffer("connected\r\n", 11);
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    netConn->connectCallback(netConn->userData, net_ok);
}
void ICACHE_FLASH_ATTR esp8266_disconnectCallback(void* arg)
{
    uart0_tx_buffer("disconnected\r\n", 14);
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    esp8266_destroyConnection(netConn);
    netConn->disconnectCallback(netConn->userData, net_ok);
}
Exemplo n.º 8
0
static void ICACHE_FLASH_ATTR serverRecvCb(void *arg, char *data, unsigned short len) {
	int x;
	char *p, *e;
	serverConnData *conn = serverFindConnData(arg);
	//ets_uart_printf("Receive callback on conn %p\n", conn);
	if (conn == NULL) return;


	uart0_tx_buffer(data, len);
}
void ICACHE_FLASH_ATTR esp8266_recvCallback(void* arg, char* buffer, unsigned short size)
{
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "rx: %d\r\n", size);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    netConn->readCallback(netConn->userData, buffer, size, net_ok);
}
void ICACHE_FLASH_ATTR net_asyncConnect(NetConnection* conn, const char* hostname)
{
    uart0_tx_buffer("connect\r\n", 9);
    HTTPESP8266ConnectionData* driver = esp8266_createConnection(conn);
    driver->secure = 1;
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "r: %s\r\n", hostname);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    err_t e = espconn_gethostbyname(&driver->connection, hostname, &driver->ip, esp8266_resolveCallback);
    switch(e)
    {
    case ESPCONN_OK: // dns cached, no async call
        esp8266_resolveCallback(hostname, &driver->ip, &driver->connection);
    case ESPCONN_INPROGRESS: // dns request queued, let callback happen
        return;
    default: // error fetching hostname
        esp8266_resolveCallback(hostname, NULL, &driver->connection);
    };
}
void ICACHE_FLASH_ATTR esp8266_reconnectCallback(void* arg, sint8 err)
{
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "recon: %d\r\n", err);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    esp8266_destroyConnection(netConn);
    netConn->readCallback(netConn->userData, NULL, 0, net_error);
}
void ICACHE_FLASH_ATTR net_asyncDisconnect(NetConnection* conn)
{
    uart0_tx_buffer("disconnect\r\n", 12);
    HTTPESP8266ConnectionData* driver = esp8266_getConnection(conn);
    //esp8266_destroyConnection(conn);
    //conn->disconnectCallback(conn->userData, net_ok);
    if(driver->secure)
        espconn_secure_disconnect(&driver->connection);
    else
        espconn_disconnect(&driver->connection);
}
Exemplo n.º 13
0
static void ICACHE_FLASH_ATTR networkConnectedCb(void *arg) {

  uart0_tx_buffer("conn",4);
  struct espconn *conn=(struct espconn *)arg;

  // char *data = "GET / HTTP/1.0\r\n\r\n\r\n";
  // sint8 d = espconn_sent(conn,data,strlen(data));

  // espconn_regist_recvcb(conn, networkRecvCb);
  // uart0_tx_buffer("cend",4);
}
Exemplo n.º 14
0
// Connection reset callback
static void ICACHE_FLASH_ATTR tcpResetCb(void *arg, sint8 err) {
	struct espconn *conn = arg;
	TcpConn *tci = conn->reverse;
	os_printf("TCP reset CB (%p %p) err=%d\n", arg, tci, err);
	// notify to serial
	char buf[6];
	short l = os_sprintf(buf, "\n~@%dZ\n", tci-tcpConn);
	uart0_tx_buffer(buf, l);
	// free
	tcpConnFree(tci);
}
Exemplo n.º 15
0
// Connected callback
static void ICACHE_FLASH_ATTR
tcpConnectCb(void *arg) {
	struct espconn *conn = arg;
	TcpConn *tci = conn->reverse;
	os_printf("TCP connect CB (%p %p)\n", arg, tci);
	tci->state = TCP_data;
	// send any buffered data
	if (tci->txBuf != NULL && tci->txBufLen > 0) tcpDoSend(tci);
	// reply to serial
	char buf[6];
	short l = os_sprintf(buf, "\n~@%dC\n", tci-tcpConn);
	uart0_tx_buffer(buf, l);
}
Exemplo n.º 16
0
static void ICACHE_FLASH_ATTR ntp_udp_timeout(void *arg) {
	
	os_timer_disarm(&ntp_timeout);
	uart0_tx_buffer("ntp timout\r\n", 12);

	// clean up connection
	if (pCon) {
		espconn_delete(pCon);
		os_free(pCon->proto.udp);
		os_free(pCon);
		pCon = 0;
	}
}
Exemplo n.º 17
0
size_t myspiffs_write( int fd, const void* ptr, size_t len ){
#if 0
  if(fd==c_stdout || fd==c_stderr){
    uart0_tx_buffer((u8_t*)ptr, len);
    return len;
  }
#endif
  int res = SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, len);
  if (res < 0) {
    NODE_DBG("write errno %i\n", SPIFFS_errno(&fs));
    return 0;
  }
  return res;
}
Exemplo n.º 18
0
LOCAL void ICACHE_FLASH_ATTR
user_socket_serial_rx(void *arg, char *pusrdata, unsigned short length)
{
    char DeviceBuffer[40] = {0};
    char Device_mac_buffer[60] = {0};
    char hwaddr[6];

    if (pusrdata == NULL) {
        return;
    }
	remoteOnline = 30;
	uart0_tx_buffer(pusrdata,length);
	//espconn_sent(&ptresp_serial, pusrdata, length);
}
void ICACHE_FLASH_ATTR net_asyncWrite(NetConnection* conn, const void* data, size_t size)
{   
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "tx: %d\r\n", size);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    HTTPESP8266ConnectionData* driver = esp8266_getConnection(conn);
    uint16 writeSize = size <= 65535 ? size : 65535;
    driver->writeData = data + writeSize;
    driver->writeDataSize = size - writeSize;
    if(driver->secure)
        espconn_secure_sent(&driver->connection, (uint8*)data, writeSize);
    else
        espconn_sent(&driver->connection, (uint8*)data, writeSize);
}
Exemplo n.º 20
0
int ICACHE_FLASH_ATTR ajaxConsoleSend(HttpdConnData *connData) {
  if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
  char buff[2048];
  int len, status = 400;
  
  // figure out where to start in buffer based on URI param
  len = httpdFindArg(connData->getArgs, "text", buff, sizeof(buff));
  if (len > 0) {
    uart0_tx_buffer(buff, len);
    status = 200;
  }
  
  jsonHeader(connData, status);
  return HTTPD_CGI_DONE;
}
void ICACHE_FLASH_ATTR esp8266_sendCallback(void* arg)
{
    uart0_tx_buffer("tx\r\n", 4);
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;
    HTTPESP8266ConnectionData* driver = esp8266_getConnection(netConn);

    if(driver->writeDataSize > 0)
    {
        net_asyncWrite(netConn, driver->writeData, driver->writeDataSize);
    }
    else
    {
        netConn->writeCallback(netConn->userData, net_ok);
    }
}
Exemplo n.º 22
0
/**
  * @brief  Udp server receive data callback function.
  * @param  arg: contain the ip link information
  * @retval None
  */
LOCAL void ICACHE_FLASH_ATTR
at_udpserver_recv(void *arg, char *pusrdata, unsigned short len)
{
  struct espconn *pespconn = (struct espconn *)arg;
  at_linkConType *linkTemp;
  char temp[32];
  uint8_t i;

  os_printf("get udpClient:\r\n");

  if(pespconn->reverse == NULL)
  {
    for(i = 0;i < at_linkMax;i++)
    {
      if(pLink[i].linkEn == FALSE)
      {
        pLink[i].linkEn = TRUE;
        break;
      }
    }
    if(i >= 5)
    {
      return;
    }
    pLink[i].teToff = FALSE;
    pLink[i].linkId = i;
    pLink[i].teType = teServer;
    pLink[i].repeaTime = 0;
    pLink[i].pCon = pespconn;
    espconn_regist_sentcb(pLink[i].pCon, at_tcpclient_sent_cb);
    mdState = m_linked;
    at_linkNum++;
    pespconn->reverse = &pLink[i];
    uart0_sendStr("Link\r\n");
  }
  linkTemp = (at_linkConType *)pespconn->reverse;
  if(pusrdata == NULL)
  {
    return;
  }
  os_sprintf(temp, "\r\n+IPD,%d,%d:",
             linkTemp->linkId, len);
  uart0_sendStr(temp);
  uart0_tx_buffer(pusrdata, len);
  at_backOk;
}
Exemplo n.º 23
0
void ICACHE_FLASH_ATTR user_uart_task(void *pvParameters)
{
	CusUartIntrPtr uartptrData;
	u32 sys_time_value = system_get_time();

	while (1)
	{
		
		if (EmptyQueue() == false && (system_get_time() - sys_time_value) >= 100) {

			ESP_DBG(("***heap_size %d\n", system_get_free_heap_size()));

			frame_t frame;

			if (Dequeue(&frame)) {
				uart0_tx_buffer((uint8_t *)&frame, frame.len);
			}
			sys_time_value = system_get_time();
		}
		
		if (xQueueReceive(xQueueCusUart, (void *)&uartptrData, (portTickType)20/*portMAX_DELAY*/)) // wait about 20msec 
		{
			ESP_DBG(("data uart recv.."));
			debug_print_hex_data(uartptrData.rx_buf, uartptrData.rx_len);

			if (uartptrData.rx_len>0x00) {
				cus_uart_data_handle(uartptrData.rx_buf, uartptrData.rx_len, NULL);
			}
		}
		/*
		if ((system_get_time() - sys_time_value) >= (60 * 1000 * 1000))  //about 1min, send data to uart0, demo beat data
		{
			ESP_DBG(("uart beat data***heap_size %d\n", system_get_free_heap_size()));
			
			//uart0_write_data(uart_beat_data, sizeof(uart_beat_data));//heatbeat sent to MCU
			
			sys_time_value = system_get_time();
		}
		*/
		
	}

	vTaskDelete(NULL);

}
Exemplo n.º 24
0
void user_init( void )
{
	positiondebut = 0;
	positionfin = 1; 


	positiondebutUDP = 0;
	positionfinUDP = 0;

    static struct station_config config;
    uart_div_modify( 0, UART_CLK_FREQ / ( 115200 ) );
    os_printf( "%s\n", __FUNCTION__ );
    uart_init(115200,9600);
    spi_slave_init(HSPI,SPI_BUFF);
    wifi_station_set_hostname( HOSTNAME );
    wifi_set_opmode_current( STATIONAP_MODE );
    gpio_init();
    spi_gpio_init();
//os_printf sur Uart0
 espconn_init() ;
    uart0_tx_buffer("init\n", 5);
    config.bssid_set = 1;
    os_memcpy( &config.ssid, SSID, 14 );
    os_memcpy( &config.password, PASSWORD, 41);
    wifi_station_set_config( &config );
    wifi_station_connect();
   // wifi_set_event_handler_cb( wifi_callback );
   shell_init();
//Démarage du client UDP
   user_set_station_config_udp();

   MessageUDP.Status = E_ID;
 MessageSPi.Status = E_ID;
    system_os_task(all_recvTask,PRIO_SPI,  all_recvTaskQueue, TASK_LENGHT);  ///demo with a task to process the uart data
    system_os_task(uart_recvTask,PRIO_UART,  uart_recvTaskQueue, TASK_LENGHT); // //demo with a task to process the spi 


}
Exemplo n.º 25
0
void ICACHE_FLASH_ATTR
tcpserver_recv_cb(void *arg, char *data, unsigned short length)
{
	struct espconn *pespconn = arg;
	// Received some data from tcp connection 
	os_printf("TCP recv data length: %d \r\n", length);
	os_printf("%s \n", data);

    if(length == 2 && strcmp("AR", data) == 0) 
    {
        // Receive AR so send OK back
        // TODO send data to supertiny (at receive board) to check if receive data is allowed...
        char buffer[] = "OK";
        espconn_sent(pespconn, buffer, os_strlen(buffer));
    } else 
    {
        // Received data wich is probably right 
        // TODO check data
        //uart0_sendStr(data); 

        uart0_tx_buffer(data, length);              // string will not send 0x00
    }
}
Exemplo n.º 26
0
static void ICACHE_FLASH_ATTR networkDisconCb(void *arg) {
  uart0_tx_buffer("dcon",4);
//  os_printf("Disconnect\n\r");
//  network_init();
}
Exemplo n.º 27
0
static void ICACHE_FLASH_ATTR networkReconCb(void *arg, sint8 err) {
  uart0_tx_buffer("rcon",4);
//  os_printf("Reconnect\n\r");
//  network_init();
}
Exemplo n.º 28
0
static void ICACHE_FLASH_ATTR networkSentCb(void *arg) {
  uart0_tx_buffer("sent",4);
}
Exemplo n.º 29
0
/**
  * @brief  Client received callback function.
  * @param  arg: contain the ip link information
  * @param  pdata: received data
  * @param  len: the lenght of received data
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_tcpclient_recv(void *arg, char *pdata, unsigned short len)
{
  struct espconn *pespconn = (struct espconn *)arg;
  at_linkConType *linkTemp = (at_linkConType *)pespconn->reverse;
  char temp[32];
  char * onboarding = "onboarding";
  char * onboardingHTML = "<html><head><title>LemonBox</title><style>body{text-align:center;}form{display:inline-block}form input{display:block}</style></head><body><form method='POST' action='/onboard'><input type='text' placeholder='SSID' name='ssid!'/><input type='text'placeholder='PASSWORD' name='password'/><input type='submit' value='submit'/></form></body></html>";
  char * get = "GET /";
  char * post = "POST /";

  os_printf("recv\r\n");
  if(at_ipMux)
  {
    if (strstr(pdata,get) != NULL){
      if (strstr(pdata,onboarding) != NULL){
        uart0_sendStr("Sending LemonOboarding");

        espconn_sent(pLink[linkTemp->linkId].pCon, onboardingHTML, strlen(onboardingHTML));
        espconn_disconnect(pLink[linkTemp->linkId].pCon);
      }      
      char * htmlSSIDs;

      if (strstr(pdata,"/accesspoints") != NULL){
        uart0_sendStr("Sending accesspoints");
        struct station_info *station;
        struct station_info *next_station;
        char tempSSID[128];

        if(at_wifiMode == STATION_MODE)
        {
          at_backError;
          return;
        }
        station = wifi_softap_get_station_info();
        while(station)
        {
          os_sprintf(tempSSID, "%d.%d.%d.%d,"MACSTR"\r\n",
                     IP2STR(&station->ip), MAC2STR(station->bssid));
          uart0_sendStr(tempSSID);
          os_sprintf("<option value=",tempSSID,"</option>");
          next_station = STAILQ_NEXT(station, next);
          os_free(station);
          station = next_station;
        }
        os_sprintf("<select>",htmlSSIDs,"</option>");
        espconn_sent(pLink[linkTemp->linkId].pCon, htmlSSIDs, strlen(htmlSSIDs));
        espconn_disconnect(pLink[linkTemp->linkId].pCon);
      }
    }    


    if (strstr(pdata,post) != NULL){
      if (strstr(pdata, "/onboard") !=NULL){
        uart0_sendStr("onboarding started");
        char *tok =pdata;

        strtok(tok, "\n");
        tok =NULL;
        char * ssid = strtok(tok, "\n");        
        tok =NULL;
        strtok(tok, "\n");
        tok =NULL;
        char * pass = strtok(tok, "\n");
        uart0_sendStr(pass);

        espconn_sent(pLink[linkTemp->linkId].pCon, "OK", 2);
        espconn_disconnect(pLink[linkTemp->linkId].pCon);
      }        

      if (strstr(pdata, "gpio/on") !=NULL){
        uart0_sendStr("GPIO 2 ON");
        gpio_output_set(BIT2, 0, BIT2, 0);
        espconn_sent(pLink[linkTemp->linkId].pCon, "<html><head><title></title></head><body>ON</body></html>", 56);
        espconn_disconnect(pLink[linkTemp->linkId].pCon);

      }      

      if (strstr(pdata, "gpio/off") !=NULL){
        uart0_sendStr("GPIO 2 OFF");
        gpio_output_set(0, BIT2, BIT2, 0);
        espconn_sent(pLink[linkTemp->linkId].pCon, "<html><head><title></title></head><body>OFF</body></html>", 57);
        espconn_disconnect(pLink[linkTemp->linkId].pCon);

      }
    }    
    os_sprintf(temp, "\r\n+IPD,%d,%d:",
               linkTemp->linkId, len);
    uart0_sendStr(temp);
    uart0_tx_buffer(pdata, len);



  }
  else if(IPMODE == FALSE)
  {
    os_sprintf(temp, "\r\n+IPD,%d:", len);
    uart0_sendStr(temp);
    uart0_tx_buffer(pdata, len);
  }
  else
  {
    uart0_tx_buffer(pdata, len);
    return;
  }
  at_backOk;
}
Exemplo n.º 30
0
void uart_putc1(char c) {
     uart0_tx_buffer(&c, 1);
}