Programming Error with Automated Gardening system

Hi, I am working on an Automated Gardening System. I have finished a moisture sensor and am now working on the code. I have finished the code for the moisture sensor and am working on one for the web scraper. When I am combining them both an error keeps popping up. Here is the code.

# include from
int s0=2;            //value of select pin at the 4051 (s0)
int s1=3;            //value of select pin at the 4051 (s1)
int s2=4;            //value of select pin at the 4051 (s2)
int count=0;          //which y pin we are selecting
void read_message() {
  debug("checking for messages");
  String indata = String();

  if(!(Serial.available() > 0)) {
    debug("no messages");
    return;
  } 
  else {
    while (Serial.available() > 0) {
      debug("available");
      char incomingByte = Serial.read();
      if (incomingByte == '\n') {
        break;
      }
      indata += incomingByte;
    }
}
}
void setup() 
{
  Serial.begin(9600);
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(A0, INPUT);
}
 void loop (){
  debug("looping");
  read_message(); // get any new messages from the computer
 }
void send_message(int type, String message) {
  Serial.println(String(type) + String('\t') + message);
}
// Message types

int DEBUG = 0;
int SENSOR = 1;
int FORECAST = 2;
unsigned int counter = 0;
//if true, prints everything out, else nothing printed 
boolean log_output = true;

void debug(String message) {
  if(log_output) {
    send_message(DEBUG, message);
  }
}

void process_debug(String message) {
  send_message(DEBUG, message);
}

# SENSOR:<integer>
# DEBUG:<string>
# FORECAST:<integer>
# 
# SENSOR:0
# SENSOR:1
# DEBUG:anything ending in a newline...
error below
from BeautifulSoup import BeautifulSoup
import urllib2, serial, time, sys
from serial.serialutil import SerialException

port = '/dev/tty.usbmodem411'
ser = serial.Serial(port, 9600)

SEPARATOR = '\t'
DEBUG = 0
SENSOR = 1
FORECAST = 2

rainylist=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,35,37,38,39,40,41
,42,43,45,46,47]

def check(c,l):
        if c in l:
                #it will rain tomorrow
                return 0
        else:
                #it will not rain tomorrow
                return 1

def process_sensor(message):
	print "Got sensor message: ", repr(message)
	if message[0] == "1":
		pg=urllib2.urlopen('http://weather.yahooapis.com/forecastrss?w=2380633').read()
		soup = BeautifulSoup(pg)
	
		tag=soup.findAll('yweather:forecast')

		forecast=tag[1]['text']
		code=tag[1]['code']
		newcode = int(code)

		rainOrShine = check(newcode,rainylist)
		rainOrShine = str(rainOrShine)
		
		# send message back to arduino
		# must send message as a string for some reason
		#send_message(FORECAST, "0")
		print "forecast: ", forecast
		print "rain (0) or shine (1)?", rainOrShine
		send_message(FORECAST, rainOrShine)
		#written = ser.write(rainOrShine)
	elif message[0]=="2":
		pass
	else:
		print "invalid"

def process_debug(message):
	print "DEBUG", repr(message)

def read_message(indata):
	#try:
	type, message = indata.split(SEPARATOR,1)
	#except ValueError:
		#print "Invalid message: ", indata
		#return
	
	if type == str(SENSOR):
		process_sensor(message)
	elif type == str(DEBUG):
		process_debug(message)

def send_message(type, message):
	type, message = str(type).encode('ascii'), str(message).encode('ascii')
	outdata = SEPARATOR.join((type, message)) + '\n'
	print 'send_message:', repr(outdata)
	ser.write(outdata)
	print 'sent'

# always waiting for inbyte
try:
	indata = ''
	inbyte = ''
	while True:
		while ser.inWaiting() > 0:
			try:
				inbyte = ser.read()
			except SerialException:
				continue
			# except OSError as e:
			# 	if e.errno == 35:

This is the error. ‘from’ does not name a type.
What does this error mean? Any help is appreciated.
Thanks,
Animesh

aj33690:

# include from

