Pages: [1]   Go Down
Author Topic: Async Wifi Sheild v2.0   Socket code  Help  (Read 876 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,  I can get the code to compile and upload but cannot see why I cannot read a string over the socket created and parse and act on that string.  

This is a slightly modified example.


Code:
/*
 * Socket App
 *
 * A simple socket application example using the WiShield 1.0
 */

#include <WiShield.h>

#define WIRELESS_MODE_INFRA      1
#define WIRELESS_MODE_ADHOC      2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2};      // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1};      // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};      // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"Gibson"};            // max 32 bytes

unsigned char security_type = 3;      // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"AlexanderTheSimple"};      // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {      0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,      // Key 0
                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      0x00,      // Key 1
                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      0x00,      // Key 2
                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,      0x00      // Key 3
                                                };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

char mybuff[20], sendbuff;
String x;
void setup()
{
      WiFi.init();
        Serial.begin(9600);
        pinMode(7,OUTPUT);
        digitalWrite(7,LOW);
}

void loop()
{
      WiFi.run();
        Serial.print(mybuff);
        x = mybuff;
        Serial.print(x);
        //delay(100);
        if (x == "on")
        {
        digitalWrite(7, HIGH);
        }
        if (x == "off")
        {
        digitalWrite(7, LOW);
       }
}


Socketapp.c remains unchanged.  

I am using python to send these commands:

Code:
>>> import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("192.168.1.2", 9000))

>>> sock.send('on')


Can anyone see why the LED does nothing upon the command being issued?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Never mind   I figured it out that the python terminal wasnt sending '/n' across properly,  instead i changed the socketapp.c read to value to '=' and it works fine.
Logged

Pages: [1]   Go Up
Jump to: