Example #1
0
int wifiAutoConnectInit_itc(void)
{
	int8_t ret;
	uint8_t result;
	uint8_t *ssid = NULL;
	char *ap_security = NULL;
	char *ap_password = NULL;

	slsi_security_config_t *sec_config = NULL;

	isConnected = 0;
	dm_conn_register_linkup_cb(linkUpEvent);

	if (WiFiIsConnected(&result, NULL) != SLSI_STATUS_SUCCESS) {
		printf("Wifi Is not Connected\n");
	}

	if (result > 0) {
		printf("Wi-Fi status - Connected : %d\n", result);
		isConnected = 1;
		return 1;
	}

	ret = WiFiStart(SLSI_WIFI_STATION_IF, NULL);
	if (ret == SLSI_STATUS_SUCCESS) {
		printf("[AutoConnect]STA mode started\n");
		ssid = (uint8_t *)CONFIG_DM_AP_SSID;
		ap_security = (char *) CONFIG_DM_AP_SECURITY;
		ap_password = (char *) CONFIG_DM_AP_PASS;
		if ((ssid == NULL) || (ap_security == NULL) || (ap_password == NULL)) {
			return -1;
		}

		sec_config = (slsi_security_config_t *)getSecurityConfig(ap_security, ap_password);
		ret = WiFiNetworkJoin(ssid, strlen(CONFIG_DM_AP_SSID), NULL, sec_config);
		sleep(1);
		if (ret == SLSI_STATUS_SUCCESS) {
			printf("[AutoConnect]Start doJoin with SSID %s\n", CONFIG_DM_AP_SSID);
			return 1;
		} else {
			printf("[AutoConnect]Failed to join the network.[%d]\n", ret);
		}
		return -1;
	} else {
		printf("[AutoConnect]Failed to start STA mode\n");
	}
	return -1;
}
Example #2
0
void mainsetup()
{
  // setup globals
  ulReqcount = 0;
  ulReconncount = 0;
  WiFiStart();
  delay(1);

  server.begin();

  // allocate ram for data storage
  uint32_t free = system_get_free_heap_size() - KEEP_MEM_FREE;
  ulNoMeasValues = free / (sizeof(float) * 5 + sizeof(unsigned long)); // humidity & temp --> 2 + time
  pulTime = new unsigned long[ulNoMeasValues];
  pfTemp1 = new float[ulNoMeasValues];
  pfTemp2 = new float[ulNoMeasValues];
  pfTemp3 = new float[ulNoMeasValues];
  pfTemp4 = new float[ulNoMeasValues];

  if (pulTime == NULL || pfTemp1 == NULL || pfTemp2 == NULL || pfTemp3 == NULL || pfTemp4 == NULL)
  {
    ulNoMeasValues = 0;
    Serial.println("Error in memory allocation!");
  }
  else
  {
    Serial.print("Allocated storage for ");
    Serial.print(ulNoMeasValues);
    Serial.println(" data points.");

    float fMeasDelta_sec = MEAS_SPAN_H * 3600. / ulNoMeasValues;
    ulMeasDelta_ms = ( (unsigned long)(fMeasDelta_sec + 0.5) ) * 1000; // round to full sec
    Serial.print("Measurements will happen each ");
    Serial.print(ulMeasDelta_ms);
    Serial.println(" ms.");

    ulNextMeas_ms = millis() + ulMeasDelta_ms;
  }
}