If you meant to include a library then the structure is, no space, angle brackets…

#include <library.name.h>

If you were trying to write a comment, then the format is, two slashed…

// include from

jbarchuk:

aj33690:

# include from

If you meant to include a library then the structure is, no space, angle brackets…

Unless, of course, the file you wish to include is in the same directory as the program being compiled. Then you should use double-quotes (so #include “myheader.h”).

I believe The C Preprocessor: 1. The C Preprocessor is an older but somewhat applicable document.

Regards,

Brad
KF7FER

EDIT: Some real interesting code too… I don’t think this will compile:

# SENSOR:1
# DEBUG:anything ending in a newline...
error below
from BeautifulSoup import BeautifulSoup
import urllib2, serial, time, sys
from serial.serialutil import SerialException

port = '/dev/tty.usbmodem411'
ser = serial.Serial(port, 9600)

Thanks. Brad, what is the part of the code that you think will not compile. I got this code of the internet from the website http://www.instructables.com/id/Garduino-Automated-Gardening-System/?ALLSTEPS . I was just copying and playing around with the code and am unsure on a few parts of the code. It says rainy list and I am not sure what that means. It also mentions def c which is terminology that I am unfamiliar with. Errors keep popping up with the code and I am unsure why they do since this was a finished piece of code. Is there some sort of forecast function I could use for the web scraper? If there is an alternate code for the Arduino to check moisture sensors and the web to determine if it should water or not if you could nudge in the right direction it would be great. Here is the code with the edits I have managed to make. Any help or guidance you could give me with this code would be appreciated. I am now thinking this was a project to complex for beginner like me!

#include "BeautifulSoup"
#include "Serial"
#include "urllib2"

int s0=2;            //value of select pin at the 4051 (s0)
int s1=3;            //value of select pin at the 4051 (s1)
int s2=4;            //value of select pin at the 4051 (s2)
int count=0;          //which y pin we are selecting

 int rainylist[31] ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,35,37,38,39,40,41,42,43,45,46,47};

void read_message() {
  debug("checking for messages");
  String indata = String();

  if(!(Serial.available() > 0)) {
    debug("no messages");
    return;
  } 
  else {
    while (Serial.available() > 0) {
      debug("available");
      char incomingByte = Serial.read();
      if (incomingByte == '\n') {
        break;
      }
      indata += incomingByte;
    }
}
}
void setup() 
{
  Serial.begin(9600);
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(A0, INPUT);
}
 void loop1 (){
  debug("looping");
  read_message(); // get any new messages from the computer
 }
void send_message(int type, String message) {
  Serial.println(String(type) + String('\t') + message);
}
// Message types

int DEBUG = 0;
int SENSOR = 1;
int FORECAST = 2;
unsigned int counter = 0;
//if true, prints everything out, else nothing printed 
boolean log_output = true;

void debug(String message) {
  if(log_output) {
    send_message(DEBUG, message);
  }
}

void process_debug(String message) {
  send_message(DEBUG, message);
}

//# SENSOR:<integer>
//# DEBUG:<string>
//# FORECAST:<integer>
 
//# SENSOR:0
//# SENSOR:1
//# DEBUG:anything ending in a newline...

//from BeautifulSoup import BeautifulSoup
//import urllib2, serial, time, sys
//from serial.serialutil import SerialException
//import SerialException

//port = '/dev/tty.usbmodem411'
//ser = serial.Serial(port, 9600)

//SEPARATOR = '\t';
//int DEBUG = 0;
//int SENSOR = 1;
//int FORECAST = ;
//rainylist=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,35,37,38,39,40,41
//,42,43,45,46,47];

#def check(c,l):
        if c in l:
                #it will rain tomorrow
                return 0
        else:
              #it will not rain tomorrow
              return 1

