cc3000 Wifi Weather Station, Server connection fails

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

Pinging ip of CC3000 produce 4 replies with no losses; however, I am unable to connect to server on 192.168.2.7

Operating system is Windows 8.1. I had an issue with data corruption @ 115,200; reduced serial data rate to 9,600. Corruption went away.
connection to server.JPG
connection to server.JPG (50.18 KiB) Viewed 4203 times

Code: Select all

/*
* Simple WiFi weather station with Arduino, the DHT22 sensor & the CC3000 chip
* Part of the code is based on the work done by Adafruit on the CC3000 chip & the DHT11 sensor
* Writtent by Marco Schwartz for Open Home Automation
*/

// Include required libraries
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.h"
#include "DHT.h"
#include<stdlib.h>

// Define CC3000 chip pins
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10

// WiFi network (change with your settings !)
#define WLAN_SSID "Oceans" // cannot be longer than 32 characters!
#define WLAN_PASS "reddog60"
#define WLAN_SECURITY WLAN_SEC_WPA2 // This can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2

// DHT11 sensor pins
#define DHTPIN 7
#define DHTTYPE DHT22

// Create CC3000 & DHT instances
DHT dht(DHTPIN, DHTTYPE);
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2);
                                         
// Local server IP, port, and repository (change with your settings !)
uint32_t ip = cc3000.IP2U32(192,168,2,7);
int port =8887;
String repository = "/wifi_weather_station/";
                                         
void setup(void)
{
 
  // Initialize DHT sensor
  dht.begin();
  
  Serial.begin(9600);
    
  // Initialise the CC3000 module
  if (!cc3000.begin())
  {
    while(1);
  }

  // Connect to WiFi network
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println("Connected to WiFi network!");
    
  // Check DHCP
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }
  
  /* Display the IP address DNS, Gateway, etc. */  
  while (! displayConnectionDetails()) {
    delay(1000);
  }
  
}

void loop(void)
{
  
    // Measure the humidity & temperature
    float h = dht.readHumidity();
    float t = dht.readTemperature();
     
    // Transform to String
    String temperature = String((int) t * 9/5 +32);
    String humidity = String((int) h);
    
    // Print data
    Serial.print("Temperature: ");
    Serial.println(temperature);
    Serial.print("Humidity: ");
    Serial.println(humidity);
    Serial.println("");
    
    // Send request
    String request = "GET "+ repository + "sensor.php?temp=" + temperature + "&hum=" + humidity + " HTTP/1.1";
    send_request(request);
    
    // Update every second
    delay(2000);
}

// Function to send a TCP request and get the result as a string
void send_request (String request) {
     
    // Connect
    Serial.println("Starting connection to server...");
    Adafruit_CC3000_Client client = cc3000.connectTCP(ip, port);
	
    // Send request
    if (client.connected()) {
	  delay(500);
      client.println(request);
      client.println(F(""));
      Serial.println("Connected & Data sent");
    }
    else {
      Serial.println(F("Connection failed"));
    }

    while (client.connected()) {
      while (client.available()) {

      // Read answer
      char c = client.read();
      }
    }
    Serial.println("Closing connection");
    Serial.println("");
    client.close();
    
}

/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
  
  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}
Is there any additional information on setting up of a server for Windows 8.1. Currently I have been trying to configure WAMPServer.
I can display website pages in localhost with the default install of WAMPServer.

Also, I found that if I create two text files --hum_data.txt and temp_data.txt; the server displays the Wifi-weather-station.htm. There is no updating of the two txt files.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by adafruit_support_mike »

You'll need to check your webserver configuration to make sure it's actually serving pages on port 8887. Also make sure your computer doesn't have anything like a firewall blocking packets for that port.

WRT WAMP, that's outside my realm of expertise. I build my servers on Unix-line platforms, and know the tools there. The best suggestion I have is to make sure the webserver has permission to write to the files you want to display.. that's a common gotcha.

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

apache.JPG
apache.JPG (21.19 KiB) Viewed 4162 times
WAMPServer is the package name; it is actually an Apache server.

