As per subject, how do I to manipulate the string passed through SoftwareSerial Print/Println function? The reason why is I tried to make the URL parameter dynamic in order to access different webpages.
*Note: The code snippet below are working fine if without using String variable
// This is working fine
SoftwareSerial iSerial(28, 29);
iSerial.println("AT+HTTPPARA=\"URL\",\"http://website.com/data1.php\"");
delay(1000);
Serial.write(iSerial.read());
// This is not working
SoftwareSerial gprsSerial(28, 29 );
Int inputNumber;
String S1 = "AT+HTTPPARA=\"URL\",\"http://website.com/";
String S2 = String(inputNumber) + "data.php\"";
String_Variable = S1+S2;
iSerial.println(String_Variable);
delay(1000);
Serial.write(iSerial.read());
*Working means able to access the webpage via simcard using SIM900 (AT+HTTPPARA)
I even tried converting the string to array using malloc() and toCharArray() but it is still not working when I use the SoftwareSerial print function.
I'm new to Arduino. Kindly advise. Thanks! :)
Related
I have a php file in my website which returns sensor reading. I had been fetching this reading and displaying in my Serial monitor using the below code
http.begin("http://<MYWEBSITE>/fetch_sensor.php");
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
SensorReading = payload.toInt();
Serial.print("Sensor Reading=");
Serial.print(SensorReading);
Serial.println();
}
Now I have updated my php file to return readings of multiple sensors. The readings are returned seperated by commas like 23,66,82,100
I am looking to update my code so that the readings returned by the php file is assigned as SensorReading1, SensorReading2, SensorReading3 etc.
Seeking help from experts..
Thanks!!
You need to split your incoming string into separate strings, and then display each one. There are a few ways of splitting a string: https://arduino.stackexchange.com/questions/1013/how-do-i-split-an-incoming-string
I read bytes from a microcontroller in VC++2010(that i dont know absolutely but i must use as in lack of someone else) using SerialPort and on DataReceived event.
private: System::Void serialPort1_DataReceived(System::Object^ sender,
System::IO::Ports::SerialDataReceivedEventArgs^ e)
{
String^mystr;
mystr = serialPort1->ReadExisting();
I need raw data but everything >0x7F looks changed to 0x3F.
in the watch window mystr[3]=0x3F,despite i sent 0x80;
Why are some data lost?I expect that a raw byte could be converted in a char ,maybe an impossible to print char,but without altering the data.
Is there any way to have an array of raw data instead?
Thanks
hello every one i want to ask you if you know a way to extract data from message_t
in the oldest version of TinyOs there are TOS_Msg and TOS_MsgPtr but in message_t i could't find a way please help me
and i want to know if there is any data type to store data like table or array list
typedef nx_struct message_localization{
nx_uint8_t NodeId;
bool ancre_nature;
nx_uint8_t x_coordinate;
nx_uint8_t y_coordinate;
x_uint8_t energie_transmited;
} message_localization_t;
The Packet interface has a command getPayload which does want you want:
command void *getPayload(message_t *msg, uint8_t len);
See the documentation for more information.
To access the data field, you may do as follows:
message_t msg;
message_localization_t *payload =
(message_localization_t *)call Packet.getPayload(
&msg, sizeof(message_localization_t));
payload->x_coordinate = x;
payload->y_coordinate = y;
/* and so on */
The same command is for convenience included in interfaces Send and AMSend. Packet and AMSend are provided by the ActiveMessageC configuration.
I want to program some kind of game where the player has to name loacations shown on a map. I am using the slick library.
My problem is that I need some way to get the keyboard input from the player. I tried it with InputDialog from JOptionPane but I do not really like it. I would rather have the string appear on some part of the screen. But I do not have any idea how I can read from the keyboard directly into a variable that should be drawn on the screen. I thought that it would be possible to use streams but if I try to get some examples, they are always about reading from files and I do not know how to use that for reading from keyboard.
String answer;
public void render(GameContainer gameContainer, StateBasedGame sbGame, Graphics g){
g.drawString(answer, 50, 50);
}
public void update(GameContainer gameContainer, StateBasedGame sbGame, int delta){
//user types something which I now call "inputFromUser"
//it does not appear anywhere before the string is drawn on the screen.
answer = inputFromUser;
}
Something like a Scanner does not work for me because the user has to type that into the console, and I want him to type it "directly into the game" like it works with a textfield. (But I do not want to use a textfield.)
I have one way to accomplish that but it's fairly resource intensive. First create a global variable to keep track of the current letters. now create a new method that runs through all of the keys to check if they are down
private String totalString;
private void handelUserInput(Input input){
if(input.isKeyDown(Input.KEY_BACK)){
totalString = totalString.substring(0, totalString.length() - 1);
}
if(input.isKeyDown(Input.KEY_A)){
totalString += "a";
}
if(input.isKeyDown(Input.KEY_B)){
totalString += "b";
}
...etc
}
next create an input handler in the update loop to pass into the handle input method.
public void update(GameContainer gc, StateBasedGame sbg, int delta)throws SlickException {
Input input = gc.getInput();
handelUserInput(input);
}
and then print the string somewhere on your window in the render loop. by the way the Input class is built into slick.
I am just working my way through the location services for the first time and everything appears to be working in that it correctly finds my location but I am having trouble extracting the coordinates.
The docs states that CLLocation has a "Coordinates" property and the compiler is happy with this piece of code. However at runtime the CLLocation only appears to return a string description.
I start the location manager
_locationManager = new CLLocationManager ();
_locationManager.DesiredAccuracy = 1000;
// handle the updated location method and update the UI
_locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
UpdateLocation (e.Locations [e.Locations.Length - 1], _destinationLatitude, _destinationLongitude);
};
if (CLLocationManager.LocationServicesEnabled)
_locationManager.StartUpdatingLocation ();
The event fires correctly
static public void UpdateLocation (CLLocation current, Double destinationLat, Double destinationLng)
{
//Make the start pairing
string start = current.Coordinate.Latitude.ToString() + "," + current.Coordinate.Longitude.ToString();
//Make the destination pairing
string destination = destinationLat.ToString() + "," + destinationLng.ToString();
}
However the app just crashes out. Catching it on a breakpoint I see the following which only appears to have a description property that contains.
Description "<+50.58198902,-3.67661728> +/- 65.00m (speed -1.00 mps / course -1.00) # 25/07/2013 13:11:28 British…" string
I can obviously extract the lat/lng from this text field but I get the feeling I shouldn't need to do this. Any help appreciated.
I moved the exact same code into a different controller and it worked fine. The only difference between the two controllers was that the failing controller was using the monotouch dialog reflection api to bind the screen elements. I can't see why this would make any difference but it is the only difference between the two controllers. Everything is working now, I will try to reproduce in a smaller sample if I get the time.