'StrContains' was not declared in this scope ???


hoi,

kan iemand mij helpen met deze foutmelding, kom er echt niet uit. code onderstaand


alvast bedankt



code: [select]
#include <spi.h>
#include <ethernet.h>
#include <sd.h>
// size of buffer used capture http requests
#define req_buf_sz 60

// mac address ethernet shield sticker under board
byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
ipaddress ip(192, 168, 0, 20); // ip address, may need change depending on network
ethernetserver server(80); // create server @ port 80
file webfile; // web page file on sd card
char http_req[req_buf_sz] = {0}; // buffered http request stored null terminated string
char req_index = 0; // index http_req buffer
boolean led_state[2] = {0}; // stores states of leds

void setup()
{
// disable ethernet chip
pinmode(10, output);
digitalwrite(10, high);

serial.begin(9600); // debugging

// initialize sd card
serial.println("initializing sd card...");
if (!sd.begin(4)) {
serial.println("error - sd card initialization failed!");
return; // init failed
}
serial.println("success - sd card initialized.");
// check index.htm file
if (!sd.exists("index.htm")) {
serial.println("error - can't find index.htm file!");
return; // can't find index file
}
serial.println("success - found index.htm file.");
// switches
pinmode(2, input);
pinmode(3, input);
// leds
pinmode(9, output);
pinmode(5, output);
pinmode(6, output);
pinmode(7, output);
pinmode(8, output);

ethernet.begin(mac, ip); // initialize ethernet device
server.begin(); // start listen clients
}