I am able to bring up localhost web pages; stil I can not connect to 192.xxx.xxx.xxx.
localhost-wifiweather.JPG
localhost-wifiweather.JPG (33.08 KiB) Viewed 4162 times
For some reason running the above sketch I can not connect to the cc3000 @ 115200, I have to drop to 9600 or I get garage on the serial monitor.

Will this effect my ability to connect to 192.xxx.xxx.xxx?

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by Franklin97355 »

It looks like your server is on port 80 so why are you trying to connect to port 8887?

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

"Wifi-Weather-Station" Sketch is currently set to port 80; I decided not re-upload the sketch for sake of brevity.

CC3000 Library; "Webclient" example sketch works flawlessly, as does, "buildtest" sketch.

I have re-traced wiring, more than once the breadboard, circuit wiring and found no mistakes in wiring.

Yet I am unable to connect on Port 80. I forwarded the ip of the CC3000 on the router. Same CC3000 ip is in the Windows Hosts file.
I have tried turning off firewall and antivirus. Still can not connect.
Server online-Port 80.JPG
Server online-Port 80.JPG (32.57 KiB) Viewed 4147 times
Could the CC3000 breakout board could be failing?

William

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by adafruit_support_mike »

There are no known failure modes that would allow the example code to work but still fail to work for other code.

From the information you've given so far, I'm confused about what you're even trying to do, so let's nail down some specifics:

- Are you trying to use the CC3000 as a client or a server?
- What's the IP address of your CC3000?
- What's the IP address of your WAMP server?
- Is your WAMP server listening to port 80 or port 8887?
- What machine is the server?
- What machine is the client?
- Is the client trying to connect to 192.168.2.7?
- Is the client trying to connect on port 80 or port 8887?

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

Link to project: http://www.openhomeautomation.net/arduino-wifi-cc3000/

1. CC3000 is sending data to an Apache server (part of a package called WAMPServer).
2. 192.168.2.7 CC3000 address
3. Windows PC running WAMPServer 192.168.2.2
4. Server Listening port is 80.
5. Server is CC3000
6. Client is Windows, PC 192.168.2.2
7. I have been try to connect to 192.168.2.7.
8. Client is trying to connect to port 80, http://192.168.2.7:80

Additional: I am unable to connect to the CC3000 using 115,200 bps due to getting garage ASCII characters.
Dropping to 9,600 bps, produces readable text.

Thank you.
William

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by adafruit_support_mike »

Those statements contradict each other, and with the project described on the page you linked.

The CC3000 at 192.168.2.7 can only send information to the Apache server at 192.168.2.2 by acting as a client. HTTP is strictly a request-based protocol, and there's no way for a server to push information to a client. If you want the CC3000 to initiate the connection, it has to send a GET or POST request to the Apache server at 192.168.2.2.

If the CC3000 is acting as a client, you won't get anything if you send GET or POST requests to it.

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

@ adafruit_support_Mike I stand corrected. Thank you. I was wrong.

http://192.168.2.2/wifiweather/weather_station.html produces a web page that only has Titles "Temperature" and "Humidity"; but no data.

Code: Select all

<!DOCTYPE html>
<html>
<head>
	<script src="jquery-2.0.3.min.js"></script>
	<link rel="stylesheet" type="text/css" href="style.css">
	<title>Weather Station</title>
</head>

<body>
	<div class="data">
		<div class="dataTitle">Temperature: </div>
		<div id="temperatureDisplay">Waiting for data ...</div>
	</div>

	<div class="data">
		<div class="dataTitle">Humidity: </div>
		<div id="humidityDisplay">Waiting for data ...</div>
	</div>

	<script type="text/javascript">
		
		setInterval(function() 
	{
	    $("#temperatureDisplay").load('temperature_display.php');
	    $("#humidityDisplay").load('humidity_display.php');
	}, 1000);

	</script>
	

</body>

</html>
There is no "Weather Station" title.

It looks to me like the GET is being received, I can see HTTP 1.1 200's:
Firefox displaying console (F12).JPG
Firefox displaying console (F12).JPG (87.43 KiB) Viewed 4121 times