#def process_sensor(message):
	print "Got sensor message: ", repr(message)
	if message[0] == "1":
		pg=urllib2.urlopen('http://weather.yahooapis.com/forecastrss?w=2380633').read()
		soup = BeautifulSoup(pg)
	       }
		tag=soup.findAll('yweather:forecast')

		forecast=tag[1]['text']
		code=tag[1]['code']
		newcode = int(code)

		rainOrShine = check(newcode,rainylist)
		rainOrShine = str(rainOrShine)
		
		# send message back to arduino
		# must send message as a string for some reason
		#send_message(FORECAST, "0")
		print "forecast: ", forecast
		print "rain (0) or shine (1)?", rainOrShine
		send_message(FORECAST, rainOrShine)
		#written = ser.write(rainOrShine)
	elif message[0]=="2":
		pass
	else:
		print "invalid"

def process_debug(message):
	print "DEBUG", repr(message)

def read_message(indata):
	#try:
	type, message = indata.split(SEPARATOR,1)
	#except ValueError:
		#print "Invalid message: ", indata
		#return
	
	if type == str(SENSOR):
		process_sensor(message)
	elif type == str(DEBUG):
		process_debug(message)

def send_message(type, message):
	type, message = str(type).encode('ascii'), str(message).encode('ascii')
	outdata = SEPARATOR.join((type, message)) + '\n'
	print 'send_message:', repr(outdata)
	ser.write(outdata)
	print 'sent'

# always waiting for inbyte
try:
	indata = ''
	inbyte = ''
	while True:
		while ser.inWaiting() > 0:
			try:
				inbyte = ser.read()
			except SerialException:
				continue
			# except OSError as e:
			# 	if e.errno == 35:

Here are all the errors.

Webscraper_Moisture_Sensor_Code_2.ino:2:25: error: BeautifulSoup: No such file or directory
Webscraper_Moisture_Sensor_Code_2.ino:3:18: error: Serial: No such file or directory
Webscraper_Moisture_Sensor_Code_2.ino:4:19: error: urllib2: No such file or directory
Webscraper_Moisture_Sensor_Code_2.ino:89:2: error: invalid preprocessing directive #def
Webscraper_Moisture_Sensor_Code_2.ino:91:18: error: invalid preprocessing directive #it
Webscraper_Moisture_Sensor_Code_2.ino:94:16: error: invalid preprocessing directive #it
Webscraper_Moisture_Sensor_Code_2.ino:97:2: error: invalid preprocessing directive #def
Webscraper_Moisture_Sensor_Code_2.ino:112:5: error: invalid preprocessing directive #send
Webscraper_Moisture_Sensor_Code_2.ino:113:5: error: invalid preprocessing directive #must
Webscraper_Moisture_Sensor_Code_2.ino:114:4: error: invalid preprocessing directive #send_message
Webscraper_Moisture_Sensor_Code_2.ino:118:4: error: invalid preprocessing directive #written
Webscraper_Moisture_Sensor_Code_2.ino:128:3: error: invalid preprocessing directive #try
Webscraper_Moisture_Sensor_Code_2.ino:130:3: error: invalid preprocessing directive #except
Webscraper_Moisture_Sensor_Code_2.ino:131:4: error: invalid preprocessing directive #print
Webscraper_Moisture_Sensor_Code_2.ino:132:4: error: invalid preprocessing directive #return
Webscraper_Moisture_Sensor_Code_2.ino:146:3: error: invalid preprocessing directive #always
Webscraper_Moisture_Sensor_Code_2.ino:148:11: error: empty character constant
Webscraper_Moisture_Sensor_Code_2.ino:149:11: error: empty character constant
Webscraper_Moisture_Sensor_Code_2.ino:156:6: error: invalid preprocessing directive #except
Webscraper_Moisture_Sensor_Code_2.ino:157:11: error: token "." is not valid in preprocessor expressions
Webscraper_Moisture_Sensor_Code_2.ino:157:1: error: unterminated #if
Webscraper_Moisture_Sensor_Code_2:90: error: expected unqualified-id before 'if'
Webscraper_Moisture_Sensor_Code_2:102: error: expected declaration before '}' token

I cannot make sense of them.

Thanks

Arduino will not run the python code you found on the Internet. You must program in C/C++.

My guess is the author was running the python code on a PC.

What does that mean. I have a PC too.