void loop()
{
ethernetclient client = server.available(); // try client

if (client) { // got client?
boolean currentlineisblank = true;
while (client.connected()) {
if (client.available()) { // client data available read
char c = client.read(); // read 1 byte (character) client
// limit size of stored received http request
// buffer first part of http request in http_req array (string)
// leave last element in array 0 null terminate string (req_buf_sz - 1)
if (req_index < (req_buf_sz - 1)) {
http_req[req_index] = c; // save http request character
req_index++;
}
// last line of client request blank , ends \n
// respond client after last line received
if (c == '\n' && currentlineisblank) {
// send standard http response header
client.println("http/1.1 200 ok");
// remainder of header follows below, depending on if
// web page or xml page requested
// ajax request - send xml file
if (strcontains(http_req, "ajax_inputs")) {
// send rest of http header
client.println("content-type: text/xml");
client.println("connection: keep-alive");
client.println();
setleds();
// send xml file containing input states
xml_response(client);
}
else { // web page request
// send rest of http header
client.println("content-type: text/html");
client.println("connection: keep-alive");
client.println();
// send web page
webfile = sd.open("index.htm"); // open web page file
if (webfile) {
while(webfile.available()) {
client.write(webfile.read()); // send web page client
}
webfile.close();
}
}
// display received http request on serial port
serial.print(http_req);
// reset buffer index , buffer elements 0
req_index = 0;
strclear(http_req, req_buf_sz);
break;
}
// every line of text received client ends \r\n
if (c == '\n') {
// last character on line of received text
// starting new line next character read
currentlineisblank = true;
}
else if (c != '\r') {
// text character received client
currentlineisblank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give web browser time receive data
client.stop(); // close connection
} // end if (client)

// read buttons , debounce
buttondebounce();
}

// function reads push button switch states, debounces , latches led states
// toggles led states on each push - release cycle
// hard coded debounce 2 switches on pins 2 , 3; , 2 leds on pins 6 , 7
// function adapted arduino ide built-in example:
// file --> examples --> 02.digital --> debounce

void buttondebounce(void)
{
static byte buttonstate[2] = {low, low}; // current reading input pin
static byte lastbuttonstate[2] = {low, low}; // previous reading input pin

// following variables long's because time, measured in miliseconds,
// become bigger number can stored in int.
static long lastdebouncetime[2] = {0}; // last time output pin toggled
long debouncedelay = 50; // debounce time; increase if output flickers

byte reading[2];

reading[0] = digitalread(2);
reading[1] = digitalread(3);

for (int = 0; < 2; i++) {
if (reading[i] != lastbuttonstate[i]) {
// reset debouncing timer
lastdebouncetime[i] = millis();
}

if ((millis() - lastdebouncetime[i]) > debouncedelay) {
// whatever reading at, it's been there longer
// debounce delay, take actual current state:

// if button state has changed:
if (reading[i] != buttonstate[i]) {
buttonstate[i] = reading[i];

// toggle led if new button state high
if (buttonstate[i] == high) {
led_state[i] = !led_state[i];
}
}
}
} // end for() loop

// set leds
digitalwrite(9, led_state[0]);
digitalwrite(5, led_state[1]);
digitalwrite(6, led_state[2]);
digitalwrite(7, led_state[3]);
digitalwrite(8, led_state[4]);

// save reading. next time through loop,
// it'll lastbuttonstate:
lastbuttonstate[0] = reading[0];
lastbuttonstate[1] = reading[1];
}

// checks if received http request switching on/off leds
// saves state of leds
void setleds(void)
{
// main verlichting (pin 9)
if (strcontains(http_req, "led1=1")) {
led_state[0] = 1; // save led state
digitalwrite(9, high);
}
else if (strcontains(http_req, "led1=0")) {
led_state[0] = 0; // save led state
digitalwrite(9, low);
}
// sub verlichting (pin 5)
if (strcontains(http_req, "led2=1")) {
led_state[1] = 1; // save led state
digitalwrite(5, high);
}
else if (strcontains(http_req, "led2=0")) {
led_state[1] = 0; // save led state
digitalwrite(5, low);
}
// alarm (pin 6)
if (strcontains(http_req, "led3=1")) {
led_state[2] = 1; // save led state
digitalwrite(6, high);
}
else if (strcontains(http_req, "led3=0")) {
led_state[2] = 0; // save led state
digitalwrite(6, low);
}

// rolluik 1(pin 7)
if (strcontains(http_req, "led4=1")) {
led_state[3] = 1; // save led state
digitalwrite(7, high);
}
else if (strcontains(http_req, "led4=0")) {
led_state[3] = 0; // save led state
digitalwrite(7, low);
}
// rolluik 2 (pin 8)
if (strcontains(http_req, "led5=1")) {
led_state[4] = 1; // save led state
digitalwrite(8, high);
}
else if (strcontains(http_req, "led5=0")) {
led_state[4] = 0; // save led state
digitalwrite(8, low);
}
}

// send xml file analog values, switch status
// , led status
void xml_response(ethernetclient cl)
{
int analog_val; // stores value read analog inputs
int count; // used 'for' loops
int sw_arr[] = {2, 3}; // pins interfaced switches

cl.print("");
cl.print("<inputs>");
// checkbox led states
// led1
cl.print("<led>");
if (led_state[0]) {
cl.print("checked");
}
else {
cl.print("unchecked");
}
cl.println("</led>");
// button led states
// led2
cl.print("<led>");
if (led_state[1]) {
cl.print("on");
}
else {
cl.print("off");
}
cl.println("</led>");
cl.print("</inputs>");
}

// button led states
// led3
cl.print("<led>");
if (led_state[2]) {
cl.print("on");
}
else {
cl.print("off");
}
cl.println("</led>");
cl.print("</inputs>");
}

// button led states
// led4
cl.print("<led>");
if (led_state[3]) {
cl.print("on");
}
else {
cl.print("off");
}
cl.println("</led>");
cl.print("</inputs>");
}

// button led states
// led5
cl.print("<led>");
if (led_state[4]) {
cl.print("on");
}
else {
cl.print("off");
}
cl.println("</led>");
cl.print("</inputs>");
}

// sets every element of str 0 (clears array)
void strclear(char *str, char length)
{
for (int = 0; < length; i++) {
str[i] = 0;
}
}

// searches string sfind in string str
// returns 1 if string found
// returns 0 if string not found
char strcontains(char *str, char *sfind)
{
char found = 0;
char index = 0;
char len;

len = strlen(str);

if (strlen(sfind) > len) {
return 0;
}
while (index < len) {
if (str[index] == sfind[found]) {
found++;
if (strlen(sfind) == found) {
return 1;
}
}
else {
found = 0;
}
index++;
}

return 0;
}

betekent meestal dat je een library niet laadt, of niet hebt.
kijkeven verder in de foutmeldingen, en heel normaal hoor, als je een programma kopieert, dan snap je niet hoe het werkt, en zit je vaak in de ellende.


Arduino Forum > International > Nederlands (Moderators: Jantje, JO3RI) > 'StrContains' was not declared in this scope ???


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'