William

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by adafruit_support_mike »

The GET requests shown in the second image are the ones generated by this chunk of javascript in the webpage:

Code: Select all

   <script type="text/javascript">
      
      setInterval(function() 
   {
       $("#temperatureDisplay").load('temperature_display.php');
       $("#humidityDisplay").load('humidity_display.php');
   }, 1000);

   </script>
The 200s do indicate valid connections, but the log shows 0 bytes sent for each request. What do you have in your 'temperature_display.php' and 'humidity_display.php' files?

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

Made this change:

Code: Select all

Original code:

// Local server IP, port, and repository (change with your settings !)
uint32_t ip = cc3000.IP2U32(192,168,0,1);
int port = 8887;
String repository = "/wifi-weather-station/";

Code changes made:

// Local server IP, port, and repository (change with your settings !)
uint32_t ip = cc3000.IP2U32(192,168,2,2);  //Apache IP Address
int port =80;
String repository = "/wifiweather/";  //Directory on Apache server were text files are located.


Serial Monitor shows "Connected and Data sent" now; however, still no updating of Data.

Requested humidity_display.php file:

Code: Select all

<?php

	$myFile = "hum_data.txt";
	$fh = fopen($myFile, 'r');
	$line = fgets($fh);
	fclose($fh);

	echo $line;

?>
Requested temperature_display.php file:

Code: Select all

<?php

	$myFile = "temp_data.txt";
	$fh = fopen($myFile, 'r');
	$line = fgets($fh);
	fclose($fh);

	echo $line;

?>
Adding sensor.php file:

Code: Select all

<?php

	// Store data
    if ($_GET["temp"] && $_GET["hum"]) {

        	$myFile = "temp_data.txt";
		$fh = fopen($myFile, 'w');
		fwrite($fh, $_GET["temp"]);
		fclose($fh);

		$myFile = "hum_data.txt";
		$fh = fopen($myFile, 'w');
		fwrite($fh, $_GET["hum"]);
		fclose($fh);
		
    }

?>
Appreciate the help!
William

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tdicola »

If you look at the temp_data.txt and hum_data.txt files that are produced by the PHP code that receives sensor data, do you see data there? Since there are a few different processes and boundaries it will help to try isolating things to see where data is failing to be passed around. I would suggest:
- Check your WAMP server logs to see if there are calls from the Arduino + CC3000 to save results.
- Check temp_data.txt and hum_data.txt are getting results written to them (mentioned above). If you see calls from the CC3000 in the logs, but no results saved in files, are permissions setup so the WAMP server can write to disk?
- Put fake values inside temp_data.txt and hum_data.txt to make sure the web page is loading the data you expect (looks like it's probably working since you see the get requests from the page, but it can't hurt to double check).

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

Good news; Wifi Weather Station sketch is now operational!
Working wifi-weather-station.JPG
Working wifi-weather-station.JPG (33.17 KiB) Viewed 4079 times
Apache _error log.JPG
Apache _error log.JPG (88.15 KiB) Viewed 4079 times
Turned out to be the url for the String Repository in the "Get" HTTP code.



Thank you for guiding me to finding the problem!!!
William
Attachments
Apache access log.JPG
Apache access log.JPG (115.83 KiB) Viewed 4079 times

User avatar
virlandlang
 
Posts: 1
Joined: Sat Oct 11, 2014 11:51 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by virlandlang »

@Tech500
my good sirs I am a newbie and if its alright can i somehow get a copy of your code and the steps you did on how to show the temp readings by just pulling up the local IP? I will really appreciate you help. I will be using this knowledge for my thesis sirs, :)
u can email me as well @ [email protected]

User avatar
tech500
 
Posts: 199
Joined: Wed Dec 04, 2013 3:53 pm

Re: cc3000 Wifi Weather Station, Server connection fails

Post by tech500 »

@virlandlang

https://learn.adafruit.com/downloads/pd ... cc3000.pdf has the information you are wanting.

Explains the whole process and where to find the code.

William

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Arduino products from Adafruit”