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